Skip to content

Commit ef2038f

Browse files
committed
Implementation for an Issue sqlmapproject#253
1 parent c40dded commit ef2038f

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

lib/core/common.py

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -759,43 +759,60 @@ def readInput(message, default=None, checkBatch=True):
759759
Reads input from terminal
760760
"""
761761

762+
retVal = None
762763
kb.stickyLevel = None
763764

764765
if "\n" in message:
765766
message += "%s> " % ("\n" if message.count("\n") > 1 else "")
766767
elif message[-1] == ']':
767768
message += " "
768769

769-
if checkBatch and conf.batch:
770-
if isListLike(default):
771-
options = ",".join(getUnicode(opt, UNICODE_ENCODING) for opt in default)
772-
elif default:
773-
options = getUnicode(default, UNICODE_ENCODING)
774-
else:
775-
options = unicode()
770+
if conf.answers:
771+
for item in conf.answers.split(','):
772+
question = item.split('=')[0].strip()
773+
answer = item.split('=')[1] if len(item.split('=')) > 1 else None
774+
if answer and question.lower() in message.lower():
775+
retVal = getUnicode(answer, UNICODE_ENCODING)
776776

777-
infoMsg = "%s%s" % (getUnicode(message), options)
778-
logger.info(infoMsg)
777+
infoMsg = "%s%s" % (getUnicode(message), retVal)
778+
logger.info(infoMsg)
779779

780-
debugMsg = "used the default behaviour, running in batch mode"
781-
logger.debug(debugMsg)
780+
debugMsg = "used the given answer"
781+
logger.debug(debugMsg)
782782

783-
data = default
784-
else:
785-
logging._acquireLock()
786-
dataToStdout("\r%s" % message, forceOutput=True, bold=True)
787-
kb.prependFlag = False
788-
try:
789-
data = raw_input() or default
790-
data = getUnicode(data, system=True) if data else data
791-
except:
792-
time.sleep(0.05) # Reference: http://www.gossamer-threads.com/lists/python/python/781893
793-
kb.prependFlag = True
794-
raise sqlmapUserQuitException
795-
finally:
796-
logging._releaseLock()
783+
break
797784

798-
return data
785+
if retVal is None:
786+
if checkBatch and conf.batch:
787+
if isListLike(default):
788+
options = ",".join(getUnicode(opt, UNICODE_ENCODING) for opt in default)
789+
elif default:
790+
options = getUnicode(default, UNICODE_ENCODING)
791+
else:
792+
options = unicode()
793+
794+
infoMsg = "%s%s" % (getUnicode(message), options)
795+
logger.info(infoMsg)
796+
797+
debugMsg = "used the default behaviour, running in batch mode"
798+
logger.debug(debugMsg)
799+
800+
retVal = default
801+
else:
802+
logging._acquireLock()
803+
dataToStdout("\r%s" % message, forceOutput=True, bold=True)
804+
kb.prependFlag = False
805+
try:
806+
retVal = raw_input() or default
807+
retVal = getUnicode(retVal, system=True) if retVal else retVal
808+
except:
809+
time.sleep(0.05) # Reference: http://www.gossamer-threads.com/lists/python/python/781893
810+
kb.prependFlag = True
811+
raise sqlmapUserQuitException
812+
finally:
813+
logging._releaseLock()
814+
815+
return retVal
799816

800817
def randomRange(start=0, stop=1000):
801818
"""

lib/core/optiondict.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
},
191191

192192
"Miscellaneous": {
193+
"mnemonics": "string",
194+
"answers": "string",
193195
"checkPayload": "boolean",
194196
"cleanup": "boolean",
195197
"dependencies": "boolean",

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ def cmdLineParser():
604604
miscellaneous.add_option("-z", dest="mnemonics",
605605
help="Use short mnemonics (e.g. \"flu,bat,ban,tec=EU\")")
606606

607+
miscellaneous.add_option("--answers", dest="answers",
608+
help="Set question answers (e.g. \"quit=N,follow=N\")")
609+
607610
miscellaneous.add_option("--check-payload", dest="checkPayload",
608611
action="store_true",
609612
help="Offline WAF/IPS/IDS payload detection testing")

sqlmap.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ updateAll = False
650650

651651
[Miscellaneous]
652652

653+
# Use short mnemonics (e.g. "flu,bat,ban,tec=EU")
654+
mnemonics =
655+
656+
# Set question answers (e.g. "quit=N,follow=N")
657+
answers =
658+
653659
# Offline WAF/IPS/IDS payload detection testing.
654660
checkPayload = False
655661

0 commit comments

Comments
 (0)