Skip to content

Commit 1f9bf58

Browse files
committed
Implementation for an Issue sqlmapproject#3108
1 parent f0e4c20 commit 1f9bf58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+113
-99
lines changed

lib/core/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,20 +868,20 @@ def boldifyMessage(message):
868868
retVal = message
869869

870870
if any(_ in message for _ in BOLD_PATTERNS):
871-
retVal = setColor(message, True)
871+
retVal = setColor(message, bold=True)
872872

873873
return retVal
874874

875-
def setColor(message, bold=False):
875+
def setColor(message, color=None, bold=False):
876876
retVal = message
877877
level = extractRegexResult(r"\[(?P<result>%s)\]" % '|'.join(_[0] for _ in getPublicTypeMembers(LOGGING_LEVELS)), message) or kb.get("stickyLevel")
878878

879879
if isinstance(level, unicode):
880880
level = unicodeencode(level)
881881

882882
if message and getattr(LOGGER_HANDLER, "is_tty", False): # colorizing handler
883-
if bold:
884-
retVal = colored(message, color=None, on_color=None, attrs=("bold",))
883+
if bold or color:
884+
retVal = colored(message, color=color, on_color=None, attrs=("bold",) if bold else None)
885885
elif level:
886886
level = getattr(logging, level, None) if isinstance(level, basestring) else level
887887
retVal = LOGGER_HANDLER.colorize(message, level)
@@ -925,7 +925,7 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
925925
if conf.get("api"):
926926
sys.stdout.write(message, status, content_type)
927927
else:
928-
sys.stdout.write(setColor(message, bold))
928+
sys.stdout.write(setColor(message, bold=bold))
929929

930930
sys.stdout.flush()
931931
except IOError:

lib/core/option.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from lib.core.common import runningAsAdmin
5555
from lib.core.common import safeExpandUser
5656
from lib.core.common import saveConfig
57+
from lib.core.common import setColor
5758
from lib.core.common import setOptimize
5859
from lib.core.common import setPaths
5960
from lib.core.common import singleTimeWarnMessage
@@ -699,6 +700,22 @@ def _setDBMS():
699700

700701
break
701702

703+
def _listTamperingFunctions():
704+
"""
705+
Lists available tamper functions
706+
"""
707+
708+
if conf.listTampers:
709+
infoMsg = "listing available tamper scripts\n"
710+
logger.info(infoMsg)
711+
712+
for script in sorted(glob.glob(os.path.join(paths.SQLMAP_TAMPER_PATH, "*.py"))):
713+
content = openFile(script, "rb").read()
714+
match = re.search(r'(?s)__priority__.+"""(.+)"""', content)
715+
if match:
716+
comment = match.group(1).strip()
717+
dataToStdout("* %s - %s\n" % (setColor(os.path.basename(script), "yellow"), re.sub(r" *\n *", " ", comment.split("\n\n")[0].strip())))
718+
702719
def _setTamperingFunctions():
703720
"""
704721
Loads tampering functions from given script(s)
@@ -2459,6 +2476,7 @@ def init():
24592476
_setDNSServer()
24602477
_adjustLoggingFormatter()
24612478
_setMultipleTargets()
2479+
_listTamperingFunctions()
24622480
_setTamperingFunctions()
24632481
_setWafFunctions()
24642482
_setTrafficOutputFP()

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
"disableColoring": "boolean",
228228
"googlePage": "integer",
229229
"identifyWaf": "boolean",
230+
"listTampers": "boolean",
230231
"mobile": "boolean",
231232
"offline": "boolean",
232233
"purge": "boolean",

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.2.7.27"
22+
VERSION = "1.2.7.28"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/parse/cmdline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ def cmdLineParser(argv=None):
637637
miscellaneous.add_option("--identify-waf", dest="identifyWaf", action="store_true",
638638
help="Make a thorough testing for a WAF/IPS/IDS protection")
639639

640+
miscellaneous.add_option("--list-tampers", dest="listTampers", action="store_true",
641+
help="Display list of available tamper scripts")
642+
640643
miscellaneous.add_option("--mobile", dest="mobile", action="store_true",
641644
help="Imitate smartphone through HTTP User-Agent header")
642645

@@ -874,9 +877,9 @@ def _(self, *args):
874877
if args.dummy:
875878
args.url = args.url or DUMMY_URL
876879

877-
if not any((args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.wizard, args.dependencies, args.purge, args.sitemapUrl)):
878-
errMsg = "missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, -x, --wizard, --update, --purge or --dependencies), "
879-
errMsg += "use -h for basic or -hh for advanced help\n"
880+
if not any((args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.wizard, args.dependencies, args.purge, args.sitemapUrl, args.listTampers)):
881+
errMsg = "missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, -x, --list-tampers, --wizard, --update, --purge or --dependencies). "
882+
errMsg += "Use -h for basic and -hh for advanced help\n"
880883
parser.error(errMsg)
881884

882885
return args

sqlmap.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ googlePage = 1
778778
# Valid: True or False
779779
identifyWaf = False
780780

781+
# Display list of available tamper scripts
782+
# Valid: True or False
783+
listTampers = False
784+
781785
# Imitate smartphone through HTTP User-Agent header.
782786
# Valid: True or False
783787
mobile = False

tamper/apostrophemask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def dependencies():
1414

1515
def tamper(payload, **kwargs):
1616
"""
17-
Replaces apostrophe character (') with its UTF-8 full width counterpart
17+
Replaces apostrophe character (') with its UTF-8 full width counterpart (e.g. ' -> %EF%BC%87)
1818
1919
References:
2020
* http://www.utf8-chartable.de/unicode-utf8-table.pl?start=65280&number=128

tamper/apostrophenullencode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def dependencies():
1414

1515
def tamper(payload, **kwargs):
1616
"""
17-
Replaces apostrophe character (') with its illegal double unicode counterpart
17+
Replaces apostrophe character (') with its illegal double unicode counterpart (e.g. ' -> %00%27)
1818
1919
>>> tamper("1 AND '1'='1")
2020
'1 AND %00%271%00%27=%00%271'

tamper/appendnullbyte.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def dependencies():
1818

1919
def tamper(payload, **kwargs):
2020
"""
21-
Appends encoded NULL byte character (%00) at the end of payload
21+
Appends (Access) NULL byte character (%00) at the end of payload
2222
2323
Requirement:
2424
* Microsoft Access

tamper/base64encode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def dependencies():
1717

1818
def tamper(payload, **kwargs):
1919
"""
20-
Base64 all characters in a given payload
20+
Base64-encodes all characters in a given payload
2121
2222
>>> tamper("1' AND SLEEP(5)#")
2323
'MScgQU5EIFNMRUVQKDUpIw=='

0 commit comments

Comments
 (0)