logo

Wireshark分析sql布尔盲注流量包

作者:ceshi6102021.09.08 22:34浏览量:446

简介:Wireshark分析sql布尔盲注流量包

0x001 题目
在这里插入图片描述.jpg

0x002 查看注入语句
将流量包导入Wireshark
在这里插入图片描述.jpg
看着很乱,输入url通过浏览器请求使用的协议为http,所以我们直接过滤出http协议的数据包。

过滤出http请求的数据包

注入语句如下:

http://localhost:81/?id=1' and ascii(substring((select keyid from flag limit 0,1),1,1))=32#

由此可见攻击者采用布尔盲注进行sql注入。

关于布尔盲注查看:https://blog.csdn.net/weixin_44032232/article/details/109358571
0x003 观察响应包
这里我们想到注入语句成功和失败所返回的数据包一定是不同的。

观察sql注入响应包。

注入失败响应内容:
在这里插入图片描述.jpg
注入成功响应内容:
在这里插入图片描述.jpg
由此我们可以想到是不是可以先将注入成功响应包过滤出来???那么我们应该以什么规则进行过滤呢,或者说以响应包哪个特征进行过滤呢???

我想到的过滤条件:

  • 过滤出响应内容中有文章内容的所有响应包
  • 根据响应包的长度进行过滤
    注入失败的响应包长度:
    在这里插入图片描述.jpg
    注入成功的响应包长度:
    在这里插入图片描述.jpg
    对于Wireshark的语法不是很熟悉,没有找到怎么以内容过滤的语法,所以我这里以响应包的长度进行过滤。

Wireshark http过滤规则:
http.host==magentonotes.com
http.host contains magentonotes.com
//过滤经过指定域名的http数据包,这里的host值不一定是请求中的域名

http.response.code==302
//过滤http响应状态码为302的数据包

http.response==1
//过滤所有的http响应包

http.request==1
//过滤所有的http请求,貌似也可以使用http.request

http.request.method==POST
//wireshark过滤所有请求方式为POST的http请求包,注意POST为大写

http.cookie contains guid
//过滤含有指定cookie的http数据包

http.request.uri==”/online/setpoint”
//过滤请求的uri,取值是域名后的部分

http.request.full_uri==” http://task.browser.360.cn/online/setpoint”
//过滤含域名的整个url则需要使用http.request.full_uri

http.server contains “nginx”
//过滤http头中server字段含有nginx字符的数据包

http.content_type == “text/html”
//过滤content_type是text/html的http响应、post包,即根据文件类型过滤http数据包

http.content_encoding == “gzip”
//过滤content_encoding是gzip的http包

http.transfer_encoding == “chunked”
//根据transfer_encoding过滤

http.content_length == 279
http.content_length_header == “279″
//根据content_length的数值过滤

http.server
//过滤所有含有http头中含有server字段的数据包

http.request.version == “HTTP/1.1″
//过滤HTTP/1.1版本的http包,包括请求和响应

http.response.phrase == “OK”
//过滤http响应中的phrase

以content-Length长度进行过滤,过滤语法为http.content_length == 366
在这里插入图片描述.jpg
所有注入成功的语句也可以从响应包查看到。

http://localhost:81/?id=1' and ascii(substring((select keyid from flag limit 0,1),1,1))=102#

这条sql语句的含义:第一个字符的ASCII码为102

http://localhost:81/?id=1' and ascii(substring((select keyid from flag limit 0,1),1,1))=102#

0x004 脚本编写
将上面过滤后的结果导出
在这里插入图片描述.jpg
使用正则过滤出注入语句和字符对应的ASCII码

import re

number = []
with open("aa.txt","r",encoding="utf-8") as f:
    for i in f.readlines():
        flag_number = re.findall(r"\[Request URI: .*?=(\d+)%23\]",i,re.S) # 字符对应的ASCII码
        url_list = re.findall(r"\[Request URI: (.*?)\]",i,re.S)  # 注入的url
        if flag_number:
            print(url_list)
            number.append(flag_number[0])

在这里插入图片描述.jpg
这里注意注入语句成功的先后顺序,也就是上图圈出来的地方按顺序排序(从第1个字符开始判断,一直到38个字符),就是注入成功的执行流程。

知道了字符对应的ASCII码,反过来通过ASCII码得出对应的字符即可。

最后跑出flag

import re

number = []
with open("aa.txt","r",encoding="utf-8") as f:
    for i in f.readlines():
        flag_number = re.findall(r"\[Request URI: .*?=(\d+)%23\]",i,re.S) # 字符对应的ASCII码
        url_list = re.findall(r"\[Request URI: (.*?)\]",i,re.S)  # 注入的url
        if flag_number:
            print(url_list)
            number.append(flag_number[0])

在这里插入图片描述.jpg

相关文章推荐

发表评论