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

Skip to content

Commit 466df89

Browse files
committed
Fixes #178 and #179 - proper handling of custom redirects
1 parent 3b3353e commit 466df89

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

lib/controller/controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ def start():
237237

238238
else:
239239
raise sqlmapNotVulnerableException, "all parameters are not injectable"
240-
return
241240

242241
if injDataSelected == "Quit":
243242
return
@@ -246,7 +245,7 @@ def start():
246245
kb.injPlace, kb.injParameter, kb.injType = injDataSelected
247246
setInjection()
248247

249-
elif kb.injPlace and kb.injParameter and kb.injType:
248+
if kb.injPlace and kb.injParameter and kb.injType:
250249
if conf.multipleTargets:
251250
message = "do you want to exploit this SQL injection? [Y/n] "
252251
exploit = readInput(message, default="Y")

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ def __setConfAttributes():
957957
conf.path = None
958958
conf.port = None
959959
conf.progressWidth = 54
960+
conf.redirectHandled = False
960961
conf.retriesCount = 0
961962
conf.scheme = None
962963
#conf.seqMatcher = difflib.SequenceMatcher(lambda x: x in " \t")

lib/request/connect.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import traceback
3232

3333
from lib.contrib import multipartpost
34+
from lib.core.common import readInput
3435
from lib.core.convert import urlencode
3536
from lib.core.data import conf
3637
from lib.core.data import kb
@@ -125,12 +126,24 @@ def getPage(**kwargs):
125126
req = urllib2.Request(url, post, headers)
126127
conn = urllib2.urlopen(req)
127128

128-
if hasattr(conn, "redurl"):
129-
infoMsg = "connection redirected, going to use "
130-
infoMsg += "%s as target address" % conn.redurl
131-
logger.info(infoMsg)
129+
if hasattr(conn, "redurl") and hasattr(conn, "redcode") and not conf.redirectHandled:
130+
msg = "sqlmap got a %d redirect to " % conn.redcode
131+
msg += "%s - What target address do you " % conn.redurl
132+
msg += "want to use from now on? %s " % conf.url
133+
msg += "(default) or provide another target address based "
134+
msg += "also on the redirection got from the application\n"
132135

133-
conf.url = conn.redurl
136+
while True:
137+
choice = readInput(msg, default="1")
138+
139+
if not choice or choice == "1":
140+
pass
141+
else:
142+
conf.url = choice
143+
144+
break
145+
146+
conf.redirectHandled = True
134147

135148
return Connect.__getPageProxy(**kwargs)
136149

lib/request/redirecthandler.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@
2525
import urllib2
2626

2727
class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
28-
def http_error_301(self, req, fp, code, msg, headers):
29-
result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
30-
28+
def common_http_redirect(self, result, headers, code):
3129
if "location" in headers:
3230
result.redurl = headers.getheaders("location")[0].split("?")[0]
3331
elif "uri" in headers:
3432
result.redurl = headers.getheaders("uri")[0].split("?")[0]
3533

34+
result.redcode = code
35+
3636
return result
3737

38+
def http_error_301(self, req, fp, code, msg, headers):
39+
result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
40+
return self.common_http_redirect(result, headers, code)
41+
3842
def http_error_302(self, req, fp, code, msg, headers):
3943
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
40-
41-
if "location" in headers:
42-
result.redurl = headers.getheaders("location")[0].split("?")[0]
43-
elif "uri" in headers:
44-
result.redurl = headers.getheaders("uri")[0].split("?")[0]
45-
46-
return result
44+
return self.common_http_redirect(result, headers, code)

0 commit comments

Comments
 (0)