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

Skip to content

Commit 511c3b8

Browse files
committed
Update and fix for an Issue #182
1 parent 10b671d commit 511c3b8

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

lib/core/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8+
class sqlmapCompressionException(Exception):
9+
pass
10+
811
class sqlmapConnectionException(Exception):
912
pass
1013

@@ -60,6 +63,7 @@ class sqlmapValueException(Exception):
6063
pass
6164

6265
exceptionsTuple = (
66+
sqlmapCompressionException,
6367
sqlmapConnectionException,
6468
sqlmapDataException,
6569
sqlmapFilePathException,

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ def __setKnowledgeBaseAttributes(flushAll=True):
15131513
kb.multiThreadMode = False
15141514
kb.negativeLogic = False
15151515
kb.nullConnection = None
1516+
kb.pageCompress = True
15161517
kb.pageTemplate = None
15171518
kb.pageTemplates = dict()
15181519
kb.previousMethod = None

lib/request/basic.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
from lib.core.common import readInput
1919
from lib.core.common import resetCookieJar
2020
from lib.core.common import singleTimeLogMessage
21+
from lib.core.common import singleTimeWarnMessage
2122
from lib.core.data import conf
2223
from lib.core.data import kb
2324
from lib.core.data import logger
2425
from lib.core.enums import HTTPHEADER
2526
from lib.core.enums import PLACE
27+
from lib.core.exception import sqlmapCompressionException
2628
from lib.core.htmlentities import htmlEntities
2729
from lib.core.settings import DEFAULT_COOKIE_DELIMITER
2830
from lib.core.settings import ML
@@ -181,7 +183,7 @@ def decodePage(page, contentEncoding, contentType):
181183

182184
if isinstance(contentEncoding, basestring) and contentEncoding.lower() in ("gzip", "x-gzip", "deflate"):
183185
try:
184-
if contentEncoding == "deflate":
186+
if contentEncoding.lower() == "deflate":
185187
# http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
186188
data = StringIO.StringIO(zlib.decompress(page, -15))
187189
else:
@@ -192,7 +194,12 @@ def decodePage(page, contentEncoding, contentType):
192194
errMsg = "detected invalid data for declared content "
193195
errMsg += "encoding '%s' ('%s')" % (contentEncoding, msg)
194196
singleTimeLogMessage(errMsg, logging.ERROR)
195-
return page
197+
198+
warnMsg = "turning off page compression"
199+
singleTimeWarnMessage(warnMsg)
200+
201+
kb.pageCompress = False
202+
raise sqlmapCompressionException
196203

197204
if not conf.charset:
198205
httpCharset, metaCharset = None, None

lib/request/connect.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from lib.core.enums import PAYLOAD
4747
from lib.core.enums import PLACE
4848
from lib.core.enums import REDIRECTION
49+
from lib.core.exception import sqlmapCompressionException
4950
from lib.core.exception import sqlmapConnectionException
5051
from lib.core.exception import sqlmapSyntaxException
5152
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
@@ -108,7 +109,7 @@ def __retryProxy(**kwargs):
108109
warnMsg += "(e.g. https://help.ubuntu.com/community/Tor)"
109110
else:
110111
warnMsg = "if the problem persists please check that the provided "
111-
warnMsg += "target url is valid. If it is, you can try to rerun "
112+
warnMsg += "target url is valid. In case that it is, you can try to rerun "
112113
warnMsg += "with the switch '--random-agent' turned on "
113114
warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)"
114115
singleTimeWarnMessage(warnMsg)
@@ -279,7 +280,7 @@ def getPage(**kwargs):
279280
headers[HTTPHEADER.PROXY_AUTHORIZATION] = kb.proxyAuthHeader
280281

281282
headers[HTTPHEADER.ACCEPT] = HTTP_ACCEPT_HEADER_VALUE
282-
headers[HTTPHEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if method != HTTPMETHOD.HEAD else "identity"
283+
headers[HTTPHEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if method != HTTPMETHOD.HEAD and kb.pageCompress else "identity"
283284
headers[HTTPHEADER.HOST] = host or getHostHeader(url)
284285

285286
if auxHeaders:
@@ -467,7 +468,7 @@ def getPage(**kwargs):
467468
debugMsg = "got HTTP error code: %d (%s)" % (code, status)
468469
logger.debug(debugMsg)
469470

470-
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, ProxyError), e:
471+
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, ProxyError, sqlmapCompressionException), e:
471472
tbMsg = traceback.format_exc()
472473

473474
if "no host given" in tbMsg:

0 commit comments

Comments
 (0)