Skip to content

Commit fc8eede

Browse files
committed
Minor cleanup and one bug fix
1 parent c8a0c52 commit fc8eede

File tree

19 files changed

+91
-106
lines changed

19 files changed

+91
-106
lines changed

lib/controller/checks.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,15 +739,15 @@ def genCmpPayload():
739739
logger.warn(warnMsg)
740740

741741
msg = "how do you want to proceed? [(S)kip current test/(e)nd detection phase/(n)ext parameter/(c)hange verbosity/(q)uit]"
742-
choice = readInput(msg, default='S', checkBatch=False).strip().upper()
742+
choice = readInput(msg, default='S', checkBatch=False).upper()
743743

744744
if choice == 'C':
745745
choice = None
746746
while not ((choice or "").isdigit() and 0 <= int(choice) <= 6):
747747
if choice:
748748
logger.warn("invalid value")
749749
msg = "enter new verbosity level: [0-6] "
750-
choice = readInput(msg, default=str(conf.verbose), checkBatch=False).strip()
750+
choice = readInput(msg, default=str(conf.verbose), checkBatch=False)
751751
conf.verbose = int(choice)
752752
setVerbosity()
753753
tests.insert(0, test)
@@ -998,7 +998,7 @@ def _(page):
998998

999999
if kb.ignoreCasted is None:
10001000
message = "do you want to skip those kind of cases (and save scanning time)? %s " % ("[Y/n]" if conf.multipleTargets else "[y/N]")
1001-
kb.ignoreCasted = readInput(message, default='Y' if conf.multipleTargets else 'N').upper() != 'N'
1001+
kb.ignoreCasted = readInput(message, default='Y' if conf.multipleTargets else 'N', boolean=True)
10021002

10031003
elif result:
10041004
infoMsg += "be injectable"
@@ -1176,7 +1176,7 @@ def checkStability():
11761176
logger.warn(warnMsg)
11771177

11781178
message = "how do you want to proceed? [(C)ontinue/(s)tring/(r)egex/(q)uit] "
1179-
choice = readInput(message, default='C').strip().upper()
1179+
choice = readInput(message, default='C').upper()
11801180

11811181
if choice == 'Q':
11821182
raise SqlmapUserQuitException
@@ -1306,9 +1306,8 @@ def checkWaf():
13061306
if not conf.identifyWaf:
13071307
message = "do you want sqlmap to try to detect backend "
13081308
message += "WAF/IPS/IDS? [y/N] "
1309-
output = readInput(message, default="N")
13101309

1311-
if output and output[0] in ("Y", "y"):
1310+
if readInput(message, default='N', boolean=True):
13121311
conf.identifyWaf = True
13131312

13141313
if conf.timeout == defaults.timeout:

lib/controller/controller.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ def _selectInjection():
116116
message += "\n"
117117

118118
message += "[q] Quit"
119-
select = readInput(message, default="0")
119+
choice = readInput(message, default='0').upper()
120120

121-
if select.isdigit() and int(select) < len(kb.injections) and int(select) >= 0:
122-
index = int(select)
123-
elif select[0] in ("Q", "q"):
121+
if choice.isdigit() and int(choice) < len(kb.injections) and int(choice) >= 0:
122+
index = int(choice)
123+
elif choice == 'Q':
124124
raise SqlmapUserQuitException
125125
else:
126126
errMsg = "invalid choice"
@@ -184,7 +184,7 @@ def _randomFillBlankFields(value):
184184
if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, value):
185185
message = "do you want to fill blank fields with random values? [Y/n] "
186186

187-
if readInput(message, default="Y", boolean=True):
187+
if readInput(message, default='Y', boolean=True):
188188
for match in re.finditer(EMPTY_FORM_FIELDS_REGEX, retVal):
189189
item = match.group("result")
190190
if not any(_ in item for _ in IGNORE_PARAMETERS) and not re.search(ASP_NET_CONTROL_REGEX, item):
@@ -306,7 +306,7 @@ def start():
306306
message += "against '%s'. Do you want to skip " % conf.hostname
307307
message += "further tests involving it? [Y/n]"
308308

