forked from sqlmapproject/sqlmap
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlmap.py
More file actions
Latest commit
executable file
·188 lines (152 loc) · 5.33 KB
/
Copy pathsqlmap.py
File metadata and controls
executable file
·188 lines (152 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
"""
Copyright (c) 2006-2015 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
importbdb
importinspect
importlogging
importos
importre
importshutil
importsys
importtempfile
importtime
importtraceback
importwarnings
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
fromlib.utilsimportversioncheck# this has to be the first non-standard import
fromlib.controller.controllerimportstart
fromlib.core.commonimportbanner
fromlib.core.commonimportcreateGithubIssue
fromlib.core.commonimportdataToStdout
fromlib.core.commonimportgetUnicode
fromlib.core.commonimportmaskSensitiveData
fromlib.core.commonimportsetColor
fromlib.core.commonimportsetPaths
fromlib.core.commonimportweAreFrozen
fromlib.core.dataimportcmdLineOptions
fromlib.core.dataimportconf
fromlib.core.dataimportkb
fromlib.core.dataimportlogger
fromlib.core.dataimportpaths
fromlib.core.commonimportunhandledExceptionMessage
fromlib.core.exceptionimportSqlmapBaseException
fromlib.core.exceptionimportSqlmapShellQuitException
fromlib.core.exceptionimportSqlmapSilentQuitException
fromlib.core.exceptionimportSqlmapUserQuitException
fromlib.core.optionimportinitOptions
fromlib.core.optionimportinit
fromlib.core.profilingimportprofile
fromlib.core.settingsimportLEGAL_DISCLAIMER
fromlib.core.testingimportsmokeTest
fromlib.core.testingimportliveTest
fromlib.parse.cmdlineimportcmdLineParser
fromlib.utils.apiimportsetRestAPILog
fromlib.utils.apiimportStdDbOut
defmodulePath():
"""
This will get us the program's directory, even if we are frozen
using py2exe
"""
try:
_=sys.executableifweAreFrozen() else__file__
exceptNameError:
_=inspect.getsourcefile(modulePath)
returngetUnicode(os.path.dirname(os.path.realpath(_)), sys.getfilesystemencoding())
defmain():
"""
Main function of sqlmap when running from command line.
"""
try:
paths.SQLMAP_ROOT_PATH=modulePath()
setPaths()
# Store original command line options for possible later restoration
cmdLineOptions.update(cmdLineParser().__dict__)
initOptions(cmdLineOptions)
ifhasattr(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()
ifconf.profile:
profile()
elifconf.smokeTest:
smokeTest()
elifconf.liveTest:
liveTest()
else:
start()
exceptSqlmapUserQuitException:
errMsg="user quit"
logger.error(errMsg)
except (SqlmapSilentQuitException, bdb.BdbQuit):
pass
exceptSqlmapShellQuitException:
cmdLineOptions.sqlmapShell=False
exceptSqlmapBaseExceptionasex:
errMsg=getUnicode(ex.message)
logger.critical(errMsg)
sys.exit(1)
exceptKeyboardInterrupt:
print
errMsg="user aborted"
logger.error(errMsg)
exceptEOFError:
print
errMsg="exit"
logger.error(errMsg)
exceptSystemExit:
pass
except:
print
errMsg=unhandledExceptionMessage()
excMsg=traceback.format_exc()
formatchinre.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:
ifconf.get("showTime"):
dataToStdout("\n[*] shutting down at %s\n\n"%time.strftime("%X"), forceOutput=True)
ifkb.get("tempDir"):
shutil.rmtree(kb.tempDir, ignore_errors=True)
kb.threadContinue=False
kb.threadException=True
ifconf.get("hashDB"):
try:
conf.hashDB.flush(True)
exceptKeyboardInterrupt:
pass
ifcmdLineOptions.get("sqlmapShell"):
cmdLineOptions.clear()
conf.clear()
kb.clear()
main()
ifhasattr(conf, "api"):
try:
conf.database_cursor.disconnect()
exceptKeyboardInterrupt:
pass
ifconf.get("dumper"):
conf.dumper.flush()
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
ifconf.get("threads", 0) >1orconf.get("dnsServer"):
os._exit(0)
if__name__=="__main__":
main()