mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-03 13:14:13 +03:00
added logging to redirecthandler
This commit is contained in:
parent
9a513198dd
commit
6607a240cf
|
@ -9,7 +9,10 @@ See the file 'doc/COPYING' for copying permission
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
from lib.core.data import conf
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
|
from lib.core.common import getUnicode
|
||||||
|
from lib.core.common import logHTTPTraffic
|
||||||
from lib.core.exception import sqlmapConnectionException
|
from lib.core.exception import sqlmapConnectionException
|
||||||
from lib.core.threads import getCurrentThreadData
|
from lib.core.threads import getCurrentThreadData
|
||||||
|
|
||||||
|
@ -22,10 +25,24 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||||
# assuming we're in a loop
|
# assuming we're in a loop
|
||||||
max_redirections = 10
|
max_redirections = 10
|
||||||
|
|
||||||
def common_http_redirect(self, result, headers, code, content):
|
def common_http_redirect(self, result, headers, code, content, msg):
|
||||||
threadData = getCurrentThreadData()
|
threadData = getCurrentThreadData()
|
||||||
threadData.lastRedirectMsg = (threadData.lastRequestUID, content)
|
threadData.lastRedirectMsg = (threadData.lastRequestUID, content)
|
||||||
|
|
||||||
|
responseMsg = "HTTP response "
|
||||||
|
responseMsg += "[#%d] (%d %s):\n" % (threadData.lastRequestUID, code, getUnicode(msg))
|
||||||
|
if headers:
|
||||||
|
logHeaders = "\n".join(["%s: %s" % (key.capitalize() if isinstance(key, basestring) else key, getUnicode(value)) for (key, value) in headers.items()])
|
||||||
|
else:
|
||||||
|
logHeaders = ""
|
||||||
|
|
||||||
|
if conf.verbose <= 5:
|
||||||
|
responseMsg += getUnicode(logHeaders)
|
||||||
|
elif conf.verbose > 5:
|
||||||
|
responseMsg += "%s\n%s\n" % (logHeaders, content)
|
||||||
|
|
||||||
|
logger.log(7, responseMsg)
|
||||||
|
|
||||||
if "location" in headers:
|
if "location" in headers:
|
||||||
result.redurl = headers.getheaders("location")[0].split("?")[0]
|
result.redurl = headers.getheaders("location")[0].split("?")[0]
|
||||||
elif "uri" in headers:
|
elif "uri" in headers:
|
||||||
|
@ -50,7 +67,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||||
logger.debug(dbgMsg)
|
logger.debug(dbgMsg)
|
||||||
|
|
||||||
result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
|
result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
|
||||||
return self.common_http_redirect(result, headers, code, content)
|
return self.common_http_redirect(result, headers, code, content, msg)
|
||||||
|
|
||||||
def http_error_302(self, req, fp, code, msg, headers):
|
def http_error_302(self, req, fp, code, msg, headers):
|
||||||
self.infinite_loop_check(req)
|
self.infinite_loop_check(req)
|
||||||
|
@ -64,7 +81,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||||
logger.debug(dbgMsg)
|
logger.debug(dbgMsg)
|
||||||
|
|
||||||
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
|
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
|
||||||
return self.common_http_redirect(result, headers, code, content)
|
return self.common_http_redirect(result, headers, code, content, msg)
|
||||||
|
|
||||||
def infinite_loop_check(self, req):
|
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):
|
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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user