()
Main function of sqlmap when running from command line.
Main function of sqlmap when running from command line.
Main function of sqlmap when running from command line .
def main():
    """
    Main function of sqlmap when running from command line.
    """

    try:
        paths.SQLMAP_ROOT_PATH = modulePath()

        try:
            os.path.isdir(paths.SQLMAP_ROOT_PATH)
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the sqlmap's directory to the other location"
            logger.error(errMsg)
            raise SystemExit

        setPaths()

        # Store original command line options for possible later restoration
        cmdLineOptions.update(cmdLineParser().__dict__)
        initOptions(cmdLineOptions)

        if hasattr(conf, "api"):
            # Overwrite system standard output and standard error to write
            # to an IPC database
            sys.stdout = StdDbOut(conf.taskid, messagetype="stdout")
            sys.stderr = StdDbOut(conf.taskid, messagetype="stderr")
            setRestAPILog()

        #banner()

        conf.showTime = True
        dataToStdout("[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True)
        dataToStdout("[*] starting at %s\n\n" % time.strftime("%X"), forceOutput=True)

        init()

        if conf.profile:
            profile()
        elif conf.smokeTest:
            smokeTest()
        elif conf.liveTest:
            liveTest()
        else:
            start()

    except SqlmapUserQuitException:
        errMsg = "user quit"
        logger.error(errMsg)

    except (SqlmapSilentQuitException, bdb.BdbQuit):
        pass

    except SqlmapShellQuitException:
        cmdLineOptions.sqlmapShell = False

    except SqlmapBaseException as ex:
        errMsg = getSafeExString(ex)
        logger.critical(errMsg)
        raise SystemExit

    except KeyboardInterrupt:
        print
        errMsg = "user aborted"
        logger.error(errMsg)

    except EOFError:
        print
        errMsg = "exit"
        logger.error(errMsg)

    except SystemExit:
        pass

    except:
        print
        errMsg = unhandledExceptionMessage()
        excMsg = traceback.format_exc()

        if "No space left" in excMsg:
            errMsg = "no space left on output device"
            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_)

        errMsg = maskSensitiveData(errMsg)
        excMsg = maskSensitiveData(excMsg)

        logger.critical(errMsg)
        kb.stickyLevel = logging.CRITICAL
        dataToStdout(excMsg)
        createGithubIssue(errMsg, excMsg)

    finally:
        if conf.get("showTime"):
            dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True)

        if kb.get("tempDir"):
            shutil.rmtree(kb.tempDir, ignore_errors=True)

        kb.threadContinue = False
        kb.threadException = True

        if conf.get("hashDB"):
            try:
                conf.hashDB.flush(True)
            except KeyboardInterrupt:
                pass

        if cmdLineOptions.get("sqlmapShell"):
            cmdLineOptions.clear()
            conf.clear()
            kb.clear()
            main()

        if hasattr(conf, "api"):
            try:
                conf.database_cursor.disconnect()
            except KeyboardInterrupt:
                pass

        if conf.get("dumper"):
            conf.dumper.flush()

        # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
        if conf.get("threads", 0) > 1 or conf.get("dnsServer"):
            os._exit(0)
def main ( ) : try : paths . SQLMAP_ROOT_PATH = modulePath ( ) try : os . path . isdir ( paths . SQLMAP_ROOT_PATH ) except UnicodeEncodeError : errMsg = "your system does not properly handle non-ASCII paths. " errMsg += "Please move the sqlmap's directory to the other location" logger . error ( errMsg ) raise SystemExit setPaths ( ) # Store original command line options for possible later restoration cmdLineOptions . update ( cmdLineParser ( ) . __dict__ ) initOptions ( cmdLineOptions ) if hasattr ( conf , "api" ) : # Overwrite system standard output and standard error to write # to an IPC database sys . stdout = StdDbOut ( conf . taskid , messagetype = "stdout" ) sys . stderr = StdDbOut ( conf . taskid , messagetype = "stderr" ) setRestAPILog ( ) #banner() conf . showTime = True dataToStdout ( "[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER , forceOutput = True ) dataToStdout ( "[*] starting at %s\n\n" % time . strftime ( "%X" ) , forceOutput = True ) init ( ) if conf . profile : profile ( ) elif conf . smokeTest : smokeTest ( ) elif conf . liveTest : liveTest ( ) else : start ( ) except SqlmapUserQuitException : errMsg = "user quit" logger . error ( errMsg ) except ( SqlmapSilentQuitException , bdb . BdbQuit ) : pass except SqlmapShellQuitException : cmdLineOptions . sqlmapShell = False except SqlmapBaseException as ex : errMsg = getSafeExString ( ex ) logger . critical ( errMsg ) raise SystemExit except KeyboardInterrupt : print errMsg = "user aborted" logger . error ( errMsg ) except EOFError : print errMsg = "exit" logger . error ( errMsg ) except SystemExit : pass except : print errMsg = unhandledExceptionMessage ( ) excMsg = traceback . format_exc ( ) if "No space left" in excMsg : errMsg = "no space left on output device" 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_ ) errMsg = maskSensitiveData ( errMsg ) excMsg = maskSensitiveData ( excMsg ) logger . critical ( errMsg ) kb . stickyLevel = logging . CRITICAL dataToStdout ( excMsg ) createGithubIssue ( errMsg , excMsg ) finally : if conf . get ( "showTime" ) : dataToStdout ( "\n[*] shutting down at %s\n\n" % time . strftime ( "%X" ) , forceOutput = True ) if kb . get ( "tempDir" ) : shutil . rmtree ( kb . tempDir , ignore_errors = True ) kb . threadContinue = False kb . threadException = True if conf . get ( "hashDB" ) : try : conf . hashDB . flush ( True ) except KeyboardInterrupt : pass if cmdLineOptions . get ( "sqlmapShell" ) : cmdLineOptions . clear ( ) conf . clear ( ) kb . clear ( ) main ( ) if hasattr ( conf , "api" ) : try : conf . database_cursor . disconnect ( ) except KeyboardInterrupt : pass if conf . get ( "dumper" ) : conf . dumper . flush ( ) # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program if conf . get ( "threads" , 0 ) > 1 or conf . get ( "dnsServer" ) : os . _exit ( 0 )