sqlmap/sqlmap.py

134 lines
3.4 KiB
Python
Raw Normal View History

2008-10-15 19:38:22 +04:00
#!/usr/bin/env python
"""
2008-10-15 19:56:32 +04:00
$Id$
2008-10-15 19:38:22 +04:00
Copyright (c) 2006-2011 sqlmap developers (http://sqlmap.sourceforge.net/)
2010-10-15 03:18:29 +04:00
See the file 'doc/COPYING' for copying permission
2008-10-15 19:38:22 +04:00
"""
import codecs
2008-10-15 19:38:22 +04:00
import os
import sys
import time
import traceback
import warnings
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
2011-04-14 18:01:47 +04:00
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
2008-10-15 19:38:22 +04:00
try:
import psyco
psyco.full()
psyco.profile()
except ImportError:
pass
2008-10-15 19:38:22 +04:00
from lib.controller.controller import start
from lib.core.common import banner
2010-10-21 02:09:03 +04:00
from lib.core.common import dataToStdout
2010-06-02 16:45:40 +04:00
from lib.core.common import getUnicode
2008-10-15 19:38:22 +04:00
from lib.core.common import setPaths
from lib.core.common import weAreFrozen
from lib.core.data import cmdLineOptions
2008-10-15 19:38:22 +04:00
from lib.core.data import conf
2010-12-29 23:26:36 +03:00
from lib.core.data import kb
2008-10-15 19:38:22 +04:00
from lib.core.data import logger
from lib.core.data import paths
from lib.core.common import unhandledExceptionMessage
2008-10-15 19:38:22 +04:00
from lib.core.exception import exceptionsTuple
from lib.core.exception import sqlmapSilentQuitException
2010-09-30 23:45:23 +04:00
from lib.core.exception import sqlmapUserQuitException
2008-10-15 19:38:22 +04:00
from lib.core.option import init
2010-09-15 16:59:51 +04:00
from lib.core.profiling import profile
from lib.core.settings import LEGAL_DISCLAIMER
2010-09-26 18:02:13 +04:00
from lib.core.testing import smokeTest
from lib.core.testing import liveTest
from lib.core.xmldump import closeDumper
2008-10-15 19:38:22 +04:00
from lib.parse.cmdline import cmdLineParser
def modulePath():
"""
This will get us the program's directory, even if we are frozen
using py2exe
"""
if weAreFrozen():
2010-06-02 16:45:40 +04:00
return os.path.dirname(getUnicode(sys.executable, sys.getfilesystemencoding()))
2008-10-15 19:38:22 +04:00
else:
return os.path.dirname(os.path.realpath(__file__))
def main():
"""
Main function of sqlmap when running from command line.
"""
2011-05-28 10:44:17 +04:00
2008-10-15 19:38:22 +04:00
paths.SQLMAP_ROOT_PATH = modulePath()
setPaths()
banner()
# Store original command line options for possible later restoration
cmdLineOptions.update(cmdLineParser().__dict__)
2008-10-15 19:38:22 +04:00
dataToStdout("[!] Legal Disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True)
2010-10-21 02:09:03 +04:00
dataToStdout("[*] starting at: %s\n\n" % time.strftime("%X"), forceOutput=True)
2008-10-15 19:38:22 +04:00
try:
init(cmdLineOptions)
2010-05-21 13:45:47 +04:00
if conf.profile:
2010-09-27 17:41:18 +04:00
profile()
2010-09-26 18:02:13 +04:00
elif conf.smokeTest:
smokeTest()
elif conf.liveTest:
liveTest()
2010-05-21 13:45:47 +04:00
else:
start()
2010-09-30 23:45:23 +04:00
except sqlmapUserQuitException:
errMsg = "user quit"
logger.error(errMsg)
closeDumper(False, errMsg)
except sqlmapSilentQuitException:
closeDumper(False)
2008-10-15 19:38:22 +04:00
except exceptionsTuple, e:
2010-06-02 16:45:40 +04:00
e = getUnicode(e)
2010-09-27 17:41:18 +04:00
logger.critical(e)
closeDumper(False, e)
2010-06-10 19:34:28 +04:00
except KeyboardInterrupt, _:
2008-10-15 19:38:22 +04:00
print
errMsg = "user aborted"
logger.error(errMsg)
2010-06-10 19:34:28 +04:00
closeDumper(False, errMsg)
2010-06-10 19:34:28 +04:00
except EOFError, _:
2008-10-15 19:38:22 +04:00
print
errMsg = "exit"
logger.error(errMsg)
2010-06-10 19:34:28 +04:00
closeDumper(False, errMsg)
2008-10-15 19:38:22 +04:00
except:
print
errMsg = unhandledExceptionMessage()
2010-09-26 18:02:13 +04:00
logger.critical(errMsg)
2008-10-15 19:38:22 +04:00
traceback.print_exc()
closeDumper(False, errMsg)
else:
closeDumper(True)
2008-10-15 19:38:22 +04:00
2010-12-29 23:26:36 +03:00
finally:
dataToStdout("\n[*] shutting down at: %s\n\n" % time.strftime("%X"), forceOutput=True)
2010-12-29 23:26:36 +03:00
kb.threadContinue = False
kb.threadException = True
# just in case handling of leftover threads
raise SystemExit
2008-10-15 19:38:22 +04:00
if __name__ == "__main__":
main()