URL重定向漏洞,python打造URL重定向漏洞檢測腳本
前言:
今天學習了重定向漏洞,這個漏洞比較好理解
漏洞名:URL重定向漏洞
威脅:低
漏洞的來源:開發者對head頭做好對應的過濾和限制
例子:
有漏洞的網站:http://a.com/x.php?url=http://a.com/login.php
這時我們通過寫個url後面的鏈接讓其跳轉到指定的頁面。例:http;//a.com/x.php?url=http://www.baidu.com
可搭配使用的漏洞:
CSRF 當一個網站存在CSRF漏洞的時候,而你知道了創建後臺管理員的鏈接。修改鏈接,運用URL重定向漏洞。在進行短鏈生成
儲存型XSS 當一個網站存在儲存型XSS漏洞的時候,你插入了一個盜取cookie的js。配合URL重定向漏洞,讓受害者直接跳轉到該頁面
正文:
這裏我們使用BWAPP這個漏洞網站來進行URL重定向測試。
http://192.168.3.41/bWAPP/unvalidated_redir_fwd_1.php
未過濾的重定向與轉發
點擊Beam按鈕跳轉到
打開Burpsuite抓包一看
發現參數是這樣的url=xxxx&form=submit
發送到repeater
修改url=http://www.baidu.com
產生302跳轉。跳轉頁面為http://www.baidu.com
回到剛剛的位置放包一看,跳轉
中級嘗試
一樣抓包
直接進行改鏈,發現跳回到登錄頁面。仔細對比發現,中級防禦通過cookie的設置來判斷
將其改為0在改其url後面的參數,直接跳轉
高級嘗試
高級和中級防禦沒區別。只是將cookie後面的值改為2。直接改0,將其鏈接設置跳轉成博客園的鏈接
博客園這裏要經過兩次跳轉
驗證URl重定向的漏洞腳的本代碼:
import requests,time def poc(): 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]=value print(‘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‘: while True: 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 == ‘‘: break url=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()
運行結果如下:
總結:
雖然漏洞威脅不高但還是要防禦。防禦方法有以下幾種:
可利用state參數進行防跨站攻擊,驗證302跳轉回來帶code參數的這個請求是否是攻擊者偽造的,防止攻擊者偽造請求。
對於外鏈攻擊,可在支持HTML5瀏覽器的環境下給所有外部鏈接加上rel=noreferrer
屬性;對於老版本IE的處理方案是利用一個HTTPS進行跳轉達到抹去referer的效果
PHP獲取retferer判斷來路防止非法訪問:http://www.90tec.com/iwork/20.html
第二種我不喜歡,其他都還好
URL重定向漏洞,python打造URL重定向漏洞檢測腳本