309-
kb.skipVulnHost = readInput(message, default="Y", boolean=True)
309+
kb.skipVulnHost = readInput(message, default='Y', boolean=True)
310310

311311
testSqlInj = not kb.skipVulnHost
312312

@@ -334,7 +334,7 @@ def start():
334334
continue
335335

336336
message += "\ndo you want to test this form? [Y/n/q] "
337-
choice = readInput(message, default='Y').strip().upper()
337+
choice = readInput(message, default='Y').upper()
338338

339339
if choice == 'N':
340340
continue
@@ -360,7 +360,7 @@ def start():
360360

361361
else:
362362
message += "\ndo you want to test this URL? [Y/n/q]"
363-
choice = readInput(message, default='Y').strip().upper()
363+
choice = readInput(message, default='Y').upper()
364364

365365
if choice == 'N':
366366
dataToStdout(os.linesep)
@@ -640,7 +640,7 @@ def start():
640640
logger.warn(warnMsg)
641641

642642
message = "do you want to skip to the next target in list? [Y/n/q]"
643-
choice = readInput(message, default='Y').strip().upper()
643+
choice = readInput(message, default='Y').upper()
644644

645645
if choice == 'N':
646646
return False

lib/core/common.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ def setDbms(dbms):
322322
msg += "correct [%s (default)/%s] " % (kb.dbms, dbms)
323323

324324
while True:
325-
_ = readInput(msg, default=kb.dbms)
325+
choice = readInput(msg, default=kb.dbms)
326326

327-
if aliasToDbmsEnum(_) == kb.dbms:
327+
if aliasToDbmsEnum(choice) == kb.dbms:
328328
kb.dbmsVersion = []
329329
kb.resolutionDbms = kb.dbms
330330
break
331-
elif aliasToDbmsEnum(_) == dbms:
332-
kb.dbms = aliasToDbmsEnum(_)
331+
elif aliasToDbmsEnum(choice) == dbms:
332+
kb.dbms = aliasToDbmsEnum(choice)
333333
break
334334
else:
335335
warnMsg = "invalid value"
@@ -382,12 +382,12 @@ def setOs(os):
382382
msg += "correct [%s (default)/%s] " % (kb.os, os)
383383

384384
while True:
385-
_ = readInput(msg, default=kb.os)
385+
choice = readInput(msg, default=kb.os)
386386

387-
if _ == kb.os:
387+
if choice == kb.os:
388388
break
389-
elif _ == os:
390-
kb.os = _.capitalize()
389+
elif choice == os:
390+
kb.os = choice.capitalize()
391391
break
392392
else:
393393
warnMsg = "invalid value"
@@ -421,10 +421,10 @@ def setArch():
421421
msg += "\n[2] 64-bit"
422422

423423
while True:
424-
_ = readInput(msg, default='1')
424+
choice = readInput(msg, default='1')
425425

426-
if isinstance(_, basestring) and _.isdigit() and int(_) in (1, 2):
427-
kb.arch = 32 if int(_) == 1 else 64
426+
if isinstance(choice, basestring) and choice.isdigit() and int(choice) in (1, 2):
427+
kb.arch = 32 if int(choice) == 1 else 64
428428
break
429429
else:
430430
warnMsg = "invalid value. Valid values are 1 and 2"
@@ -754,17 +754,17 @@ def getManualDirectories():
754754
message += "[2] custom location(s)\n"
755755
message += "[3] custom directory list file\n"
756756
message += "[4] brute force search"
757-
choice = readInput(message, default="1").strip()
757+
choice = readInput(message, default='1')
758758

759-
if choice == "2":
759+
if choice == '2':
760760
message = "please provide a comma separate list of absolute directory paths: "
761761
directories = readInput(message, default="").split(',')
762-
elif choice == "3":
762+
elif choice == '3':
763763
message = "what's the list file location?\n"
764764
listPath = readInput(message, default="")
765765
checkFile(listPath)
766766
directories = getFileItems(listPath)
767-
elif choice == "4":
767+
elif choice == '4':
768768
targets = set([conf.hostname])
769769
_ = conf.hostname.split('.')
770770

@@ -1038,8 +1038,11 @@ def readInput(message, default=None, checkBatch=True, boolean=False):
10381038
finally:
10391039
logging._releaseLock()
10401040

