minor update toward the implementation of request from Santiago

This commit is contained in:
Miroslav Stampar 2011-03-17 06:39:05 +00:00
parent 0535225fe7
commit fbd0cfda29
2 changed files with 8 additions and 3 deletions

View File

@ -21,6 +21,7 @@ class ThreadData():
self.disableStdOut = False
self.lastErrorPage = None
self.lastHTTPError = None
self.lastRedirectMsg = None
self.lastQueryDuration = 0
self.lastRequestUID = 0
self.seqMatcher = difflib.SequenceMatcher(None)

View File

@ -10,6 +10,7 @@ See the file 'doc/COPYING' for copying permission
import urllib2
from lib.core.exception import sqlmapConnectionException
from lib.core.threads import getCurrentThreadData
class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
# maximum number of redirections to any single URL
@ -20,7 +21,10 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
# assuming we're in a loop
max_redirections = 10
def common_http_redirect(self, result, headers, code):
def common_http_redirect(self, result, headers, code, msg):
threadData = getCurrentThreadData()
threadData.lastRedirectMsg = (threadData.lastRequestUID, msg)
if "location" in headers:
result.redurl = headers.getheaders("location")[0].split("?")[0]
elif "uri" in headers:
@ -36,12 +40,12 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
def http_error_301(self, req, fp, code, msg, headers):
self.infinite_loop_check(req)
result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
return self.common_http_redirect(result, headers, code)
return self.common_http_redirect(result, headers, code, msg)
def http_error_302(self, req, fp, code, msg, headers):
self.infinite_loop_check(req)
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
return self.common_http_redirect(result, headers, code)
return self.common_http_redirect(result, headers, code, msg)
def infinite_loop_check(self, req):
if hasattr(req, 'redirect_dict') and (req.redirect_dict.get(req.get_full_url(), 0) >= self.max_repeats or len(req.redirect_dict) >= self.max_redirections):