|
7 | 7 | See the file 'doc/COPYING' for copying permission |
8 | 8 | """ |
9 | 9 |
|
10 | | -import codecs |
11 | | -import os |
12 | 10 | import sys |
13 | | -import time |
14 | | -import traceback |
15 | | -import warnings |
16 | 11 |
|
17 | | -warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning) |
18 | | -warnings.filterwarnings(action="ignore", category=DeprecationWarning) |
| 12 | +PYVERSION = sys.version.split()[0] |
19 | 13 |
|
20 | | -try: |
21 | | - import psyco |
22 | | - psyco.full() |
23 | | - psyco.profile() |
24 | | -except ImportError: |
25 | | - pass |
26 | | - |
27 | | -from lib.controller.controller import start |
28 | | -from lib.core.common import banner |
29 | | -from lib.core.common import dataToStdout |
30 | | -from lib.core.common import getUnicode |
31 | | -from lib.core.common import setPaths |
32 | | -from lib.core.common import weAreFrozen |
33 | | -from lib.core.data import cmdLineOptions |
34 | | -from lib.core.data import conf |
35 | | -from lib.core.data import kb |
36 | | -from lib.core.data import logger |
37 | | -from lib.core.data import paths |
38 | | -from lib.core.common import unhandledExceptionMessage |
39 | | -from lib.core.exception import exceptionsTuple |
40 | | -from lib.core.exception import sqlmapSilentQuitException |
41 | | -from lib.core.exception import sqlmapUserQuitException |
42 | | -from lib.core.option import init |
43 | | -from lib.core.profiling import profile |
44 | | -from lib.core.settings import LEGAL_DISCLAIMER |
45 | | -from lib.core.testing import smokeTest |
46 | | -from lib.core.testing import liveTest |
47 | | -from lib.core.xmldump import closeDumper |
48 | | -from lib.parse.cmdline import cmdLineParser |
49 | | - |
50 | | -def modulePath(): |
51 | | - """ |
52 | | - This will get us the program's directory, even if we are frozen |
53 | | - using py2exe |
54 | | - """ |
55 | | - |
56 | | - if weAreFrozen(): |
57 | | - return os.path.dirname(getUnicode(sys.executable, sys.getfilesystemencoding())) |
58 | | - else: |
59 | | - return os.path.dirname(os.path.realpath(__file__)) |
60 | | - |
61 | | -def main(): |
62 | | - """ |
63 | | - Main function of sqlmap when running from command line. |
64 | | - """ |
65 | | - |
66 | | - try: |
67 | | - paths.SQLMAP_ROOT_PATH = modulePath() |
68 | | - setPaths() |
69 | | - banner() |
70 | | - |
71 | | - dataToStdout("[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True) |
72 | | - dataToStdout("[*] starting at %s\n\n" % time.strftime("%X"), forceOutput=True) |
73 | | - |
74 | | - # Store original command line options for possible later restoration |
75 | | - cmdLineOptions.update(cmdLineParser().__dict__) |
76 | | - |
77 | | - init(cmdLineOptions) |
78 | | - |
79 | | - if conf.profile: |
80 | | - profile() |
81 | | - elif conf.smokeTest: |
82 | | - smokeTest() |
83 | | - elif conf.liveTest: |
84 | | - liveTest() |
85 | | - else: |
86 | | - start() |
87 | | - |
88 | | - except sqlmapUserQuitException: |
89 | | - errMsg = "user quit" |
90 | | - logger.error(errMsg) |
91 | | - closeDumper(False, errMsg) |
92 | | - |
93 | | - except sqlmapSilentQuitException: |
94 | | - closeDumper(False) |
95 | | - |
96 | | - except exceptionsTuple, e: |
97 | | - e = getUnicode(e) |
98 | | - logger.critical(e) |
99 | | - closeDumper(False, e) |
100 | | - |
101 | | - except KeyboardInterrupt, _: |
102 | | - print |
103 | | - errMsg = "user aborted" |
104 | | - logger.error(errMsg) |
105 | | - closeDumper(False, errMsg) |
106 | | - |
107 | | - except EOFError, _: |
108 | | - print |
109 | | - errMsg = "exit" |
110 | | - logger.error(errMsg) |
111 | | - closeDumper(False, errMsg) |
112 | | - |
113 | | - except SystemExit: |
114 | | - pass |
115 | | - |
116 | | - except: |
117 | | - print |
118 | | - errMsg = unhandledExceptionMessage() |
119 | | - logger.critical(errMsg) |
120 | | - traceback.print_exc() |
121 | | - closeDumper(False, errMsg) |
122 | | - |
123 | | - else: |
124 | | - closeDumper(True) |
125 | | - |
126 | | - finally: |
127 | | - dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True) |
128 | | - |
129 | | - kb.threadContinue = False |
130 | | - kb.threadException = True |
131 | | - |
132 | | - # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program |
133 | | - if hasattr(conf, "threads") and conf.threads > 1: |
134 | | - os._exit(0) |
135 | | - |
136 | | -if __name__ == "__main__": |
| 14 | +if PYVERSION >= "3" or PYVERSION < "2.6": |
| 15 | + exit("[CRITICAL] wrong Python version detected ('%s'). For successfully running sqlmap you have to use 2.6 <= Python < 3.0" % PYVERSION) |
| 16 | +else: |
| 17 | + from _sqlmap import main |
137 | 18 | main() |
0 commit comments