From 511c3b8dcc8ed318fdb9537bd116d9ba87f1b917 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 11 Sep 2012 14:58:52 +0200 Subject: [PATCH] Update and fix for an Issue #182 --- lib/core/exception.py | 4 ++++ lib/core/option.py | 1 + lib/request/basic.py | 11 +++++++++-- lib/request/connect.py | 7 ++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/core/exception.py b/lib/core/exception.py index 67d47f81e..966342e84 100644 --- a/lib/core/exception.py +++ b/lib/core/exception.py @@ -5,6 +5,9 @@ Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ +class sqlmapCompressionException(Exception): + pass + class sqlmapConnectionException(Exception): pass @@ -60,6 +63,7 @@ class sqlmapValueException(Exception): pass exceptionsTuple = ( + sqlmapCompressionException, sqlmapConnectionException, sqlmapDataException, sqlmapFilePathException, diff --git a/lib/core/option.py b/lib/core/option.py index 37928b909..87fbb9019 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1513,6 +1513,7 @@ def __setKnowledgeBaseAttributes(flushAll=True): kb.multiThreadMode = False kb.negativeLogic = False kb.nullConnection = None + kb.pageCompress = True kb.pageTemplate = None kb.pageTemplates = dict() kb.previousMethod = None diff --git a/lib/request/basic.py b/lib/request/basic.py index 8dbb3146e..dc4d8438b 100644 --- a/lib/request/basic.py +++ b/lib/request/basic.py @@ -18,11 +18,13 @@ from lib.core.common import getUnicode from lib.core.common import readInput from lib.core.common import resetCookieJar from lib.core.common import singleTimeLogMessage +from lib.core.common import singleTimeWarnMessage from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger from lib.core.enums import HTTPHEADER from lib.core.enums import PLACE +from lib.core.exception import sqlmapCompressionException from lib.core.htmlentities import htmlEntities from lib.core.settings import DEFAULT_COOKIE_DELIMITER from lib.core.settings import ML @@ -181,7 +183,7 @@ def decodePage(page, contentEncoding, contentType): if isinstance(contentEncoding, basestring) and contentEncoding.lower() in ("gzip", "x-gzip", "deflate"): try: - if contentEncoding == "deflate": + if contentEncoding.lower() == "deflate": # http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations data = StringIO.StringIO(zlib.decompress(page, -15)) else: @@ -192,7 +194,12 @@ def decodePage(page, contentEncoding, contentType): errMsg = "detected invalid data for declared content " errMsg += "encoding '%s' ('%s')" % (contentEncoding, msg) singleTimeLogMessage(errMsg, logging.ERROR) - return page + + warnMsg = "turning off page compression" + singleTimeWarnMessage(warnMsg) + + kb.pageCompress = False + raise sqlmapCompressionException if not conf.charset: httpCharset, metaCharset = None, None diff --git a/lib/request/connect.py b/lib/request/connect.py index 6e5c75381..64840f8f1 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -46,6 +46,7 @@ from lib.core.enums import NULLCONNECTION from lib.core.enums import PAYLOAD from lib.core.enums import PLACE from lib.core.enums import REDIRECTION +from lib.core.exception import sqlmapCompressionException from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapSyntaxException from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR @@ -108,7 +109,7 @@ class Connect: warnMsg += "(e.g. https://help.ubuntu.com/community/Tor)" else: warnMsg = "if the problem persists please check that the provided " - warnMsg += "target url is valid. If it is, you can try to rerun " + warnMsg += "target url is valid. In case that it is, you can try to rerun " warnMsg += "with the switch '--random-agent' turned on " warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)" singleTimeWarnMessage(warnMsg) @@ -279,7 +280,7 @@ class Connect: headers[HTTPHEADER.PROXY_AUTHORIZATION] = kb.proxyAuthHeader headers[HTTPHEADER.ACCEPT] = HTTP_ACCEPT_HEADER_VALUE - headers[HTTPHEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if method != HTTPMETHOD.HEAD else "identity" + headers[HTTPHEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if method != HTTPMETHOD.HEAD and kb.pageCompress else "identity" headers[HTTPHEADER.HOST] = host or getHostHeader(url) if auxHeaders: @@ -467,7 +468,7 @@ class Connect: debugMsg = "got HTTP error code: %d (%s)" % (code, status) logger.debug(debugMsg) - except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, ProxyError), e: + except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, ProxyError, sqlmapCompressionException), e: tbMsg = traceback.format_exc() if "no host given" in tbMsg: