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

Skip to content

Commit dce9a76

Browse files
committed
important update regarding restoring of potentially changed switch values in multi-target mode and/or missing switch values in resume mode
1 parent 96341f8 commit dce9a76

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

lib/core/data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# sqlmap paths
2222
paths = advancedDict()
2323

24+
# object to store original command line options
25+
cmdLineOptions = advancedDict()
26+
2427
# object to share within function and classes command
2528
# line options and settings
2629
conf = advancedDict()

lib/core/session.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ def unSafeFormatString(value):
4040
retVal = retVal.replace("__LEFT_SQUARE_BRACKET__", "[").replace("__RIGHT_SQUARE_BRACKET__", "]")
4141
return retVal
4242

43+
def setTextOnly():
44+
"""
45+
Save text only option to session file.
46+
"""
47+
48+
condition = (
49+
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
50+
not kb.resumedQueries[conf.url].has_key("Text only") )
51+
)
52+
53+
if condition:
54+
dataToSessionFile("[%s][None][None][Text only][True]\n" % conf.url)
55+
4356
def setString():
4457
"""
4558
Save string to match in session file.
@@ -263,7 +276,23 @@ def setRemoteTempPath():
263276
dataToSessionFile("[%s][%s][%s][Remote temp path][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(conf.tmpPath)))
264277

265278
def resumeConfKb(expression, url, value):
266-
if expression == "String" and url == conf.url:
279+
if expression == "Text only" and url == conf.url:
280+
value = unSafeFormatString(value[:-1])
281+
282+
logMsg = "resuming text only option '%s' from session file" % value
283+
logger.info(logMsg)
284+
285+
if value and not conf.textOnly:
286+
message = "you did not turned on --text-only switch this time "
287+
message += "which could potentially lead to different "
288+
message += "and/or unstable results. "
289+
message += "Do you want to turn it on? [Y/n] "
290+
test = readInput(message, default="Y")
291+
292+
if not test or test[0] in ("y", "Y"):
293+
conf.textOnly = value
294+
295+
elif expression == "String" and url == conf.url:
267296
string = unSafeFormatString(value[:-1])
268297

269298
logMsg = "resuming string match '%s' from session file" % string

lib/core/target.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from lib.core.common import dataToSessionFile
1717
from lib.core.common import paramToDict
1818
from lib.core.common import readInput
19+
from lib.core.data import cmdLineOptions
1920
from lib.core.data import conf
2021
from lib.core.data import kb
2122
from lib.core.data import logger
@@ -29,6 +30,7 @@
2930
from lib.core.option import __setDBMS
3031
from lib.core.option import __setKnowledgeBaseAttributes
3132
from lib.core.session import resumeConfKb
33+
from lib.core.session import setTextOnly
3234
from lib.core.xmldump import dumper as xmldumper
3335
from lib.request.connect import Connect as Request
3436

@@ -263,6 +265,22 @@ def __createTargetDirs():
263265
__createFilesDir()
264266
__configureDumper()
265267

268+
def __saveSwitches():
269+
"""
270+
Store critical switches to the session file.
271+
"""
272+
if conf.textOnly:
273+
setTextOnly()
274+
275+
def __restoreCmdLineOptions():
276+
"""
277+
Restore command line options that could be possibly
278+
changed during the testing of previous target.
279+
"""
280+
conf.regexp = cmdLineOptions.regexp
281+
conf.string = cmdLineOptions.string
282+
conf.textOnly = cmdLineOptions.textOnly
283+
266284
def initTargetEnv():
267285
"""
268286
Initialize target environment.
@@ -277,9 +295,11 @@ def initTargetEnv():
277295
conf.sessionFile = None
278296

279297
__setKnowledgeBaseAttributes(False)
298+
__restoreCmdLineOptions()
280299
__setDBMS()
281300

282301
def setupTargetEnv():
283302
__createTargetDirs()
284303
__setRequestParams()
285304
__setOutputResume()
305+
__saveSwitches()

sqlmap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.core.common import getUnicode
3030
from lib.core.common import setPaths
3131
from lib.core.common import weAreFrozen
32+
from lib.core.data import cmdLineOptions
3233
from lib.core.data import conf
3334
from lib.core.data import kb
3435
from lib.core.data import logger
@@ -64,7 +65,9 @@ def main():
6465
setPaths()
6566

6667
banner()
67-
cmdLineOptions = cmdLineParser()
68+
69+
# Store original command line options for possible later restoration
70+
cmdLineOptions.update(cmdLineParser().__dict__)
6871

6972
dataToStdout("[*] starting at: %s\n\n" % time.strftime("%X"), forceOutput=True)
7073

0 commit comments

Comments
 (0)