|
21 | 21 | from lib.core.common import normalizeUnicode |
22 | 22 | from lib.core.common import openFile |
23 | 23 | from lib.core.common import paramToDict |
| 24 | +from lib.core.common import randomStr |
24 | 25 | from lib.core.common import readInput |
25 | 26 | from lib.core.common import resetCookieJar |
26 | 27 | from lib.core.common import urldecode |
@@ -604,28 +605,33 @@ def _createTargetDirs(): |
604 | 605 | Create the output directory. |
605 | 606 | """ |
606 | 607 |
|
607 | | - if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH): |
608 | | - try: |
609 | | - if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH): |
610 | | - os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755) |
611 | | - warnMsg = "using '%s' as the output directory" % paths.SQLMAP_OUTPUT_PATH |
612 | | - logger.warn(warnMsg) |
613 | | - except (OSError, IOError), ex: |
614 | | - try: |
615 | | - tempDir = tempfile.mkdtemp(prefix="sqlmapoutput") |
616 | | - except Exception, _: |
617 | | - errMsg = "unable to write to the temporary directory ('%s'). " % _ |
618 | | - errMsg += "Please make sure that your disk is not full and " |
619 | | - errMsg += "that you have sufficient write permissions to " |
620 | | - errMsg += "create temporary files and/or directories" |
621 | | - raise SqlmapSystemException(errMsg) |
| 608 | + try: |
| 609 | + if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH): |
| 610 | + os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755) |
622 | 611 |
|
623 | | - warnMsg = "unable to create regular output directory " |
624 | | - warnMsg += "'%s' (%s). " % (paths.SQLMAP_OUTPUT_PATH, getUnicode(ex)) |
625 | | - warnMsg += "Using temporary directory '%s' instead" % getUnicode(tempDir) |
| 612 | + _ = os.path.join(paths.SQLMAP_OUTPUT_PATH, randomStr()) |
| 613 | + open(_, "w+b").close() |
| 614 | + os.remove(_) |
| 615 | + |
| 616 | + if conf.outputDir: |
| 617 | + warnMsg = "using '%s' as the output directory" % paths.SQLMAP_OUTPUT_PATH |
626 | 618 | logger.warn(warnMsg) |
| 619 | + except (OSError, IOError), ex: |
| 620 | + try: |
| 621 | + tempDir = tempfile.mkdtemp(prefix="sqlmapoutput") |
| 622 | + except Exception, _: |
| 623 | + errMsg = "unable to write to the temporary directory ('%s'). " % _ |
| 624 | + errMsg += "Please make sure that your disk is not full and " |
| 625 | + errMsg += "that you have sufficient write permissions to " |
| 626 | + errMsg += "create temporary files and/or directories" |
| 627 | + raise SqlmapSystemException(errMsg) |
| 628 | + |
| 629 | + warnMsg = "unable to %s output directory " % ("create" if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH) else "write to the") |
| 630 | + warnMsg += "'%s' (%s). " % (paths.SQLMAP_OUTPUT_PATH, getUnicode(ex)) |
| 631 | + warnMsg += "Using temporary directory '%s' instead" % getUnicode(tempDir) |
| 632 | + logger.warn(warnMsg) |
627 | 633 |
|
628 | | - paths.SQLMAP_OUTPUT_PATH = tempDir |
| 634 | + paths.SQLMAP_OUTPUT_PATH = tempDir |
629 | 635 |
|
630 | 636 | conf.outputPath = os.path.join(getUnicode(paths.SQLMAP_OUTPUT_PATH), normalizeUnicode(getUnicode(conf.hostname))) |
631 | 637 |
|
|
0 commit comments