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

Skip to content

Commit d2f86fb

Browse files
committed
Fixes #172 - also cookies are parsed from burp/webscarab logs (-l) and request file (-r) now
1 parent 466df89 commit d2f86fb

2 files changed

Lines changed: 29 additions & 109 deletions

File tree

lib/controller/controller.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def start():
138138

139139
logMsg = "testing url %s" % targetUrl
140140
logger.info(logMsg)
141-
141+
142142
initTargetEnv()
143143
parseTargetUrl()
144144
setupTargetEnv()
@@ -150,28 +150,28 @@ def start():
150150
for _, cookie in enumerate(conf.cj):
151151
cookie = str(cookie)
152152
index = cookie.index(" for ")
153-
153+
154154
cookieStr += "%s;" % cookie[8:index]
155155

156156
if cookieStr:
157157
cookieStr = cookieStr[:-1]
158-
158+
159159
if "Cookie" in conf.parameters:
160160
message = "you provided an HTTP Cookie header value. "
161161
message += "The target url provided its own Cookie within "
162162
message += "the HTTP Set-Cookie header. Do you want to "
163163
message += "continue using the HTTP Cookie values that "
164164
message += "you provided? [Y/n] "
165165
test = readInput(message, default="Y")
166-
166+
167167
if not test or test[0] in ("y", "Y"):
168168
setCookieAsInjectable = False
169-
169+
170170
if setCookieAsInjectable:
171171
conf.httpHeaders.append(("Cookie", cookieStr))
172172
conf.parameters["Cookie"] = cookieStr
173173
__paramDict = paramToDict("Cookie", cookieStr)
174-
174+
175175
if __paramDict:
176176
conf.paramDict["Cookie"] = __paramDict
177177
__testableParameters = True

lib/core/option.py

Lines changed: 23 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,29 @@ def __setMultipleTargets():
227227
infoMsg += "testable requests from the targets list"
228228
logger.info(infoMsg)
229229

230+
def __setRequestFromFile():
231+
"""
232+
This function checks if the way to make a HTTP request is through supplied
233+
textual file, parses it and saves the information into the knowledge base.
234+
"""
235+
236+
if not conf.requestFile:
237+
return
238+
239+
addedTargetUrls = set()
240+
241+
conf.requestFile = os.path.expanduser(conf.requestFile)
242+
243+
infoMsg = "parsing HTTP request from '%s'" % conf.requestFile
244+
logger.info(infoMsg)
245+
246+
if not os.path.isfile(conf.requestFile):
247+
errMsg = "the specified HTTP request file "
248+
errMsg += "does not exist"
249+
raise sqlmapFilePathException, errMsg
250+
251+
__feedTargetsDict(conf.requestFile, addedTargetUrls)
252+
230253
def __setGoogleDorking():
231254
"""
232255
This function checks if the way to request testable hosts is through
@@ -274,109 +297,6 @@ def __setGoogleDorking():
274297
errMsg += "have GET parameters to test for SQL injection"
275298
raise sqlmapGenericException, errMsg
276299

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

0 commit comments

Comments
 (0)