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
|
|
|
|
|
|
|
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
|
|
|
|
|
2010-03-03 18:26:27 +03:00
|
|
|
Copyright (c) 2007-2010 Bernardo Damele A. G. <bernardo.damele@gmail.com>
|
2009-04-22 15:48:07 +04:00
|
|
|
Copyright (c) 2006 Daniele Bellucci <daniele.bellucci@gmail.com>
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
sqlmap is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation version 2 of the License.
|
|
|
|
|
|
|
|
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
"""
|
|
|
|
|
2010-05-28 17:32:36 +04:00
|
|
|
import codecs
|
2008-10-15 19:38:22 +04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import traceback
|
2010-03-28 00:50:19 +03:00
|
|
|
import warnings
|
|
|
|
|
|
|
|
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-05-29 03:12:20 +04:00
|
|
|
# NOTE: This breaks SQL shell and OS shell history and TAB functionalities
|
2010-07-30 16:49:25 +04:00
|
|
|
#import locale
|
2010-05-29 03:12:20 +04:00
|
|
|
#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
|
2010-05-28 17:32:36 +04:00
|
|
|
|
2008-12-03 20:32:16 +03: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-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 conf
|
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.data import paths
|
|
|
|
from lib.core.exception import exceptionsTuple
|
|
|
|
from lib.core.exception import unhandledException
|
|
|
|
from lib.core.option import init
|
2010-09-15 16:59:51 +04:00
|
|
|
from lib.core.profiling import profile
|
2010-09-26 18:02:13 +04:00
|
|
|
from lib.core.testing import smokeTest
|
|
|
|
from lib.core.testing import liveTest
|
2010-05-28 20:43:04 +04:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
paths.SQLMAP_ROOT_PATH = modulePath()
|
|
|
|
setPaths()
|
|
|
|
|
|
|
|
banner()
|
|
|
|
cmdLineOptions = cmdLineParser()
|
|
|
|
|
|
|
|
print "[*] starting at: %s\n" % time.strftime("%X")
|
|
|
|
|
|
|
|
try:
|
|
|
|
init(cmdLineOptions)
|
2010-05-21 13:45:47 +04:00
|
|
|
if conf.profile:
|
2010-09-26 18:02:13 +04:00
|
|
|
profile()
|
|
|
|
elif conf.smokeTest:
|
|
|
|
smokeTest()
|
|
|
|
elif conf.liveTest:
|
|
|
|
liveTest()
|
2010-05-21 13:45:47 +04:00
|
|
|
else:
|
|
|
|
start()
|
2008-10-15 19:38:22 +04:00
|
|
|
except exceptionsTuple, e:
|
2010-06-02 16:45:40 +04:00
|
|
|
e = getUnicode(e)
|
2008-10-15 19:38:22 +04:00
|
|
|
logger.error(e)
|
2010-05-28 20:43:04 +04:00
|
|
|
closeDumper(False, e)
|
2008-11-02 21:23:42 +03:00
|
|
|
|
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)
|
2008-11-02 21:23:42 +03:00
|
|
|
|
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-11-02 21:23:42 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
except:
|
2010-03-16 15:14:02 +03:00
|
|
|
print
|
2008-10-15 19:38:22 +04:00
|
|
|
errMsg = unhandledException()
|
2010-09-26 18:02:13 +04:00
|
|
|
logger.critical(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
traceback.print_exc()
|
2010-05-28 20:43:04 +04:00
|
|
|
closeDumper(False, errMsg)
|
|
|
|
|
|
|
|
else:
|
|
|
|
closeDumper(True)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
print "\n[*] shutting down at: %s\n" % time.strftime("%X")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|