zoukankan      html  css  js  c++  java
  • 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 

    第二种我不喜欢,其他都还好

     

  • 相关阅读:
    CodeSmith中SchemaExplorer属性的介绍
    Bugku-INSERT INTO 注入
    XCTF-PHP2
    网络安全实验室CTF-注入关
    XSS挑战
    SQL注入
    CTFHub-技能树-命令执行
    CTFHub-技能树-文件上传
    史上最难的一道Java面试题 (分析篇)
    高可用的一些思考和理解
  • 原文地址:https://www.cnblogs.com/haq5201314/p/8975380.html
Copyright © 2011-2022 走看看