1041+
if retVal and default and isinstance(default, basestring) and len(default) == 1:
1042+
retVal = retVal.strip()
1043+
10411044
if boolean:
1042-
retVal = retVal.strip().upper == 'Y'
1045+
retVal = retVal.strip().upper() == 'Y'
10431046

10441047
return retVal
10451048

lib/core/option.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def _setTamperingFunctions():
944944
message = "it appears that you might have mixed "
945945
message += "the order of tamper scripts. "
946946
message += "Do you want to auto resolve this? [Y/n/q] "
947-
choice = readInput(message, default='Y').strip().upper()
947+
choice = readInput(message, default='Y').upper()
948948

949949
if choice == 'N':
950950
resolve_priorities = False

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.1.4.37"
22+
VERSION = "1.1.4.38"
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/core/target.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def process(match, repl):
152152
elif re.search(JSON_LIKE_RECOGNITION_REGEX, conf.data):
153153
message = "JSON-like data found in %s data. " % conf.method
154154
message += "Do you want to process it? [Y/n/q] "
155-
choice = readInput(message, default='Y').strip().upper()
155+
choice = readInput(message, default='Y').upper()
156156

157157
if choice == 'Q':
158158
raise SqlmapUserQuitException
@@ -166,7 +166,7 @@ def process(match, repl):
166166
elif re.search(ARRAY_LIKE_RECOGNITION_REGEX, conf.data):
167167
message = "Array-like data found in %s data. " % conf.method
168168
message += "Do you want to process it? [Y/n/q] "
169-
choice = readInput(message, default='Y').strip().upper()
169+
choice = readInput(message, default='Y').upper()
170170

171171
if choice == 'Q':
172172
raise SqlmapUserQuitException
@@ -178,7 +178,7 @@ def process(match, repl):
178178
elif re.search(XML_RECOGNITION_REGEX, conf.data):
179179
message = "SOAP/XML data found in %s data. " % conf.method
180180
message += "Do you want to process it? [Y/n/q] "
181-
choice = readInput(message, default='Y').strip().upper()
181+
choice = readInput(message, default='Y').upper()
182182

183183
if choice == 'Q':
184184
raise SqlmapUserQuitException
@@ -191,7 +191,7 @@ def process(match, repl):
191191
elif re.search(MULTIPART_RECOGNITION_REGEX, conf.data):
192192
message = "Multipart-like data found in %s data. " % conf.method
193193
message += "Do you want to process it? [Y/n/q] "
194-
choice = readInput(message, default='Y').strip().upper()
194+
choice = readInput(message, default='Y').upper()
195195

196196
if choice == 'Q':
197197
raise SqlmapUserQuitException
@@ -228,7 +228,7 @@ def process(match, repl):
228228

229229
message = "do you want to try URI injections "
230230
message += "in the target URL itself? [Y/n/q] "
231-
choice = readInput(message, default='Y').strip().upper()
231+
choice = readInput(message, default='Y').upper()
232232

233233
if choice == 'Q':
234234
raise SqlmapUserQuitException
@@ -243,7 +243,7 @@ def process(match, repl):
243243
lut = {PLACE.URI: '-u', PLACE.CUSTOM_POST: '--data', PLACE.CUSTOM_HEADER: '--headers/--user-agent/--referer/--cookie'}
244244
message = "custom injection marking character ('%s') found in option " % CUSTOM_INJECTION_MARK_CHAR
245245
message += "'%s'. Do you want to process it? [Y/n/q] " % lut[place]
246-
choice = readInput(message, default='Y').strip().upper()
246+
choice = readInput(message, default='Y').upper()
247247

248248
if choice == 'Q':
249249
raise SqlmapUserQuitException

