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

Skip to content

Commit cc07e5d

Browse files
committed
added --charset option to force charset encoding of the retrieved data (e.g. when the backend collation is different than the current web page charset) as requested by devon.mitchell1988@y​ahoo.com
1 parent dfe81cc commit cc07e5d

5 files changed

Lines changed: 58 additions & 38 deletions

File tree

lib/core/option.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,15 @@ def __basicOptionValidation():
16361636
errMsg = "value for --union-cols must be a range with hyphon (e.g. 1-10)"
16371637
raise sqlmapSyntaxException, errMsg
16381638

1639+
if conf.charset:
1640+
try:
1641+
codecs.lookup(conf.charset)
1642+
except LookupError:
1643+
errMsg = "unknown charset '%s'. please visit page " % conf.charset
1644+
errMsg += "'http://docs.python.org/library/codecs.html#standard-encodings' "
1645+
errMsg += "to get the full list of supported charsets"
1646+
raise sqlmapSyntaxException, errMsg
1647+
16391648
def init(inputOptions=advancedDict(), overrideOptions=False):
16401649
"""
16411650
Set attributes into both configuration and knowledge base singletons

lib/core/optiondict.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@
150150

151151
"General": {
152152
#"xmlFile": "string",
153-
"trafficFile": "string",
154153
"sessionFile": "string",
154+
"trafficFile": "string",
155+
"batch": "boolean",
156+
"charset": "string",
157+
"eta": "boolean",
155158
"flushSession": "boolean",
156-
"freshQueries": "boolean",
157159
"forms": "boolean",
158-
"eta": "boolean",
159-
"updateAll": "boolean",
160-
"batch": "boolean"
160+
"freshQueries": "boolean",
161+
"updateAll": "boolean"
161162
},
162163

163164
"Miscellaneous": {

lib/parse/cmdline.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,38 +447,41 @@ def cmdLineParser():
447447
#general.add_option("-x", dest="xmlFile",
448448
# help="Dump the data into an XML file")
449449

450-
general.add_option("-t", dest="trafficFile",
451-
help="Log all HTTP traffic into a "
452-
"textual file")
453-
454450
general.add_option("-s", dest="sessionFile",
455451
help="Save and resume all data retrieved "
456452
"on a session file")
457453

458-
general.add_option("--flush-session", dest="flushSession",
459-
action="store_true", default=False,
460-
help="Flush session file for current target")
454+
general.add_option("-t", dest="trafficFile",
455+
help="Log all HTTP traffic into a "
456+
"textual file")
461457

462-
general.add_option("--fresh-queries", dest="freshQueries",
458+
general.add_option("--batch", dest="batch",
463459
action="store_true", default=False,
464-
help="Ignores query results stored in session file")
460+
help="Never ask for user input, use the default behaviour")
461+
462+
general.add_option("--charset", dest="charset",
463+
help="Force character encoding used for data retrieval")
465464

466465
general.add_option("--eta", dest="eta",
467466
action="store_true", default=False,
468467
help="Display for each output the "
469468
"estimated time of arrival")
470469

471-
general.add_option("--update", dest="updateAll",
470+
general.add_option("--flush-session", dest="flushSession",
472471
action="store_true", default=False,
473-
help="Update sqlmap")
472+
help="Flush session file for current target")
473+
474+
general.add_option("--fresh-queries", dest="freshQueries",
475+
action="store_true", default=False,
476+
help="Ignores query results stored in session file")
474477

475478
general.add_option("--save", dest="saveCmdline",
476479
action="store_true", default=False,
477480
help="Save options on a configuration INI file")
478481

479-
general.add_option("--batch", dest="batch",
482+
general.add_option("--update", dest="updateAll",
480483
action="store_true", default=False,
481-
help="Never ask for user input, use the default behaviour")
484+
help="Update sqlmap")
482485

483486
# Miscellaneous options
484487
miscellaneous = OptionGroup(parser, "Miscellaneous")

lib/request/basic.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def checkCharEncoding(encoding):
134134
return None
135135

136136
# http://www.iana.org/assignments/character-sets
137+
# http://docs.python.org/library/codecs.html
137138
try:
138139
codecs.lookup(encoding)
139140
except LookupError:
@@ -173,19 +174,22 @@ def decodePage(page, contentEncoding, contentType):
173174

174175
page = data.read()
175176

176-
httpCharset, metaCharset = None, None
177+
if not conf.charset:
178+
httpCharset, metaCharset = None, None
177179

178-
# http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode
179-
if contentType and (contentType.find('charset=') != -1):
180-
httpCharset = checkCharEncoding(contentType.split('charset=')[-1])
180+
# http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode
181+
if contentType and (contentType.find('charset=') != -1):
182+
httpCharset = checkCharEncoding(contentType.split('charset=')[-1])
181183

182-
metaCharset = checkCharEncoding(extractRegexResult(META_CHARSET_REGEX, page, re.DOTALL | re.IGNORECASE))
184+
metaCharset = checkCharEncoding(extractRegexResult(META_CHARSET_REGEX, page, re.DOTALL | re.IGNORECASE))
183185

184-
if ((httpCharset or metaCharset) and not all([httpCharset, metaCharset]))\
185-
or (httpCharset == metaCharset and all([httpCharset, metaCharset])):
186-
kb.pageEncoding = httpCharset or metaCharset
186+
if ((httpCharset or metaCharset) and not all([httpCharset, metaCharset]))\
187+
or (httpCharset == metaCharset and all([httpCharset, metaCharset])):
188+
kb.pageEncoding = httpCharset or metaCharset
189+
else:
190+
kb.pageEncoding = None
187191
else:
188-
kb.pageEncoding = None
192+
kb.pageEncoding = conf.charset
189193

190194
if contentType and any(map(lambda x: x in contentType.lower(), ('text/txt', 'text/raw', 'text/html', 'text/xml'))):
191195
# can't do for all responses because we need to support binary files too

sqlmap.conf

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,23 @@ regType =
493493
# These options can be used to set some general working parameters.
494494
[General]
495495

496+
# Save and resume all data retrieved on a session file.
497+
sessionFile =
498+
496499
# Log all HTTP traffic into a textual file.
497500
trafficFile =
498501

499-
# Save and resume all data retrieved on a session file.
500-
sessionFile =
502+
# Never ask for user input, use the default behaviour.
503+
# Valid: True or False
504+
batch = False
505+
506+
# Force character encoding used for data retrieval.
507+
charset =
508+
509+
# Retrieve each query output length and calculate the estimated time of
510+
# arrival in real time.
511+
# Valid: True or False
512+
eta = False
501513

502514
# Flush session file for current target.
503515
# Valid: True or False
@@ -507,19 +519,10 @@ flushSession = False
507519
# Valid: True or False
508520
freshQueries = False
509521

510-
# Retrieve each query output length and calculate the estimated time of
511-
# arrival in real time.
512-
# Valid: True or False
513-
eta = False
514-
515522
# Update sqlmap.
516523
# Valid: True or False
517524
updateAll = False
518525

519-
# Never ask for user input, use the default behaviour.
520-
# Valid: True or False
521-
batch = False
522-
523526

524527
[Miscellaneous]
525528

0 commit comments

Comments
 (0)