2011-09-13 02:48:57 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2012-07-12 21:38:03 +04:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2011-09-13 02:48:57 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
2012-10-30 04:23:01 +04:00
|
|
|
import bdb
|
2012-12-12 14:54:59 +04:00
|
|
|
import logging
|
2011-09-13 02:48:57 +04:00
|
|
|
import os
|
2012-12-12 17:03:03 +04:00
|
|
|
import StringIO
|
2011-09-13 02:48:57 +04:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import traceback
|
2012-12-12 17:22:24 +04:00
|
|
|
import types
|
2011-09-13 02:48:57 +04:00
|
|
|
import warnings
|
|
|
|
|
|
|
|
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
|
|
|
|
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
|
|
|
|
|
|
|
|
from lib.controller.controller import start
|
|
|
|
from lib.core.common import banner
|
|
|
|
from lib.core.common import dataToStdout
|
|
|
|
from lib.core.common import getUnicode
|
|
|
|
from lib.core.common import setPaths
|
|
|
|
from lib.core.common import weAreFrozen
|
2012-12-12 17:03:03 +04:00
|
|
|
from lib.core.convert import stdoutencode
|
2011-09-13 02:48:57 +04:00
|
|
|
from lib.core.data import cmdLineOptions
|
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.data import paths
|
|
|
|
from lib.core.common import unhandledExceptionMessage
|
|
|
|
from lib.core.exception import exceptionsTuple
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapSilentQuitException
|
|
|
|
from lib.core.exception import SqlmapUserQuitException
|
2012-12-12 17:03:03 +04:00
|
|
|
from lib.core.log import FORMATTER
|
2012-12-12 17:22:24 +04:00
|
|
|
from lib.core.log import LOGGER_HANDLER
|
2011-09-13 02:48:57 +04:00
|
|
|
from lib.core.option import init
|
|
|
|
from lib.core.profiling import profile
|
|
|
|
from lib.core.settings import LEGAL_DISCLAIMER
|
2012-12-12 14:54:59 +04:00
|
|
|
from lib.core.settings import XMLRPC_SERVER_PORT
|
2011-09-13 02:48:57 +04:00
|
|
|
from lib.core.testing import smokeTest
|
|
|
|
from lib.core.testing import liveTest
|
|
|
|
from lib.parse.cmdline import cmdLineParser
|
2012-12-11 19:02:06 +04:00
|
|
|
from lib.utils.xmlrpc import XMLRPCServer
|
2011-09-13 02:48:57 +04:00
|
|
|
|
|
|
|
def modulePath():
|
|
|
|
"""
|
|
|
|
This will get us the program's directory, even if we are frozen
|
|
|
|
using py2exe
|
|
|
|
"""
|
|
|
|
|
2011-12-14 18:57:35 +04:00
|
|
|
return os.path.dirname(getUnicode(sys.executable if weAreFrozen() else __file__, sys.getfilesystemencoding()))
|
2011-09-13 02:48:57 +04:00
|
|
|
|
2012-12-12 17:03:03 +04:00
|
|
|
def xmlRpcServe():
|
|
|
|
logger.setLevel(logging.INFO)
|
2012-12-12 19:53:29 +04:00
|
|
|
cmdLineOptions.batch = True
|
2012-12-12 17:22:24 +04:00
|
|
|
cmdLineOptions.disableColoring = True
|
2012-12-12 17:03:03 +04:00
|
|
|
server = XMLRPCServer(cmdLineOptions.xmlRpcPort or XMLRPC_SERVER_PORT)
|
2012-12-12 17:22:24 +04:00
|
|
|
def emit(self, record):
|
|
|
|
message = stdoutencode(FORMATTER.format(record))
|
2012-12-12 19:31:20 +04:00
|
|
|
sys.stdout.write("%s" % message)
|
2012-12-12 17:22:24 +04:00
|
|
|
LOGGER_HANDLER.emit = types.MethodType(emit, LOGGER_HANDLER, type(LOGGER_HANDLER))
|
2012-12-12 17:03:03 +04:00
|
|
|
sys.stdout = StringIO.StringIO()
|
|
|
|
sys.stderr = StringIO.StringIO()
|
|
|
|
server.serve()
|
|
|
|
|
2011-09-13 02:48:57 +04:00
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
Main function of sqlmap when running from command line.
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
paths.SQLMAP_ROOT_PATH = modulePath()
|
|
|
|
setPaths()
|
|
|
|
banner()
|
|
|
|
|
|
|
|
dataToStdout("[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True)
|
|
|
|
dataToStdout("[*] starting at %s\n\n" % time.strftime("%X"), forceOutput=True)
|
|
|
|
|
|
|
|
# Store original command line options for possible later restoration
|
|
|
|
cmdLineOptions.update(cmdLineParser().__dict__)
|
|
|
|
|
2012-12-11 19:02:06 +04:00
|
|
|
if cmdLineOptions.xmlRpc:
|
2012-12-12 17:03:03 +04:00
|
|
|
xmlRpcServe()
|
2011-09-13 02:48:57 +04:00
|
|
|
else:
|
2012-12-11 19:02:06 +04:00
|
|
|
init(cmdLineOptions)
|
|
|
|
|
|
|
|
if conf.profile:
|
|
|
|
profile()
|
|
|
|
elif conf.smokeTest:
|
|
|
|
smokeTest()
|
|
|
|
elif conf.liveTest:
|
|
|
|
liveTest()
|
|
|
|
else:
|
|
|
|
start()
|
2011-09-13 02:48:57 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
except SqlmapUserQuitException:
|
2011-09-13 02:48:57 +04:00
|
|
|
errMsg = "user quit"
|
|
|
|
logger.error(errMsg)
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
except (SqlmapSilentQuitException, bdb.BdbQuit):
|
2011-12-28 19:59:30 +04:00
|
|
|
pass
|
2011-09-13 02:48:57 +04:00
|
|
|
|
|
|
|
except exceptionsTuple, e:
|
|
|
|
e = getUnicode(e)
|
|
|
|
logger.critical(e)
|
|
|
|
|
2011-12-22 03:23:00 +04:00
|
|
|
except KeyboardInterrupt:
|
2011-09-13 02:48:57 +04:00
|
|
|
print
|
|
|
|
errMsg = "user aborted"
|
|
|
|
logger.error(errMsg)
|
|
|
|
|
2011-12-22 03:23:00 +04:00
|
|
|
except EOFError:
|
2011-09-13 02:48:57 +04:00
|
|
|
print
|
|
|
|
errMsg = "exit"
|
|
|
|
logger.error(errMsg)
|
|
|
|
|
|
|
|
except SystemExit:
|
|
|
|
pass
|
|
|
|
|
|
|
|
except:
|
|
|
|
print
|
|
|
|
errMsg = unhandledExceptionMessage()
|
|
|
|
logger.critical(errMsg)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
finally:
|
2012-07-14 13:04:46 +04:00
|
|
|
dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True)
|
2011-09-13 02:48:57 +04:00
|
|
|
|
|
|
|
kb.threadContinue = False
|
|
|
|
kb.threadException = True
|
|
|
|
|
2012-08-21 12:28:25 +04:00
|
|
|
if conf.get("hashDB"):
|
2011-12-22 03:23:00 +04:00
|
|
|
try:
|
|
|
|
conf.hashDB.flush(True)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2011-11-22 14:54:29 +04:00
|
|
|
|
2011-09-13 02:48:57 +04:00
|
|
|
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
|
2012-08-21 12:28:25 +04:00
|
|
|
if conf.get("threads", 0) > 1 or conf.get("dnsServer"):
|
2011-09-13 02:48:57 +04:00
|
|
|
os._exit(0)
|