Visitar URL original
Fixes #6133 · sqlmapproject/sqlmap@1d9965d · GitHub
Skip to content

Commit 1d9965d

Browse files
committed
Fixes #6133
1 parent 4d518ff commit 1d9965d

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.9.31"
23+
VERSION = "1.10.9.32"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,12 @@ def _createFilesDir():
666666
if not any((conf.fileRead, conf.commonFiles, conf.xxe)):
667667
return
668668

669-
# Note: normalize the hostname consistently with conf.outputPath / conf.dumpPath (see _createDumpDir)
670-
conf.filePath = paths.SQLMAP_FILES_PATH % normalizeUnicode(getUnicode(conf.hostname))
669+
# Note: normalize the hostname consistently with conf.outputPath / conf.dumpPath (see _createDumpDir).
670+
# safeStringFormat() (not raw '%') because SQLMAP_FILES_PATH embeds SQLMAP_OUTPUT_PATH, which comes
671+
# straight from --output-dir - a literal '%' anywhere in that user-supplied path (e.g. an unexpanded
672+
# '$(date +%Y%m%d)' on a shell that doesn't support command substitution) would otherwise make the
673+
# '%' operator try to parse it as a format directive and crash
674+
conf.filePath = safeStringFormat(paths.SQLMAP_FILES_PATH, normalizeUnicode(getUnicode(conf.hostname)))
671675

672676
if not os.path.isdir(conf.filePath):
673677
try:

‎tests/test_target_parsing.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ def test_files_dir_created_per_host(self):
483483
self.assertTrue(os.path.isdir(conf.filePath))
484484
self.assertIn("example.com", conf.filePath)
485485

486+
def test_files_dir_survives_percent_in_output_dir(self):
487+
# --output-dir carries a literal '%' straight into SQLMAP_FILES_PATH (e.g. an unexpanded
488+
# '$(date +%Y%m%d)' on a shell without command substitution, as in #6133) - the '%' operator
489+
# would try to parse '%Y' as a format directive and crash; safeStringFormat() must not
490+
self._outdir("f_out_%Y%m%d_%H%M%S")
491+
conf.hostname = "example.com"
492+
conf.fileRead = "/etc/passwd"
493+
conf.commonFiles = None
494+
_createFilesDir()
495+
self.assertTrue(os.path.isdir(conf.filePath))
496+
self.assertIn("example.com", conf.filePath)
497+
486498
def test_target_dir_and_target_txt(self):
487499
self._outdir("t_out")
488500
conf.hostname = "example.com"

0 commit comments

Comments
 (0)