Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 258e9fb

Browse files
committed
fix for a "bug" reported by Spencer J. McIntyre (os.makedirs(conf.outputPath, 0755) -> permission denied)
1 parent 69c4f94 commit 258e9fb

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

lib/core/target.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import codecs
1111
import os
1212
import re
13+
import tempfile
1314
import time
1415

1516
from lib.core.common import dataToSessionFile
@@ -231,13 +232,29 @@ def __createTargetDirs():
231232
Create the output directory.
232233
"""
233234

234-
conf.outputPath = "%s%s%s" % (paths.SQLMAP_OUTPUT_PATH, os.sep, conf.hostname)
235-
236235
if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH):
237-
os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755)
236+
try:
237+
os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755)
238+
except:
239+
tempDir = tempfile.mkdtemp(prefix='output')
240+
warnMsg = "unable to create default root output directory at "
241+
warnMsg += "'%s'. using temporary directory '%s' instead" % (paths.SQLMAP_OUTPUT_PATH, tempDir)
242+
logger.warn(warnMsg)
243+
244+
paths.SQLMAP_OUTPUT_PATH = tempDir
245+
246+
conf.outputPath = "%s%s%s" % (paths.SQLMAP_OUTPUT_PATH, os.sep, conf.hostname)
238247

239248
if not os.path.isdir(conf.outputPath):
240-
os.makedirs(conf.outputPath, 0755)
249+
try:
250+
os.makedirs(conf.outputPath, 0755)
251+
except:
252+
tempDir = tempfile.mkdtemp(prefix='output')
253+
warnMsg = "unable to create output directory '%s'. " % conf.outputPath
254+
warnMsg += "using temporary directory '%s' instead" % tempDir
255+
logger.warn(warnMsg)
256+
257+
conf.outputPath = tempDir
241258

242259
__createDumpDir()
243260
__createFilesDir()

0 commit comments

Comments
 (0)