python漏洞检测脚本_URL重定向漏洞,python打造URL重定向漏洞检测脚本
前言:
今天學習了重定向漏洞,這個漏洞比較好理解
漏洞名:URL重定向漏洞
威脅:低
漏洞的來源:開發(fā)者對head頭做好對應的過濾和限制
例子:
有漏洞的網(wǎng)站:http://a.com/x.php?url=http://a.com/login.php
這時我們通過寫個url后面的鏈接讓其跳轉(zhuǎn)到指定的頁面。例:http;//a.com/x.php?url=http://www.baidu.com
可搭配使用的漏洞:
CSRF? 當一個網(wǎng)站存在CSRF漏洞的時候,而你知道了創(chuàng)建后臺管理員的鏈接。修改鏈接,運用URL重定向漏洞。在進行短鏈生成
儲存型XSS 當一個網(wǎng)站存在儲存型XSS漏洞的時候,你插入了一個盜取cookie的js。配合URL重定向漏洞,讓受害者直接跳轉(zhuǎn)到該頁面
正文:
這里我們使用BWAPP這個漏洞網(wǎng)站來進行URL重定向測試。
http://192.168.3.41/bWAPP/unvalidated_redir_fwd_1.php
未過濾的重定向與轉(zhuǎn)發(fā)
點擊Beam按鈕跳轉(zhuǎn)到
打開Burpsuite抓包一看
發(fā)現(xiàn)參數(shù)是這樣的url=xxxx&form=submit
發(fā)送到repeater
修改url=http://www.baidu.com
產(chǎn)生302跳轉(zhuǎn)。跳轉(zhuǎn)頁面為http://www.baidu.com
回到剛剛的位置放包一看,跳轉(zhuǎn)
中級嘗試
一樣抓包
直接進行改鏈,發(fā)現(xiàn)跳回到登錄頁面。仔細對比發(fā)現(xiàn),中級防御通過cookie的設置來判斷
將其改為0在改其url后面的參數(shù),直接跳轉(zhuǎn)
高級嘗試
高級和中級防御沒區(qū)別。只是將cookie后面的值改為2。直接改0,將其鏈接設置跳轉(zhuǎn)成博客園的鏈接
博客園這里要經(jīng)過兩次跳轉(zhuǎn)
驗證URl重定向的漏洞腳的本代碼:
importrequests,timedefpoc():
user=input('Please enter the web site to be tested:')
user2=input('Please enter the parameters you want to bring in:')
values=user2.strip().split('?')[-1]
params={}for line in values.split('&'):
key,value=line.split('=',1)
params[key]=valueprint('URL:',user)print('The parameters you have taken are:',params)
time.sleep(0.2)print('If you want to change the parameters, please enter y')print('Do not need to change to enter n')
user3=input('Do you want to change your parameters[y/n]:')if user3 == 'y':whileTrue:print('Please enter the name of the parameter you want to change{name: value}')print(params)
user4=input('Please fill in the name:')
user5=input('Please enter the value you want to change:')
params['{}'.format(user4)]='{}'.format(user5)print('The change is done, and your current parameter is',params)
user6=input('Do you want to continue to love the parameters more[y/n]?:')if user6 == 'y':continue
elif user6 == 'n':break
elif user6 == '':breakurl=user.strip()
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'}
rest=requests.get(url=url,headers=headers,timeout=6,params=params, allow_redirects=False)print('Http_code:',rest.status_code)print(rest.headers)try:print(rest.headers['Location'])if rest.headers['Location'] == 'http://www.baidu.com':print('[*]There is a URL redirection vulnerability in this link')else:print('[+]There is no URL redirection vulnerability in this link')except:print('[-]not Location head')
poc()
運行結(jié)果如下:
總結(jié):
雖然漏洞威脅不高但還是要防御。防御方法有以下幾種:
可利用state參數(shù)進行防跨站攻擊,驗證302跳轉(zhuǎn)回來帶code參數(shù)的這個請求是否是攻擊者偽造的,防止攻擊者偽造請求。
對于外鏈攻擊,可在支持HTML5瀏覽器的環(huán)境下給所有外部鏈接加上rel=noreferrer屬性;對于老版本IE的處理方案是利用一個HTTPS進行跳轉(zhuǎn)達到抹去referer的效果
PHP獲取retferer判斷來路防止非法訪問:http://www.90tec.com/iwork/20.html
第二種我不喜歡,其他都還好
總結(jié)
以上是生活随笔為你收集整理的python漏洞检测脚本_URL重定向漏洞,python打造URL重定向漏洞检测脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hide show vue 动画_Vue
- 下一篇: cmd52命令发送 mmc_乾坤合一~L