Implementation for an Issue #195

This commit is contained in:
Miroslav Stampar 2012-09-25 10:17:25 +02:00
parent 9ca7b3e20e
commit c9e7e71ea2
2 changed files with 11 additions and 8 deletions

View File

@ -117,6 +117,7 @@ from lib.core.threads import getCurrentThreadData
from lib.core.update import update from lib.core.update import update
from lib.parse.configfile import configFileParser from lib.parse.configfile import configFileParser
from lib.parse.payloads import loadPayloads from lib.parse.payloads import loadPayloads
from lib.request.basic import checkCharEncoding
from lib.request.connect import Connect as Request from lib.request.connect import Connect as Request
from lib.request.dns import DNSServer from lib.request.dns import DNSServer
from lib.request.proxy import ProxyHTTPSHandler from lib.request.proxy import ProxyHTTPSHandler
@ -1965,13 +1966,14 @@ def __basicOptionValidation():
raise sqlmapSyntaxException, errMsg raise sqlmapSyntaxException, errMsg
if conf.charset: if conf.charset:
try: _ = checkCharEncoding(conf.charset, False)
codecs.lookup(conf.charset) if _ is None:
except LookupError:
errMsg = "unknown charset '%s'. Please visit " % conf.charset errMsg = "unknown charset '%s'. Please visit " % conf.charset
errMsg += "'%s' to get the full list of " % CODECS_LIST_PAGE errMsg += "'%s' to get the full list of " % CODECS_LIST_PAGE
errMsg += "supported charsets" errMsg += "supported charsets"
raise sqlmapSyntaxException, errMsg raise sqlmapSyntaxException, errMsg
else:
conf.charset = _
if conf.loadCookies: if conf.loadCookies:
if not os.path.exists(conf.loadCookies): if not os.path.exists(conf.loadCookies):

View File

@ -100,14 +100,14 @@ def parseResponse(page, headers):
if page: if page:
htmlParser(page) htmlParser(page)
def checkCharEncoding(encoding): def checkCharEncoding(encoding, warn=True):
if encoding: if encoding:
encoding = encoding.lower() encoding = encoding.lower()
else: else:
return encoding return encoding
# http://www.destructor.de/charsets/index.htm # http://www.destructor.de/charsets/index.htm
translate = { "windows-874": "iso-8859-11", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8"} translate = { "windows-874": "iso-8859-11", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8", "ebcdic": "ebcdic-cp-be"}
for delimiter in (';', ',', '('): for delimiter in (';', ',', '('):
if delimiter in encoding: if delimiter in encoding:
@ -156,9 +156,10 @@ def checkCharEncoding(encoding):
try: try:
codecs.lookup(encoding) codecs.lookup(encoding)
except LookupError: except LookupError:
warnMsg = "unknown web page charset '%s'. " % encoding if warn:
warnMsg += "Please report by e-mail to %s." % ML warnMsg = "unknown web page charset '%s'. " % encoding
singleTimeLogMessage(warnMsg, logging.WARN, encoding) warnMsg += "Please report by e-mail to %s." % ML
singleTimeLogMessage(warnMsg, logging.WARN, encoding)
encoding = None encoding = None
return encoding return encoding