From c5a2567033a5ae1394aa5b9b5863c13d757789d0 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 6 May 2019 15:39:11 +0200 Subject: [PATCH] Minor DREI patch (leaky multiprocessing) --- lib/core/common.py | 1 + lib/core/option.py | 6 ++++++ lib/core/patch.py | 13 +++++++++++++ lib/core/settings.py | 2 +- sqlmap.py | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 2a91c3510..fbfbd0073 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4650,6 +4650,7 @@ def decloakToTemp(filename): >>> _ = decloakToTemp(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.asp_")) >>> openFile(_, "rb", encoding=None).read().startswith(b'<%') True + >>> os.remove(_) """ content = decloak(filename) diff --git a/lib/core/option.py b/lib/core/option.py index 162bb136d..9f3e8ee9a 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1519,6 +1519,9 @@ def _createHomeDirectories(): paths["SQLMAP_%s_PATH" % context.upper()] = tempDir +def _pympTempLeakPatch(tempDir): # Cross-referenced function + raise NotImplementedError + def _createTemporaryDirectory(): """ Creates temporary directory for this run. @@ -1570,6 +1573,9 @@ def _createTemporaryDirectory(): errMsg += "temporary directory location ('%s')" % getSafeExString(ex) raise SqlmapSystemException(errMsg) + if six.PY3: + _pympTempLeakPatch(kb.tempDir) + def _cleanupOptions(): """ Cleanup configuration attributes. diff --git a/lib/core/patch.py b/lib/core/patch.py index 5fc1be330..e32d8b2cf 100644 --- a/lib/core/patch.py +++ b/lib/core/patch.py @@ -11,6 +11,7 @@ import lib.controller.checks import lib.core.common import lib.core.threads import lib.core.convert +import lib.core.option import lib.request.connect import lib.utils.search import thirdparty.ansistrm.ansistrm @@ -61,8 +62,20 @@ def resolveCrossReferences(): lib.core.convert.filterNone = filterNone lib.core.convert.isListLike = isListLike lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage + lib.core.option._pympTempLeakPatch = pympTempLeakPatch lib.request.connect.setHTTPHandlers = _setHTTPHandlers lib.utils.search.setHTTPHandlers = _setHTTPHandlers lib.controller.checks.setVerbosity = setVerbosity lib.controller.checks.setWafFunctions = _setWafFunctions thirdparty.ansistrm.ansistrm.stdoutencode = stdoutencode + +def pympTempLeakPatch(tempDir): + """ + Patch for "pymp" leaking directories inside Python3 + """ + + try: + import multiprocessing.util + multiprocessing.util.get_temp_dir = lambda: tempDir + except: + pass \ No newline at end of file diff --git a/lib/core/settings.py b/lib/core/settings.py index c4f2c0405..b870e44e8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.3.5.29" +VERSION = "1.3.5.30" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/sqlmap.py b/sqlmap.py index 667e61253..b74912277 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -378,7 +378,7 @@ def main(): except OSError: pass - if not filterNone(filepath for filepath in glob.glob(os.path.join(kb.tempDir, '*')) if not any(filepath.endswith(_) for _ in ('.lock', '.exe', '_'))): + if not filterNone(filepath for filepath in glob.glob(os.path.join(kb.tempDir, '*')) if not any(filepath.endswith(_) for _ in (".lock", ".exe", ".so", '_'))): # ignore junk files try: shutil.rmtree(kb.tempDir, ignore_errors=True) except OSError: