前言:
今天学习了重定向漏洞, 这个漏洞比较好理解
漏洞名: URL 重定向漏洞
威胁: 低
例子:
有漏洞的网站: 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
第二种我不喜欢, 其他都还好
来源: https://www.cnblogs.com/haq5201314/p/8975380.html