lib/request/inject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _goInferenceProxy(expression, fromUser=False, batch=False, unpack=True, char
208208
message += "entries do you want to retrieve?\n"
209209
message += "[a] All (default)\n[#] Specific number\n"
210210
message += "[q] Quit"
211-
choice = readInput(message, default='A').strip().upper()
211+
choice = readInput(message, default='A').upper()
212212

213213
if choice == 'A':
214214
stopLimit = count

lib/request/redirecthandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _ask_redirect_choice(self, redcode, redurl, method):
5959
msg += "resend original POST data to a new "
6060
msg += "location? [%s] " % ("Y/n" if not kb.originalPage else "y/N")
6161

62-
kb.resendPostOnRedirect = readInput(msg, default=("Y" if not kb.originalPage else "N"), boolean=True)
62+
kb.resendPostOnRedirect = readInput(msg, default=('Y' if not kb.originalPage else 'N'), boolean=True)
6363

6464
if kb.resendPostOnRedirect:
6565
self.redirect_request = self._redirect_request

lib/takeover/udf.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ def udfInjectCore(self, udfDict):
154154

155155
message = "do you want to proceed anyway? Beware that the "
156156
message += "operating system takeover will fail [y/N] "
157-
choice = readInput(message, default="N")
158157

159-
if choice and choice.lower() == "y":
158+
if readInput(message, default='N', boolean=True):
160159
written = True
161160
else:
162161
return False
@@ -237,20 +236,16 @@ def udfInjectCustom(self):
237236
msg += "from the shared library? "
238237

239238
while True:
240-
udfCount = readInput(msg, default=1)
239+
udfCount = readInput(msg, default='1')
241240

242-
if isinstance(udfCount, basestring) and udfCount.isdigit():
241+
if udfCount.isdigit():
243242
udfCount = int(udfCount)
244243

245244
if udfCount <= 0:
246245
logger.info("nothing to inject then")
247246
return
248247
else:
249248
break
250-
251-
elif isinstance(udfCount, int):
252-
break
253-
254249
else:
255250
logger.warn("invalid value, only digits are allowed")
256251

@@ -272,20 +267,16 @@ def udfInjectCustom(self):
272267

273268
self.udfs[udfName]["input"] = []
274269

275-
default = 1
276270
msg = "how many input parameters takes UDF "
277-
msg += "'%s'? (default: %d) " % (udfName, default)
271+
msg += "'%s'? (default: 1) " % udfName
278272

279273
while True:
280-
parCount = readInput(msg, default=default)
274+
parCount = readInput(msg, default='1')
281275

282-
if isinstance(parCount, basestring) and parCount.isdigit() and int(parCount) >= 0:
276+
if parCount.isdigit() and int(parCount) >= 0:
283277
parCount = int(parCount)
284278
break
285279

286-
elif isinstance(parCount, int):
287-
break
288-
289280
else:
290281
logger.warn("invalid value, only digits >= 0 are allowed")
291282

@@ -294,9 +285,9 @@ def udfInjectCustom(self):
294285
msg += "number %d? (default: %s) " % ((y + 1), defaultType)
295286

296287
while True:
297-
parType = readInput(msg, default=defaultType)
288+
parType = readInput(msg, default=defaultType).strip()
298289

299-
if isinstance(parType, basestring) and parType.isdigit():
290+
if parType.isdigit():
300291
logger.warn("you need to specify the data-type of the parameter")
301292

302293
else:
@@ -323,7 +314,7 @@ def udfInjectCustom(self):
323314

324315
msg = "do you want to call your injected user-defined "
325316
msg += "functions now? [Y/n/q] "
326-
choice = readInput(msg, default='Y').strip().upper()
317+
choice = readInput(msg, default='Y').upper()
327318

328319
if choice == 'N':
329320
self.cleanup(udfDict=self.udfs)
@@ -343,7 +334,7 @@ def udfInjectCustom(self):
343334
msg += "\n[q] Quit"
344335

345336
while True:
346-
choice = readInput(msg).strip().upper()
337+
choice = readInput(msg).upper()
347338

348339
if choice == 'Q':
349340
break

lib/utils/hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def attackDumpedTable():
482482
storeHashesToFile(attack_dict)
483483

484484
message = "do you want to crack them via a dictionary-based attack? %s" % ("[y/N/q]" if conf.multipleTargets else "[Y/n/q]")
485-
choice = readInput(message, default='N' if conf.multipleTargets else 'Y').strip().upper()
485+
choice = readInput(message, default='N' if conf.multipleTargets else 'Y').upper()
486486

487487
if choice == 'N':
488488
return

0 commit comments

Comments
 (0)