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

Skip to content

Commit 65b2b0a

Browse files
committed
adding switch --eval
1 parent 0ce885e commit 65b2b0a

7 files changed

Lines changed: 47 additions & 3 deletions

File tree

lib/core/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3135,4 +3135,11 @@ def getHostHeader(url):
31353135
if any(map(lambda x: retVal.endswith(':%d' % x), [80, 443])):
31363136
retVal = retVal.split(':')[0]
31373137

3138-
return retVal
3138+
return retVal
3139+
3140+
def executeCode(code, variables=None):
3141+
try:
3142+
exec(code, variables)
3143+
except Exception, ex:
3144+
errMsg = "an error occured while evaluating provided code ('%s'). " % ex
3145+
raise sqlmapGenericException, errMsg

lib/core/option.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,6 @@ def __setKnowledgeBaseAttributes(flushAll=True):
14021402
kb.dynamicMarkings = []
14031403
kb.dynamicParameters = False
14041404
kb.endDetection = False
1405-
kb.httpErrorCodes = {}
14061405
kb.explicitSettings = set()
14071406
kb.errorIsNone = True
14081407
kb.forcedDbms = None
@@ -1411,6 +1410,8 @@ def __setKnowledgeBaseAttributes(flushAll=True):
14111410
kb.heuristicTest = None
14121411
kb.hintValue = None
14131412
kb.htmlFp = []
1413+
kb.httpErrorCodes = {}
1414+
kb.inferenceMode = False
14141415
kb.ignoreTimeout = False
14151416
kb.injection = InjectionDict()
14161417
kb.injections = []

lib/core/optiondict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"retries": "integer",
4545
"scope": "string",
4646
"safUrl": "string",
47-
"saFreq": "integer"
47+
"saFreq": "integer",
48+
"evalCode": "string"
4849
},
4950

5051
"Optimization": {

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def cmdLineParser():
140140
request.add_option("--safe-freq", dest="saFreq", type="int",
141141
help="Test requests between two visits to a given safe url")
142142

143+
request.add_option("--eval", dest="evalCode",
144+
help="Evaluate provided Python code before the request (e.g. \"import hashlib;id2=hashlib.md5(str(id)).hexdigest()\")")
145+
143146
# Optimization options
144147
optimization = OptionGroup(parser, "Optimization", "These "
145148
"options can be used to optimize the "

lib/request/connect.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from lib.core.common import calculateDeltaSeconds
2323
from lib.core.common import clearConsoleLine
2424
from lib.core.common import cpuThrottle
25+
from lib.core.common import executeCode
2526
from lib.core.common import extractRegexResult
2627
from lib.core.common import getCurrentThreadData
2728
from lib.core.common import getFilteredPageContent
@@ -603,6 +604,31 @@ def _randomizeParameter(paramString, randomParameter):
603604
elif item == PLACE.COOKIE and cookie:
604605
cookie = _randomizeParameter(cookie, randomParameter)
605606

607+
if conf.evalCode:
608+
variables = {}
609+
originals = {}
610+
611+
if get:
612+
executeCode(get.replace("&", ";"), variables)
613+
if post:
614+
executeCode(post.replace("&", ";"), variables)
615+
616+
originals.update(variables)
617+
executeCode(conf.evalCode, variables)
618+
619+
for name, value in variables.items():
620+
if name != "__builtins__" and originals.get(name, "") != value:
621+
if isinstance(value, (basestring, int)):
622+
value = unicode(value)
623+
if '%s=' % name in (get or ""):
624+
get = re.sub("(%s=)([^&]+)" % name, "\g<1>%s" % value, get)
625+
elif '%s=' % name in (post or ""):
626+
post = re.sub("(%s=)([^&]+)" % name, "\g<1>%s" % value, post)
627+
elif post:
628+
post += "&%s=%s" % (name, value)
629+
else:
630+
get += "&%s=%s" % (name, value)
631+
606632
get = urlencode(get, limit=True)
607633
if post and place != PLACE.POST and hasattr(post, UNENCODED_ORIGINAL_VALUE):
608634
post = getattr(post, UNENCODED_ORIGINAL_VALUE)

lib/request/inject.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def __goInference(payload, expression, charsetType=None, firstChar=None, lastCha
6363

6464
dataToSessionFile("[%s][%s][%s][%s][" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression))
6565

66+
kb.inferenceMode = True
6667
count, value = bisection(payload, expression, length, charsetType, firstChar, lastChar, dump)
68+
kb.inferenceMode = False
6769

6870
if not kb.bruteMode:
6971
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))

sqlmap.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ safUrl =
130130
# Default: 0
131131
saFreq = 0
132132

133+
# Evaluate provided Python code before the request
134+
# Example: import hashlib;id2=hashlib.md5(str(id)).hexdigest()
135+
evalCode =
136+
133137

134138
# These options can be used to optimize the performance of sqlmap.
135139
[Optimization]

0 commit comments

Comments
 (0)