Fixes leakage of sqlmap temporary directories

This commit is contained in:
Miroslav Stampar
2025-07-09 23:18:48 +02:00
parent da65936a3c
commit de10cff3e0
4 changed files with 13 additions and 10 deletions

View File

@@ -567,17 +567,17 @@ def main():
kb.threadException = True
if kb.get("tempDir"):
for tempDir in conf.get("tempDirs", []):
for prefix in (MKSTEMP_PREFIX.IPC, MKSTEMP_PREFIX.TESTING, MKSTEMP_PREFIX.COOKIE_JAR, MKSTEMP_PREFIX.BIG_ARRAY):
for filepath in glob.glob(os.path.join(kb.tempDir, "%s*" % prefix)):
for filepath in glob.glob(os.path.join(tempDir, "%s*" % prefix)):
try:
os.remove(filepath)
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", ".so", '_'))): # ignore junk files
if any((conf.vulnTest, conf.smokeTest)) or not filterNone(filepath for filepath in glob.glob(os.path.join(tempDir, '*')) if not any(filepath.endswith(_) for _ in (".lock", ".exe", ".so", '_'))): # ignore junk files
try:
shutil.rmtree(kb.tempDir, ignore_errors=True)
shutil.rmtree(tempDir, ignore_errors=True)
except OSError:
pass