From 6607a240cf955555c2cced2b21ad1bd3c7972303 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 17 Mar 2011 12:21:27 +0000 Subject: [PATCH] added logging to redirecthandler --- lib/request/redirecthandler.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index be9743249..30e684869 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -9,7 +9,10 @@ See the file 'doc/COPYING' for copying permission import urllib2 +from lib.core.data import conf 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.threads import getCurrentThreadData @@ -22,10 +25,24 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): # assuming we're in a loop 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.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: result.redurl = headers.getheaders("location")[0].split("?")[0] elif "uri" in headers: @@ -50,7 +67,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): logger.debug(dbgMsg) 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): self.infinite_loop_check(req) @@ -64,7 +81,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): logger.debug(dbgMsg) 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): 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):