Optimized imports on swipedown.py.

Working on integrating sql.py with webscrape to make it automated.

Renamed errmsg variables to be reflective of their origin. Editor threw an error for each former errmsg variable.
This commit is contained in:
arcad3luke 2023-01-29 20:17:51 -05:00
parent de38351ce4
commit cbb7847b37

279
sqlmap.py
View File

@ -117,17 +117,17 @@ def checkEnvironment():
try: try:
os.path.isdir(modulePath()) os.path.isdir(modulePath())
except UnicodeEncodeError: except UnicodeEncodeError:
errMsg = "your system does not properly handle non-ASCII paths. " Uni_errMsg = '''your system does not properly handle non-ASCII paths. \n
errMsg += "Please move the sqlmap's directory to the other location" Please move the sqlmap's directory to the other location'''
logger.critical(errMsg) logger.critical(Uni_errMsg)
raise SystemExit raise SystemExit
if LooseVersion(VERSION) < LooseVersion("1.0"): if LooseVersion(VERSION) < LooseVersion("1.0"):
errMsg = "your runtime environment (e.g. PYTHONPATH) is " Loose_errMsg = '''your runtime environment (e.g. PYTHONPATH) is \n"
errMsg += "broken. Please make sure that you are not running " broken. Please make sure that you are not running \n"
errMsg += "newer versions of sqlmap with runtime scripts for older " newer versions of sqlmap with runtime scripts for older \n"
errMsg += "versions" versions'''
logger.critical(errMsg) logger.critical(Loose_errMsg)
raise SystemExit raise SystemExit
# Patch for pip (import) environment # Patch for pip (import) environment
@ -211,8 +211,8 @@ def main():
crawl(target) crawl(target)
except Exception as ex: except Exception as ex:
if target and not isinstance(ex, SqlmapUserQuitException): if target and not isinstance(ex, SqlmapUserQuitException):
errMsg = "problem occurred while crawling '%s' ('%s')" % (target, getSafeExString(ex)) Quit_errMsg = "problem occurred while crawling '%s' ('%s')" % (target, getSafeExString(ex))
logger.error(errMsg) logger.error(Quit_errMsg)
else: else:
raise raise
else: else:
@ -224,16 +224,16 @@ def main():
os._exitcode = 1 os._exitcode = 1
if "can't start new thread" in getSafeExString(ex): if "can't start new thread" in getSafeExString(ex):
errMsg = "unable to start new threads. Please check OS (u)limits" thread_errMsg = "unable to start new threads. Please check OS (u)limits"
logger.critical(errMsg) logger.critical(thread_errMsg)
raise SystemExit raise SystemExit
else: else:
raise raise
except SqlmapUserQuitException: except SqlmapUserQuitException:
if not conf.batch: if not conf.batch:
errMsg = "user quit" user_errMsg = "user quit"
logger.error(errMsg) logger.error(user_errMsg)
except (SqlmapSilentQuitException, bdb.BdbQuit): except (SqlmapSilentQuitException, bdb.BdbQuit):
pass pass
@ -242,8 +242,8 @@ def main():
cmdLineOptions.sqlmapShell = False cmdLineOptions.sqlmapShell = False
except SqlmapBaseException as ex: except SqlmapBaseException as ex:
errMsg = getSafeExString(ex) base_errMsg = getSafeExString(ex)
logger.critical(errMsg) logger.critical(base_errMsg)
os._exitcode = 1 os._exitcode = 1
@ -258,182 +258,184 @@ def main():
except EOFError: except EOFError:
print() print()
errMsg = "exit" exit_errMsg = "exit"
logger.error(errMsg) logger.error(exit_errMsg)
except SystemExit as ex: except SystemExit as ex:
os._exitcode = ex.code or 0 os._exitcode = ex.code or 0
except: except Exception as e:
print() print(e)
errMsg = unhandledExceptionMessage() Exception_errmsg = unhandledExceptionMessage()
excMsg = traceback.format_exc() excMsg = traceback.format_exc()
valid = checkIntegrity() valid = checkIntegrity()
os._exitcode = 255 os._exitcode = 255
if any(_ in excMsg for _ in ("MemoryError", "Cannot allocate memory")): if any(_ in excMsg for _ in ("MemoryError", "Cannot allocate memory")):
errMsg = "memory exhaustion detected" mem_errMsg = "memory exhaustion detected"
logger.critical(errMsg) logger.critical(mem_errMsg)
raise SystemExit raise SystemExit
elif any(_ in excMsg for _ in ("No space left", "Disk quota exceeded", "Disk full while accessing")): elif any(_ in excMsg for _ in ("No space left", "Disk quota exceeded", "Disk full while accessing")):
errMsg = "no space left on output device" no_space_errMsg = "no space left on output device"
logger.critical(errMsg) logger.critical(no_space_errMsg)
raise SystemExit raise SystemExit
elif any(_ in excMsg for _ in ("The paging file is too small",)): elif any(_ in excMsg for _ in ("The paging file is too small",)):
errMsg = "no space left for paging file" page_small_errMsg = "no space left for paging file"
logger.critical(errMsg) logger.critical(page_small_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("Access is denied", "subprocess", "metasploit")): elif all(_ in excMsg for _ in ("Access is denied", "subprocess", "metasploit")):
errMsg = "permission error occurred while running Metasploit" no_root_errMsg = "permission error occurred while running Metasploit"
logger.critical(errMsg) logger.critical(no_root_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("Permission denied", "metasploit")): elif all(_ in excMsg for _ in ("Permission denied", "metasploit")):
errMsg = "permission error occurred while using Metasploit" permissions_errMsg = "permission error occurred while using Metasploit"
logger.critical(errMsg) logger.critical(permissions_errMsg)
raise SystemExit raise SystemExit
elif "Read-only file system" in excMsg: elif "Read-only file system" in excMsg:
errMsg = "output device is mounted as read-only" RO_errMsg = "output device is mounted as read-only"
logger.critical(errMsg) logger.critical(RO_errMsg)
raise SystemExit raise SystemExit
elif "Insufficient system resources" in excMsg: elif "Insufficient system resources" in excMsg:
errMsg = "resource exhaustion detected" no_ram_errMsg = "resource exhaustion detected"
logger.critical(errMsg) logger.critical(no_ram_errMsg)
raise SystemExit raise SystemExit
elif "OperationalError: disk I/O error" in excMsg: elif "OperationalError: disk I/O error" in excMsg:
errMsg = "I/O error on output device" IO_errMsg = "I/O error on output device"
logger.critical(errMsg) logger.critical(IO_errMsg)
raise SystemExit raise SystemExit
elif "Violation of BIDI" in excMsg: elif "Violation of BIDI" in excMsg:
errMsg = "invalid URL (violation of Bidi IDNA rule - RFC 5893)" BIDI_errMsg = "invalid URL (violation of Bidi IDNA rule - RFC 5893)"
logger.critical(errMsg) logger.critical(BIDI_errMsg)
raise SystemExit raise SystemExit
elif "Invalid IPv6 URL" in excMsg: elif "Invalid IPv6 URL" in excMsg:
errMsg = "invalid URL ('%s')" % excMsg.strip().split('\n')[-1] bad_IPv6_errMsg = "invalid URL ('%s')" % excMsg.strip().split('\n')[-1]
logger.critical(errMsg) logger.critical(bad_IPv6_errMsg)
raise SystemExit raise SystemExit
elif "_mkstemp_inner" in excMsg: elif "_mkstemp_inner" in excMsg:
errMsg = "there has been a problem while accessing temporary files" tmp_errMsg = "there has been a problem while accessing temporary files"
logger.critical(errMsg) logger.critical(tmp_errMsg)
raise SystemExit raise SystemExit
elif any(_ in excMsg for _ in ("tempfile.mkdtemp", "tempfile.mkstemp", "tempfile.py")): elif any(_ in excMsg for _ in ("tempfile.mkdtemp", "tempfile.mkstemp", "tempfile.py")):
errMsg = "unable to write to the temporary directory '%s'. " % tempfile.gettempdir() temp_write_errMsg = '''unable to write to the temporary directory '%s'. " % tempfile.gettempdir() \n
errMsg += "Please make sure that your disk is not full and " Please make sure that your disk is not full and \n
errMsg += "that you have sufficient write permissions to " that you have sufficient write permissions to \n
errMsg += "create temporary files and/or directories" create temporary files and/or directories'''
logger.critical(errMsg) logger.critical(temp_write_errMsg)
raise SystemExit raise SystemExit
elif "Permission denied: '" in excMsg: elif "Permission denied: '" in excMsg:
match = re.search(r"Permission denied: '([^']*)", excMsg) match = re.search(r"Permission denied: '([^']*)", excMsg)
errMsg = "permission error occurred while accessing file '%s'" % match.group(1) denied_errMsg = "permission error occurred while accessing file '%s'" % match.group(1)
logger.critical(errMsg) logger.critical(denied_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("twophase", "sqlalchemy")): elif all(_ in excMsg for _ in ("twophase", "sqlalchemy")):
errMsg = "please update the 'sqlalchemy' package (>= 1.1.11) " update_errMsg = '''please update the 'sqlalchemy' package (>= 1.1.11) \n
errMsg += "(Reference: 'https://qiita.com/tkprof/items/7d7b2d00df9c5f16fffe')" (Reference: 'https://qiita.com/tkprof/items/7d7b2d00df9c5f16fffe')'''
logger.critical(errMsg) logger.critical(update_errMsg)
raise SystemExit raise SystemExit
elif "invalid maximum character passed to PyUnicode_New" in excMsg and re.search(r"\A3\.[34]", sys.version) is not None: elif "invalid maximum character passed to PyUnicode_New" in excMsg and re.search(r"\A3\.[34]", sys.version) is not None:
errMsg = "please upgrade the Python version (>= 3.5) " py_version_errMsg = '''please upgrade the Python version (>= 3.5) \n
errMsg += "(Reference: 'https://bugs.python.org/issue18183')" (Reference: 'https://bugs.python.org/issue18183')'''
logger.critical(errMsg) logger.critical(py_version_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("scramble_caching_sha2", "TypeError")): elif all(_ in excMsg for _ in ("scramble_caching_sha2", "TypeError")):
errMsg = "please downgrade the 'PyMySQL' package (=< 0.8.1) " PyMySQL_errMsg = '''please downgrade the 'PyMySQL' package (=< 0.8.1) \n
errMsg += "(Reference: 'https://github.com/PyMySQL/PyMySQL/issues/700')" (Reference: 'https://github.com/PyMySQL/PyMySQL/issues/700')'''
logger.critical(errMsg) logger.critical(PyMySQL_errMsg)
raise SystemExit raise SystemExit
elif "must be pinned buffer, not bytearray" in excMsg: elif "must be pinned buffer, not bytearray" in excMsg:
errMsg = "error occurred at Python interpreter which " buffer_pin_errMsg = '''error occurred at Python interpreter which \n
errMsg += "is fixed in 2.7. Please update accordingly " is fixed in 2.7. Please update accordingly \n
errMsg += "(Reference: 'https://bugs.python.org/issue8104')" (Reference: 'https://bugs.python.org/issue8104')'''
logger.critical(errMsg) logger.critical(buffer_pin_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("OSError: [Errno 22] Invalid argument: '", "importlib")): elif all(_ in excMsg for _ in ("OSError: [Errno 22] Invalid argument: '", "importlib")):
errMsg = "unable to read file '%s'" % extractRegexResult(r"OSError: \[Errno 22\] Invalid argument: '(?P<result>[^']+)", excMsg) importlib_errMsg = "unable to read file '%s'" % extractRegexResult(r"OSError: \[Errno 22\] Invalid argument: '(?P<result>[^']+)", excMsg)
logger.critical(errMsg) logger.critical(importlib_errMsg)
raise SystemExit raise SystemExit
elif "hash_randomization" in excMsg: elif "hash_randomization" in excMsg:
errMsg = "error occurred at Python interpreter which " hash_random_errMsg = '''error occurred at Python interpreter which \n
errMsg += "is fixed in 2.7.3. Please update accordingly " is fixed in 2.7.3. Please update accordingly \n
errMsg += "(Reference: 'https://docs.python.org/2/library/sys.html')" (Reference: 'https://docs.python.org/2/library/sys.html')'''
logger.critical(errMsg) logger.critical(hash_random_errMsg)
raise SystemExit raise SystemExit
elif "AttributeError: unable to access item" in excMsg and re.search(r"3\.11\.\d+a", sys.version): elif "AttributeError: unable to access item" in excMsg and re.search(r"3\.11\.\d+a", sys.version):
errMsg = "there is a known issue when sqlmap is run with ALPHA versions of Python 3.11. " alpha_errMsg = '''there is a known issue when sqlmap is run with ALPHA versions of Python 3.11. \n
errMsg += "Please downgrade to some stable Python version" Please downgrade to some stable Python version.'''
logger.critical(errMsg) logger.critical(alpha_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("Resource temporarily unavailable", "os.fork()", "dictionaryAttack")): elif all(_ in excMsg for _ in ("Resource temporarily unavailable", "os.fork()", "dictionaryAttack")):
errMsg = "there has been a problem while running the multiprocessing hash cracking. " no_dict_attack_errMsg = '''there has been a problem while running the multiprocessing hash cracking. "
errMsg += "Please rerun with option '--threads=1'" Please rerun with option '--threads=1' '''
logger.critical(errMsg) logger.critical(no_dict_attack_errMsg)
raise SystemExit raise SystemExit
elif "can't start new thread" in excMsg: elif "can't start new thread" in excMsg:
errMsg = "there has been a problem while creating new thread instance. " new_thread_errMsg = '''there has been a problem while creating new thread instance. \n
errMsg += "Please make sure that you are not running too many processes" Please make sure that you are not running too many processes'''
if not IS_WIN: if not IS_WIN:
errMsg += " (or increase the 'ulimit -u' value)" new_thread_errMsg += " (or increase the 'ulimit -u' value)"
logger.critical(errMsg) logger.critical(new_thread_errMsg)
raise SystemExit raise SystemExit
elif "can't allocate read lock" in excMsg: elif "can't allocate read lock" in excMsg:
errMsg = "there has been a problem in regular socket operation " new_line = '\n'
errMsg += "('%s')" % excMsg.strip().split('\n')[-1] socket_errMsg = f'''there has been a problem in regular socket operation "
logger.critical(errMsg) {'%s' % excMsg.strip().split(new_line)[-1]}'''
logger.critical(socket_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("pymysql", "configparser")): elif all(_ in excMsg for _ in ("pymysql", "configparser")):
errMsg = "wrong initialization of 'pymsql' detected (using Python3 dependencies)" pymsql_errMsg = "wrong initialization of 'pymsql' detected (using Python3 dependencies)"
logger.critical(errMsg) logger.critical(pymsql_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("ntlm", "socket.error, err", "SyntaxError")): elif all(_ in excMsg for _ in ("ntlm", "socket.error, err", "SyntaxError")):
errMsg = "wrong initialization of 'python-ntlm' detected (using Python2 syntax)" python_ntlm_errMsg = "wrong initialization of 'python-ntlm' detected (using Python2 syntax)"
logger.critical(errMsg) logger.critical(python_ntlm_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("drda", "to_bytes")): elif all(_ in excMsg for _ in ("drda", "to_bytes")):
errMsg = "wrong initialization of 'drda' detected (using Python3 syntax)" drda_errMsg = "wrong initialization of 'drda' detected (using Python3 syntax)"
logger.critical(errMsg) logger.critical(drda_errMsg)
raise SystemExit raise SystemExit
elif "'WebSocket' object has no attribute 'status'" in excMsg: elif "'WebSocket' object has no attribute 'status'" in excMsg:
errMsg = "wrong websocket library detected" websocket_errMsg = '''wrong websocket library detected"
errMsg += " (Reference: 'https://github.com/sqlmapproject/sqlmap/issues/4572#issuecomment-775041086')" (Reference: 'https://github.com/sqlmapproject/sqlmap/issues/4572#issuecomment-775041086')'''
logger.critical(errMsg) logger.critical(websocket_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("window = tkinter.Tk()",)): elif all(_ in excMsg for _ in ("window = tkinter.Tk()",)):
errMsg = "there has been a problem in initialization of GUI interface " new_line = '\n'
errMsg += "('%s')" % excMsg.strip().split('\n')[-1] GUI_errMsg = f'''there has been a problem in initialization of GUI interface \n
logger.critical(errMsg) {'%s' % excMsg.strip().split(new_line)[-1]}'''
logger.critical(GUI_errMsg)
raise SystemExit raise SystemExit
elif any(_ in excMsg for _ in ("unable to access item 'liveTest'",)): elif any(_ in excMsg for _ in ("unable to access item 'liveTest'",)):
errMsg = "detected usage of files from different versions of sqlmap" livetest_errMsg = "detected usage of files from different versions of sqlmap"
logger.critical(errMsg) logger.critical(livetest_errMsg)
raise SystemExit raise SystemExit
elif kb.get("dumpKeyboardInterrupt"): elif kb.get("dumpKeyboardInterrupt"):
@ -443,10 +445,10 @@ def main():
raise SystemExit raise SystemExit
elif valid is False: elif valid is False:
errMsg = "code integrity check failed (turning off automatic issue creation). " integrity_errMsg = f'''code integrity check failed (turning off automatic issue creation). \n
errMsg += "You should retrieve the latest development version from official GitHub " You should retrieve the latest development version from official GitHub \n
errMsg += "repository at '%s'" % GIT_PAGE repository at {'%s' % GIT_PAGE}'''
logger.critical(errMsg) logger.critical(integrity_errMsg)
print() print()
dataToStdout(excMsg) dataToStdout(excMsg)
raise SystemExit raise SystemExit
@ -458,62 +460,65 @@ def main():
raise SystemExit raise SystemExit
elif any(_ in excMsg for _ in ("ImportError", "ModuleNotFoundError", "<frozen", "Can't find file for module", "SAXReaderNotAvailable", "source code string cannot contain null bytes", "No module named", "tp_name field", "module 'sqlite3' has no attribute 'OperationalError'")): elif any(_ in excMsg for _ in ("ImportError", "ModuleNotFoundError", "<frozen", "Can't find file for module", "SAXReaderNotAvailable", "source code string cannot contain null bytes", "No module named", "tp_name field", "module 'sqlite3' has no attribute 'OperationalError'")):
errMsg = "invalid runtime environment ('%s')" % excMsg.split("Error: ")[-1].strip() module_bad_runtime_errMsg = "invalid runtime environment ('%s')" % excMsg.split("Error: ")[-1].strip()
logger.critical(errMsg) logger.critical(module_bad_runtime_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("SyntaxError: Non-ASCII character", ".py on line", "but no encoding declared")): elif all(_ in excMsg for _ in ("SyntaxError: Non-ASCII character", ".py on line", "but no encoding declared")):
errMsg = "invalid runtime environment ('%s')" % excMsg.split("Error: ")[-1].strip() non_ascii_errMsg = "invalid runtime environment ('%s')" % excMsg.split("Error: ")[-1].strip()
logger.critical(errMsg) logger.critical(non_ascii_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("PermissionError: [WinError 5]", "multiprocessing")): elif all(_ in excMsg for _ in ("PermissionError: [WinError 5]", "multiprocessing")):
errMsg = "there is a permission problem in running multiprocessing on this system. " win_error_5_errMsg = f'''there is a permission problem in running multiprocessing on this system. \n
errMsg += "Please rerun with '--disable-multi'" Please rerun with '--disable-multi' '''
logger.critical(errMsg) logger.critical(win_error_5_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("No such file", "_'")): elif all(_ in excMsg for _ in ("No such file", "_'")):
errMsg = "corrupted installation detected ('%s'). " % excMsg.strip().split('\n')[-1] new_line = '\n'
errMsg += "You should retrieve the latest development version from official GitHub " corrupt_install_errMsg = f'''corrupted installation detected {'%s' % excMsg.strip().split(new_line)[-1]}. \n
errMsg += "repository at '%s'" % GIT_PAGE You should retrieve the latest development version from official GitHub "
logger.critical(errMsg) repository at {'%s' % GIT_PAGE}'''
logger.critical(corrupt_install_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("No such file", "sqlmap.conf", "Test")): elif all(_ in excMsg for _ in ("No such file", "sqlmap.conf", "Test")):
errMsg = "you are trying to run (hidden) development tests inside the production environment" sqlmap_conf_errMsg = "you are trying to run (hidden) development tests inside the production environment"
logger.critical(errMsg) logger.critical(sqlmap_conf_errMsg)
raise SystemExit raise SystemExit
elif all(_ in excMsg for _ in ("HTTPNtlmAuthHandler", "'str' object has no attribute 'decode'")): elif all(_ in excMsg for _ in ("HTTPNtlmAuthHandler", "'str' object has no attribute 'decode'")):
errMsg = "package 'python-ntlm' has a known compatibility issue with the " HTTPNtlmAuthHandler_errMsg = '''package 'python-ntlm' has a known compatibility issue with the \n
errMsg += "Python 3 (Reference: 'https://github.com/mullender/python-ntlm/pull/61')" Python 3 (Reference: 'https://github.com/mullender/python-ntlm/pull/61')'''
logger.critical(errMsg) logger.critical(HTTPNtlmAuthHandler_errMsg)
raise SystemExit raise SystemExit
elif "'DictObject' object has no attribute '" in excMsg and all(_ in errMsg for _ in ("(fingerprinted)", "(identified)")): elif "'DictObject' object has no attribute '" in excMsg and all(_ in Exception_errmsg for _ in ("(fingerprinted)", "(identified)")):
errMsg = "there has been a problem in enumeration. " dictobject_errMsg = '''there has been a problem in enumeration. \n
errMsg += "Because of a considerable chance of false-positive case " Because of a considerable chance of false-positive case \n
errMsg += "you are advised to rerun with switch '--flush-session'" you are advised to rerun with switch '--flush-session' '''
logger.critical(errMsg) logger.critical(dictobject_errMsg)
raise SystemExit raise SystemExit
elif "database disk image is malformed" in excMsg: elif "database disk image is malformed" in excMsg:
errMsg = "local session file seems to be malformed. Please rerun with '--flush-session'" bad_session_errMsg = "local session file seems to be malformed. Please rerun with '--flush-session'"
logger.critical(errMsg) logger.critical(bad_session_errMsg)
raise SystemExit raise SystemExit
elif "AttributeError: 'module' object has no attribute 'F_GETFD'" in excMsg: elif "AttributeError: 'module' object has no attribute 'F_GETFD'" in excMsg:
errMsg = "invalid runtime (\"%s\") " % excMsg.split("Error: ")[-1].strip() F_GETFD_errMsg = f'''invalid runtime {'%s' % excMsg.split("Error: ")[-1].strip()} \n
errMsg += "(Reference: 'https://stackoverflow.com/a/38841364' & 'https://bugs.python.org/issue24944#msg249231')" (Reference: \n
logger.critical(errMsg) 'https://stackoverflow.com/a/38841364' &\n
'https://bugs.python.org/issue24944#msg249231')'''
logger.critical(F_GETFD_errMsg)
raise SystemExit raise SystemExit
elif "bad marshal data (unknown type code)" in excMsg: elif "bad marshal data (unknown type code)" in excMsg:
match = re.search(r"\s*(.+)\s+ValueError", excMsg) match = re.search(r"\s*(.+)\s+ValueError", excMsg)
errMsg = "one of your .pyc files are corrupted%s" % (" ('%s')" % match.group(1) if match else "") bad_marshal_errMsg = f'''one of your .pyc files are corrupted{'%s' % (" ('%s')" % match.group(1) if match else "")}. \n
errMsg += ". Please delete .pyc files on your system to fix the problem" Please delete .pyc files on your system to fix the problem.'''
logger.critical(errMsg) logger.critical(bad_marshal_errMsg)
raise SystemExit raise SystemExit
for match in re.finditer(r'File "(.+?)", line', excMsg): for match in re.finditer(r'File "(.+?)", line', excMsg):
@ -530,15 +535,15 @@ def main():
file_ = re.sub(r"/{2,}", '/', file_) file_ = re.sub(r"/{2,}", '/', file_)
excMsg = excMsg.replace(match.group(1), file_) excMsg = excMsg.replace(match.group(1), file_)
errMsg = maskSensitiveData(errMsg) api_errMsg = maskSensitiveData(errMsg)
excMsg = maskSensitiveData(excMsg) excMsg = maskSensitiveData(excMsg)
if conf.get("api") or not valid: if conf.get("api") or not valid:
logger.critical("%s\n%s" % (errMsg, excMsg)) logger.critical("%s\n%s" % (api_errMsg, excMsg))
else: else:
logger.critical(errMsg) logger.critical(api_errMsg)
dataToStdout("%s\n" % setColor(excMsg.strip(), level=logging.CRITICAL)) dataToStdout("%s\n" % setColor(excMsg.strip(), level=logging.CRITICAL))
createGithubIssue(errMsg, excMsg) createGithubIssue(api_errMsg, excMsg)
finally: finally:
kb.threadContinue = False kb.threadContinue = False
@ -575,8 +580,8 @@ def main():
with openFile(conf.harFile, "w+b") as f: with openFile(conf.harFile, "w+b") as f:
json.dump(conf.httpCollector.obtain(), fp=f, indent=4, separators=(',', ': ')) json.dump(conf.httpCollector.obtain(), fp=f, indent=4, separators=(',', ': '))
except SqlmapBaseException as ex: except SqlmapBaseException as ex:
errMsg = getSafeExString(ex) base_errMsg = getSafeExString(ex)
logger.critical(errMsg) logger.critical(base_errMsg)
if conf.get("api"): if conf.get("api"):
conf.databaseCursor.disconnect() conf.databaseCursor.disconnect()
@ -603,12 +608,12 @@ if __name__ == "__main__":
pass pass
except SystemExit: except SystemExit:
raise raise
except: except IOError:
traceback.print_exc() traceback.print_exc()
finally: finally:
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
if threading.active_count() > 1: if threading.active_count() > 1:
os._exit(getattr(os, "_exitcode", 0)) sys.exit(getattr(os, "_exitcode", 0))
else: else:
sys.exit(getattr(os, "_exitcode", 0)) sys.exit(getattr(os, "_exitcode", 0))
else: else: