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

Skip to content

Commit 18aea25

Browse files
committed
added concept of tamper script priority
1 parent 303359e commit 18aea25

13 files changed

Lines changed: 85 additions & 1 deletion

lib/core/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def __init__(self, lineNumber, pageTotal, lineContentBefore, lineContentAfter):
110110
self.lineContentBefore = lineContentBefore
111111
self.lineContentAfter = lineContentAfter
112112

113-
114113
def paramToDict(place, parameters=None):
115114
"""
116115
Split the parameters into names and values, check if these parameters

lib/core/option.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.core.common import parseTargetUrl
3232
from lib.core.common import paths
3333
from lib.core.common import randomRange
34+
from lib.core.common import readInput
3435
from lib.core.common import runningAsAdmin
3536
from lib.core.common import sanitizeStr
3637
from lib.core.common import UnicodeRawConfigParser
@@ -47,7 +48,9 @@
4748
from lib.core.exception import sqlmapMissingPrivileges
4849
from lib.core.exception import sqlmapSyntaxException
4950
from lib.core.exception import sqlmapUnsupportedDBMSException
51+
from lib.core.exception import sqlmapUserQuitException
5052
from lib.core.optiondict import optDict
53+
from lib.core.priority import PRIORITY
5154
from lib.core.settings import IS_WIN
5255
from lib.core.settings import PLATFORM
5356
from lib.core.settings import PYVERSION
@@ -521,6 +524,11 @@ def __setTamperingFunctions():
521524
"""
522525

523526
if conf.tamper:
527+
last_priority = PRIORITY.LOWEST
528+
check_priority = True
529+
resolve_priorities = False
530+
priorities = []
531+
524532
for tfile in conf.tamper.split(','):
525533
found = False
526534

@@ -556,16 +564,41 @@ def __setTamperingFunctions():
556564
except ImportError, msg:
557565
raise sqlmapSyntaxException, "can not import tamper script '%s' (%s)" % (filename[:-3], msg)
558566

567+
priority = PRIORITY.NORMAL if not hasattr(module, '__priority__') else module.__priority__
568+
559569
for name, function in inspect.getmembers(module, inspect.isfunction):
560570
if name == "tamper" and function.func_code.co_argcount == 1:
561571
kb.tamperFunctions.append(function)
562572
found = True
563573

574+
if check_priority and priority < last_priority:
575+
message = "it seems that you've probably "
576+
message += "mixed order of tamper scripts.\n"
577+
message += "do you want to auto resolve this? [Y/n/q]"
578+
test = readInput(message, default="Y")
579+
580+
if not test or test[0] in ("y", "Y"):
581+
resolve_priorities = True
582+
elif test[0] in ("n", "N"):
583+
resolve_priorities = False
584+
elif test[0] in ("q", "Q"):
585+
raise sqlmapUserQuitException
586+
587+
check_priority = False
588+
589+
priorities.append((priority, function))
590+
last_priority = priority
564591
break
565592

566593
if not found:
567594
raise sqlmapGenericException, "missing function 'tamper(value)' in tamper script '%s'" % tfile
568595

596+
if resolve_priorities and priorities:
597+
priorities.sort()
598+
kb.tamperFunctions = []
599+
for _, function in priorities:
600+
kb.tamperFunctions.append(function)
601+
569602
def __setThreads():
570603
if not isinstance(conf.threads, int) or conf.threads <= 0:
571604
conf.threads = 1

lib/core/priority.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
5+
6+
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
7+
See the file 'doc/COPYING' for copying permission
8+
"""
9+
10+
class PRIORITY:
11+
LOWEST = -100
12+
LOWER = -50
13+
LOW = -10
14+
NORMAL = 0
15+
HIGH = 10
16+
HIGHER = 50
17+
HIGHEST = 100

tamper/between.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10+
from lib.core.priority import PRIORITY
11+
12+
__priority__ = PRIORITY.HIGHEST
13+
1014
def tamper(value):
1115
"""
1216
Replaces '>' with 'NOT BETWEEN 0 AND #'

tamper/charencode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import string
1111

1212
from lib.core.exception import sqlmapUnsupportedFeatureException
13+
from lib.core.priority import PRIORITY
14+
15+
__priority__ = PRIORITY.LOWEST
1316

1417
def tamper(value):
1518
"""

tamper/charunicodeencode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import string
1111

1212
from lib.core.exception import sqlmapUnsupportedFeatureException
13+
from lib.core.priority import PRIORITY
14+
15+
__priority__ = PRIORITY.LOWEST
1316

1417
def tamper(value):
1518
"""

tamper/ifnull2ifisnull.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10+
from lib.core.priority import PRIORITY
11+
12+
__priority__ = PRIORITY.HIGHEST
13+
1014
def tamper(value):
1115
"""
1216
Replaces 'IFNULL(A, B)' with 'IF(ISNULL(A), B, A)'

tamper/randomcase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
from lib.core.common import randomRange
1313
from lib.core.data import kb
14+
from lib.core.priority import PRIORITY
15+
16+
__priority__ = PRIORITY.NORMAL
1417

1518
def tamper(value):
1619
"""

tamper/randomcomments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
from lib.core.common import randomRange
1313
from lib.core.data import kb
14+
from lib.core.priority import PRIORITY
15+
16+
__priority__ = PRIORITY.LOW
1417

1518
def tamper(value):
1619
"""

tamper/space2comment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10+
from lib.core.priority import PRIORITY
11+
12+
__priority__ = PRIORITY.LOW
13+
1014
def tamper(value):
1115
"""
1216
Replaces ' ' with '/**/'

0 commit comments

Comments
 (0)