From 849babaf8d58f60d2c6d0f9c1db9e0c3071d2a2b Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 28 Dec 2015 11:39:46 +0100 Subject: [PATCH] Minor patch for too fast Ctrl-C(-ers) --- sqlmap.py | 70 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/sqlmap.py b/sqlmap.py index fdbc7afa1..af95008e9 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -111,7 +111,10 @@ def main(): except SqlmapUserQuitException: errMsg = "user quit" - logger.error(errMsg) + try: + logger.error(errMsg) + except KeyboardInterrupt: + pass except (SqlmapSilentQuitException, bdb.BdbQuit): pass @@ -121,18 +124,30 @@ def main(): except SqlmapBaseException as ex: errMsg = getSafeExString(ex) - logger.critical(errMsg) + try: + logger.critical(errMsg) + except KeyboardInterrupt: + pass + raise SystemExit except KeyboardInterrupt: print + errMsg = "user aborted" - logger.error(errMsg) + try: + logger.error(errMsg) + except KeyboardInterrupt: + pass except EOFError: print errMsg = "exit" - logger.error(errMsg) + + try: + logger.error(errMsg) + except KeyboardInterrupt: + pass except SystemExit: pass @@ -142,32 +157,35 @@ def main(): errMsg = unhandledExceptionMessage() excMsg = traceback.format_exc() - if any(_ in excMsg for _ in ("No space left", "Disk quota exceeded")): - errMsg = "no space left on output device" - logger.error(errMsg) - raise SystemExit + try: + if any(_ in excMsg for _ in ("No space left", "Disk quota exceeded")): + errMsg = "no space left on output device" + logger.error(errMsg) + raise SystemExit - elif "bad marshal data (unknown type code)" in 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 "") - errMsg += ". Please delete .pyc files on your system to fix the problem" - logger.error(errMsg) - raise SystemExit + elif "bad marshal data (unknown type code)" in 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 "") + errMsg += ". Please delete .pyc files on your system to fix the problem" + logger.error(errMsg) + raise SystemExit - for match in re.finditer(r'File "(.+?)", line', excMsg): - file_ = match.group(1) - file_ = os.path.relpath(file_, os.path.dirname(__file__)) - file_ = file_.replace("\\", '/') - file_ = re.sub(r"\.\./", '/', file_).lstrip('/') - excMsg = excMsg.replace(match.group(1), file_) + for match in re.finditer(r'File "(.+?)", line', excMsg): + file_ = match.group(1) + file_ = os.path.relpath(file_, os.path.dirname(__file__)) + file_ = file_.replace("\\", '/') + file_ = re.sub(r"\.\./", '/', file_).lstrip('/') + excMsg = excMsg.replace(match.group(1), file_) - errMsg = maskSensitiveData(errMsg) - excMsg = maskSensitiveData(excMsg) + errMsg = maskSensitiveData(errMsg) + excMsg = maskSensitiveData(excMsg) - logger.critical(errMsg) - kb.stickyLevel = logging.CRITICAL - dataToStdout(excMsg) - createGithubIssue(errMsg, excMsg) + logger.critical(errMsg) + kb.stickyLevel = logging.CRITICAL + dataToStdout(excMsg) + createGithubIssue(errMsg, excMsg) + except KeyboardInterrupt: + pass finally: if conf.get("showTime"):