Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a58b36f

Browse files
committed
code commit regarding Feature #119
1 parent 4a72ad1 commit a58b36f

4 files changed

Lines changed: 130 additions & 6 deletions

File tree

lib/core/option.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,121 @@ def __setGoogleDorking():
267267
errMsg += "have GET parameters to test for SQL injection"
268268
raise sqlmapGenericException, errMsg
269269

270+
def __setRequestFromFile():
271+
"""
272+
This function checks if the way to make a HTTP request is through supplied
273+
textual file, parses it and saves the information into the knowledge base.
274+
"""
275+
276+
if not conf.requestFile:
277+
return
278+
279+
conf.requestFile = os.path.expanduser(conf.requestFile)
280+
281+
debugMsg = "parsing HTTP request from '%s'" % conf.requestFile
282+
logger.debug(debugMsg)
283+
284+
if not os.path.isfile(conf.requestFile):
285+
errMsg = "the specified HTTP request file "
286+
errMsg += "'%s' does not exist" % conf.requestFile
287+
raise sqlmapFilePathException, errMsg
288+
289+
fp = open(conf.requestFile, "r")
290+
fread = fp.read()
291+
fread = fread.replace("\r", "")
292+
fp.close()
293+
294+
lines = fread.split("\n")
295+
296+
if len(lines) == 0:
297+
errMsg = "the specified HTTP request file "
298+
errMsg += "'%s' has no content" % conf.requestFile
299+
raise sqlmapFilePathException, errMsg
300+
301+
if not (lines[0].startswith("GET ") or lines[0].startswith("POST ")):
302+
errMsg = "the specified HTTP request file "
303+
errMsg += "doesn't start with GET or POST keyword"
304+
raise sqlmapFilePathException, errMsg
305+
306+
307+
if lines[0].upper().startswith("GET "):
308+
index = 4
309+
else:
310+
index = 5
311+
312+
if lines[0].find(" HTTP/") == -1:
313+
errMsg = "the specified HTTP request file "
314+
errMsg += "has a syntax error at line: 1"
315+
raise sqlmapFilePathException, errMsg
316+
317+
host = None
318+
headers = ""
319+
page = lines[0][index:lines[0].index(" HTTP/")]
320+
321+
if conf.method:
322+
warnMsg = "HTTP method previously set. overriding it with "
323+
warnMsg += "the value supplied from the HTTP request file"
324+
logger.warn(warnMsg)
325+
conf.method = lines[0][:index-1]
326+
327+
for index in xrange(1, len(lines) - 1):
328+
line = lines[index]
329+
valid = True
330+
331+
if len(line) == 0:
332+
break
333+
334+
headers += line + "\n"
335+
336+
items = line.split(': ')
337+
if len(items) != 2:
338+
valid = False
339+
else:
340+
if items[0].upper() == "HOST":
341+
host = items[1]
342+
343+
if not valid:
344+
errMsg = "the specified HTTP request file"
345+
errMsg += "has a syntax error at line: %d" % (index + 1)
346+
raise sqlmapFilePathException, errMsg
347+
348+
if conf.headers and headers:
349+
warnMsg = "HTTP headers previously set. overriding it with "
350+
warnMsg += "the value(s) supplied from the HTTP request file"
351+
logger.warn(warnMsg)
352+
conf.headers = headers.strip("\n")
353+
354+
if fread.find("\n\n") != -1:
355+
if conf.data:
356+
warnMsg = "HTTP POST data previously set. overriding it with "
357+
warnMsg += "the value supplied from the HTTP request file"
358+
logger.warn(warnMsg)
359+
conf.data = fread[fread.index('\n\n')+2:].strip("\n")
360+
361+
if conf.url:
362+
warnMsg = "target url previously set. overriding it with "
363+
warnMsg += "the value supplied from the HTTP request file"
364+
logger.warn(warnMsg)
365+
366+
if host:
367+
conf.url = "%s%s" % (host, page)
368+
elif conf.url: #insert page into here
369+
index = conf.url.find("://")
370+
if index != -1:
371+
index += len("://")
372+
else:
373+
index = 0
374+
375+
index = conf.url.find("/", index)
376+
if index != -1:
377+
conf.url = "%s%s" % (conf.url[:conf.url.find("/", index)], page)
378+
else:
379+
conf.url = "%s%s" % (conf.url, page)
380+
pass #mirek
381+
else:
382+
errMsg = "target url is not known"
383+
raise sqlmapFilePathException, errMsg
384+
270385
def __setMetasploit():
271386
if not conf.osPwn and not conf.osSmb and not conf.osBof:
272387
return
@@ -1004,6 +1119,8 @@ def init(inputOptions=advancedDict()):
10041119
__setKnowledgeBaseAttributes()
10051120
__cleanupOptions()
10061121

1122+
__setRequestFromFile()
1123+
10071124
parseTargetUrl()
10081125

10091126
__setHTTPTimeout()

lib/core/optiondict.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"Target": {
2828
"url": "string",
2929
"list": "string",
30-
"googleDork": "string"
30+
"googleDork": "string",
31+
"configFile": "string"
3132
},
3233

3334
"Request": {
@@ -47,7 +48,8 @@
4748
"delay": "float",
4849
"timeout": "float",
4950
"retries": "integer",
50-
"scope": "string"
51+
"scope": "string",
52+
"requestFile": "string"
5153
},
5254

5355
"Injection": {

lib/parse/cmdline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def cmdLineParser():
5858

5959
target.add_option("-c", dest="configFile",
6060
help="Load options from a configuration INI file")
61-
61+
6262
# Request options
6363
request = OptionGroup(parser, "Request", "These options can be used "
6464
"to specify how to connect to the target url.")
@@ -121,6 +121,9 @@ def cmdLineParser():
121121
request.add_option("--scope", dest="scope",
122122
help="Regexp to filter targets from provided proxy log")
123123

124+
request.add_option("-r", dest="requestFile",
125+
help="Load HTTP request from a file")
126+
124127
# Injection options
125128
injection = OptionGroup(parser, "Injection", "These options can be "
126129
"used to specify which parameters to test "
@@ -421,8 +424,8 @@ def cmdLineParser():
421424

422425
(args, _) = parser.parse_args()
423426

424-
if not args.url and not args.list and not args.googleDork and not args.configFile and not args.updateAll:
425-
errMsg = "missing a mandatory parameter ('-u', '-l', '-g', '-c' or '--update'), "
427+
if not args.url and not args.list and not args.googleDork and not args.configFile and not args.requestFile and not args.updateAll:
428+
errMsg = "missing a mandatory parameter ('-u', '-l', '-g', '-c', '-r' or '--update'), "
426429
errMsg += "-h for help"
427430
parser.error(errMsg)
428431

sqlmap.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ list =
1717
# Example: +ext:php +inurl:"&id=" +intext:"powered by "
1818
googleDork =
1919

20-
2120
[Request]
2221

2322
# HTTP method to perform HTTP requests.
@@ -100,6 +99,9 @@ retries = 3
10099
# Example: (google|yahoo)
101100
scope =
102101

102+
# Load HTTP request from a file
103+
# Example (file content): POST /login.jsp HTTP/1.1\nUser-Agent: Mozilla/4.0\n\nuserid=joe&password=guessme
104+
requestFile =
103105

104106
[Injection]
105107

0 commit comments

Comments
 (0)