diff --git a/sqlmap.py b/sqlmap.py index 2b3c126fb..5f5621fb7 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -117,17 +117,17 @@ def checkEnvironment(): try: os.path.isdir(modulePath()) except UnicodeEncodeError: - errMsg = "your system does not properly handle non-ASCII paths. " - errMsg += "Please move the sqlmap's directory to the other location" - logger.critical(errMsg) + Uni_errMsg = '''your system does not properly handle non-ASCII paths. \n + Please move the sqlmap's directory to the other location''' + logger.critical(Uni_errMsg) raise SystemExit if LooseVersion(VERSION) < LooseVersion("1.0"): - errMsg = "your runtime environment (e.g. PYTHONPATH) is " - errMsg += "broken. Please make sure that you are not running " - errMsg += "newer versions of sqlmap with runtime scripts for older " - errMsg += "versions" - logger.critical(errMsg) + Loose_errMsg = '''your runtime environment (e.g. PYTHONPATH) is \n" + broken. Please make sure that you are not running \n" + newer versions of sqlmap with runtime scripts for older \n" + versions''' + logger.critical(Loose_errMsg) raise SystemExit # Patch for pip (import) environment @@ -211,8 +211,8 @@ def main(): crawl(target) except Exception as ex: if target and not isinstance(ex, SqlmapUserQuitException): - errMsg = "problem occurred while crawling '%s' ('%s')" % (target, getSafeExString(ex)) - logger.error(errMsg) + Quit_errMsg = "problem occurred while crawling '%s' ('%s')" % (target, getSafeExString(ex)) + logger.error(Quit_errMsg) else: raise else: @@ -224,16 +224,16 @@ def main(): os._exitcode = 1 if "can't start new thread" in getSafeExString(ex): - errMsg = "unable to start new threads. Please check OS (u)limits" - logger.critical(errMsg) + thread_errMsg = "unable to start new threads. Please check OS (u)limits" + logger.critical(thread_errMsg) raise SystemExit else: raise except SqlmapUserQuitException: if not conf.batch: - errMsg = "user quit" - logger.error(errMsg) + user_errMsg = "user quit" + logger.error(user_errMsg) except (SqlmapSilentQuitException, bdb.BdbQuit): pass @@ -242,8 +242,8 @@ def main(): cmdLineOptions.sqlmapShell = False except SqlmapBaseException as ex: - errMsg = getSafeExString(ex) - logger.critical(errMsg) + base_errMsg = getSafeExString(ex) + logger.critical(base_errMsg) os._exitcode = 1 @@ -258,182 +258,184 @@ def main(): except EOFError: print() - errMsg = "exit" - logger.error(errMsg) + exit_errMsg = "exit" + logger.error(exit_errMsg) except SystemExit as ex: os._exitcode = ex.code or 0 - except: - print() - errMsg = unhandledExceptionMessage() + except Exception as e: + print(e) + Exception_errmsg = unhandledExceptionMessage() excMsg = traceback.format_exc() valid = checkIntegrity() os._exitcode = 255 if any(_ in excMsg for _ in ("MemoryError", "Cannot allocate memory")): - errMsg = "memory exhaustion detected" - logger.critical(errMsg) + mem_errMsg = "memory exhaustion detected" + logger.critical(mem_errMsg) raise SystemExit elif any(_ in excMsg for _ in ("No space left", "Disk quota exceeded", "Disk full while accessing")): - errMsg = "no space left on output device" - logger.critical(errMsg) + no_space_errMsg = "no space left on output device" + logger.critical(no_space_errMsg) raise SystemExit elif any(_ in excMsg for _ in ("The paging file is too small",)): - errMsg = "no space left for paging file" - logger.critical(errMsg) + page_small_errMsg = "no space left for paging file" + logger.critical(page_small_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("Access is denied", "subprocess", "metasploit")): - errMsg = "permission error occurred while running Metasploit" - logger.critical(errMsg) + no_root_errMsg = "permission error occurred while running Metasploit" + logger.critical(no_root_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("Permission denied", "metasploit")): - errMsg = "permission error occurred while using Metasploit" - logger.critical(errMsg) + permissions_errMsg = "permission error occurred while using Metasploit" + logger.critical(permissions_errMsg) raise SystemExit elif "Read-only file system" in excMsg: - errMsg = "output device is mounted as read-only" - logger.critical(errMsg) + RO_errMsg = "output device is mounted as read-only" + logger.critical(RO_errMsg) raise SystemExit elif "Insufficient system resources" in excMsg: - errMsg = "resource exhaustion detected" - logger.critical(errMsg) + no_ram_errMsg = "resource exhaustion detected" + logger.critical(no_ram_errMsg) raise SystemExit elif "OperationalError: disk I/O error" in excMsg: - errMsg = "I/O error on output device" - logger.critical(errMsg) + IO_errMsg = "I/O error on output device" + logger.critical(IO_errMsg) raise SystemExit elif "Violation of BIDI" in excMsg: - errMsg = "invalid URL (violation of Bidi IDNA rule - RFC 5893)" - logger.critical(errMsg) + BIDI_errMsg = "invalid URL (violation of Bidi IDNA rule - RFC 5893)" + logger.critical(BIDI_errMsg) raise SystemExit elif "Invalid IPv6 URL" in excMsg: - errMsg = "invalid URL ('%s')" % excMsg.strip().split('\n')[-1] - logger.critical(errMsg) + bad_IPv6_errMsg = "invalid URL ('%s')" % excMsg.strip().split('\n')[-1] + logger.critical(bad_IPv6_errMsg) raise SystemExit elif "_mkstemp_inner" in excMsg: - errMsg = "there has been a problem while accessing temporary files" - logger.critical(errMsg) + tmp_errMsg = "there has been a problem while accessing temporary files" + logger.critical(tmp_errMsg) raise SystemExit elif any(_ in excMsg for _ in ("tempfile.mkdtemp", "tempfile.mkstemp", "tempfile.py")): - errMsg = "unable to write to the temporary directory '%s'. " % tempfile.gettempdir() - errMsg += "Please make sure that your disk is not full and " - errMsg += "that you have sufficient write permissions to " - errMsg += "create temporary files and/or directories" - logger.critical(errMsg) + temp_write_errMsg = '''unable to write to the temporary directory '%s'. " % tempfile.gettempdir() \n + Please make sure that your disk is not full and \n + that you have sufficient write permissions to \n + create temporary files and/or directories''' + logger.critical(temp_write_errMsg) raise SystemExit elif "Permission denied: '" in excMsg: match = re.search(r"Permission denied: '([^']*)", excMsg) - errMsg = "permission error occurred while accessing file '%s'" % match.group(1) - logger.critical(errMsg) + denied_errMsg = "permission error occurred while accessing file '%s'" % match.group(1) + logger.critical(denied_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("twophase", "sqlalchemy")): - errMsg = "please update the 'sqlalchemy' package (>= 1.1.11) " - errMsg += "(Reference: 'https://qiita.com/tkprof/items/7d7b2d00df9c5f16fffe')" - logger.critical(errMsg) + update_errMsg = '''please update the 'sqlalchemy' package (>= 1.1.11) \n + (Reference: 'https://qiita.com/tkprof/items/7d7b2d00df9c5f16fffe')''' + logger.critical(update_errMsg) raise SystemExit 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) " - errMsg += "(Reference: 'https://bugs.python.org/issue18183')" - logger.critical(errMsg) + py_version_errMsg = '''please upgrade the Python version (>= 3.5) \n + (Reference: 'https://bugs.python.org/issue18183')''' + logger.critical(py_version_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("scramble_caching_sha2", "TypeError")): - errMsg = "please downgrade the 'PyMySQL' package (=< 0.8.1) " - errMsg += "(Reference: 'https://github.com/PyMySQL/PyMySQL/issues/700')" - logger.critical(errMsg) + PyMySQL_errMsg = '''please downgrade the 'PyMySQL' package (=< 0.8.1) \n + (Reference: 'https://github.com/PyMySQL/PyMySQL/issues/700')''' + logger.critical(PyMySQL_errMsg) raise SystemExit elif "must be pinned buffer, not bytearray" in excMsg: - errMsg = "error occurred at Python interpreter which " - errMsg += "is fixed in 2.7. Please update accordingly " - errMsg += "(Reference: 'https://bugs.python.org/issue8104')" - logger.critical(errMsg) + buffer_pin_errMsg = '''error occurred at Python interpreter which \n + is fixed in 2.7. Please update accordingly \n + (Reference: 'https://bugs.python.org/issue8104')''' + logger.critical(buffer_pin_errMsg) raise SystemExit 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[^']+)", excMsg) - logger.critical(errMsg) + importlib_errMsg = "unable to read file '%s'" % extractRegexResult(r"OSError: \[Errno 22\] Invalid argument: '(?P[^']+)", excMsg) + logger.critical(importlib_errMsg) raise SystemExit elif "hash_randomization" in excMsg: - errMsg = "error occurred at Python interpreter which " - errMsg += "is fixed in 2.7.3. Please update accordingly " - errMsg += "(Reference: 'https://docs.python.org/2/library/sys.html')" - logger.critical(errMsg) + hash_random_errMsg = '''error occurred at Python interpreter which \n + is fixed in 2.7.3. Please update accordingly \n + (Reference: 'https://docs.python.org/2/library/sys.html')''' + logger.critical(hash_random_errMsg) raise SystemExit 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. " - errMsg += "Please downgrade to some stable Python version" - logger.critical(errMsg) + alpha_errMsg = '''there is a known issue when sqlmap is run with ALPHA versions of Python 3.11. \n + Please downgrade to some stable Python version.''' + logger.critical(alpha_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("Resource temporarily unavailable", "os.fork()", "dictionaryAttack")): - errMsg = "there has been a problem while running the multiprocessing hash cracking. " - errMsg += "Please rerun with option '--threads=1'" - logger.critical(errMsg) + no_dict_attack_errMsg = '''there has been a problem while running the multiprocessing hash cracking. " + Please rerun with option '--threads=1' ''' + logger.critical(no_dict_attack_errMsg) raise SystemExit elif "can't start new thread" in excMsg: - errMsg = "there has been a problem while creating new thread instance. " - errMsg += "Please make sure that you are not running too many processes" + new_thread_errMsg = '''there has been a problem while creating new thread instance. \n + Please make sure that you are not running too many processes''' if not IS_WIN: - errMsg += " (or increase the 'ulimit -u' value)" - logger.critical(errMsg) + new_thread_errMsg += " (or increase the 'ulimit -u' value)" + logger.critical(new_thread_errMsg) raise SystemExit elif "can't allocate read lock" in excMsg: - errMsg = "there has been a problem in regular socket operation " - errMsg += "('%s')" % excMsg.strip().split('\n')[-1] - logger.critical(errMsg) + new_line = '\n' + socket_errMsg = f'''there has been a problem in regular socket operation " + {'%s' % excMsg.strip().split(new_line)[-1]}''' + logger.critical(socket_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("pymysql", "configparser")): - errMsg = "wrong initialization of 'pymsql' detected (using Python3 dependencies)" - logger.critical(errMsg) + pymsql_errMsg = "wrong initialization of 'pymsql' detected (using Python3 dependencies)" + logger.critical(pymsql_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("ntlm", "socket.error, err", "SyntaxError")): - errMsg = "wrong initialization of 'python-ntlm' detected (using Python2 syntax)" - logger.critical(errMsg) + python_ntlm_errMsg = "wrong initialization of 'python-ntlm' detected (using Python2 syntax)" + logger.critical(python_ntlm_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("drda", "to_bytes")): - errMsg = "wrong initialization of 'drda' detected (using Python3 syntax)" - logger.critical(errMsg) + drda_errMsg = "wrong initialization of 'drda' detected (using Python3 syntax)" + logger.critical(drda_errMsg) raise SystemExit elif "'WebSocket' object has no attribute 'status'" in excMsg: - errMsg = "wrong websocket library detected" - errMsg += " (Reference: 'https://github.com/sqlmapproject/sqlmap/issues/4572#issuecomment-775041086')" - logger.critical(errMsg) + websocket_errMsg = '''wrong websocket library detected" + (Reference: 'https://github.com/sqlmapproject/sqlmap/issues/4572#issuecomment-775041086')''' + logger.critical(websocket_errMsg) raise SystemExit elif all(_ in excMsg for _ in ("window = tkinter.Tk()",)): - errMsg = "there has been a problem in initialization of GUI interface " - errMsg += "('%s')" % excMsg.strip().split('\n')[-1] - logger.critical(errMsg) + new_line = '\n' + GUI_errMsg = f'''there has been a problem in initialization of GUI interface \n + {'%s' % excMsg.strip().split(new_line)[-1]}''' + logger.critical(GUI_errMsg) raise SystemExit elif any(_ in excMsg for _ in ("unable to access item 'liveTest'",)): - errMsg = "detected usage of files from different versions of sqlmap" - logger.critical(errMsg) + livetest_errMsg = "detected usage of files from different versions of sqlmap" + logger.critical(livetest_errMsg) raise SystemExit elif kb.get("dumpKeyboardInterrupt"): @@ -443,10 +445,10 @@ def main(): raise SystemExit elif valid is False: - errMsg = "code integrity check failed (turning off automatic issue creation). " - errMsg += "You should retrieve the latest development version from official GitHub " - errMsg += "repository at '%s'" % GIT_PAGE - logger.critical(errMsg) + integrity_errMsg = f'''code integrity check failed (turning off automatic issue creation). \n + You should retrieve the latest development version from official GitHub \n + repository at {'%s' % GIT_PAGE}''' + logger.critical(integrity_errMsg) print() dataToStdout(excMsg) raise SystemExit @@ -458,62 +460,65 @@ def main(): raise SystemExit elif any(_ in excMsg for _ in ("ImportError", "ModuleNotFoundError", " 1: - os._exit(getattr(os, "_exitcode", 0)) + sys.exit(getattr(os, "_exitcode", 0)) else: sys.exit(getattr(os, "_exitcode", 0)) else: