Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95b9223

Browse files
committed
Merge branch 'master' of github.com:sqlmapproject/sqlmap
2 parents a59ac8e + e8bd3c9 commit 95b9223

10 files changed

Lines changed: 176 additions & 114 deletions

File tree

_sqlmap.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
from lib.core.exception import SqlmapBaseException
3131
from lib.core.exception import SqlmapSilentQuitException
3232
from lib.core.exception import SqlmapUserQuitException
33+
from lib.core.option import initOptions
3334
from lib.core.option import init
3435
from lib.core.profiling import profile
3536
from lib.core.settings import LEGAL_DISCLAIMER
3637
from lib.core.testing import smokeTest
3738
from lib.core.testing import liveTest
3839
from lib.parse.cmdline import cmdLineParser
40+
from lib.utils.api import setRestAPILog
3941
from lib.utils.api import StdDbOut
4042

4143
def modulePath():
@@ -57,19 +59,22 @@ def main():
5759

5860
# Store original command line options for possible later restoration
5961
cmdLineOptions.update(cmdLineParser().__dict__)
60-
init(cmdLineOptions)
62+
initOptions(cmdLineOptions)
6163

6264
if hasattr(conf, "api"):
6365
# Overwrite system standard output and standard error to write
6466
# to an IPC database
6567
sys.stdout = StdDbOut(conf.taskid, messagetype="stdout")
6668
sys.stderr = StdDbOut(conf.taskid, messagetype="stderr")
69+
setRestAPILog()
6770

6871
banner()
6972

7073
dataToStdout("[!] legal disclaimer: %s\n\n" % LEGAL_DISCLAIMER, forceOutput=True)
7174
dataToStdout("[*] starting at %s\n\n" % time.strftime("%X"), forceOutput=True)
7275

76+
init()
77+
7378
if conf.profile:
7479
profile()
7580
elif conf.smokeTest:

extra/shutils/regressiontest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def main():
6666
test_counts = []
6767
attachments = {}
6868

69-
command_line = "python /opt/sqlmap/sqlmap.py --live-test"
70-
proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
69+
proc = subprocess.Popen("python /opt/sqlmap/sqlmap.py --update", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
70+
proc.wait()
7171

72+
proc = subprocess.Popen("python /opt/sqlmap/sqlmap.py --live-test", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7273
proc.wait()
7374
stdout, stderr = proc.communicate()
7475

lib/controller/action.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.core.data import kb
1313
from lib.core.data import logger
1414
from lib.core.data import paths
15+
from lib.core.enums import API_CONTENT_TYPE
1516
from lib.core.exception import SqlmapNoneDataException
1617
from lib.core.exception import SqlmapUnsupportedDBMSException
1718
from lib.core.settings import SUPPORTED_DBMS
@@ -77,7 +78,7 @@ def action():
7778
if conf.getPasswordHashes:
7879
try:
7980
conf.dumper.userSettings("database management system users password hashes",
80-
conf.dbmsHandler.getPasswordHashes(), "password hash")
81+
conf.dbmsHandler.getPasswordHashes(), "password hash", API_CONTENT_TYPE.PASSWORDS)
8182
except SqlmapNoneDataException, ex:
8283
logger.critical(ex)
8384
except:
@@ -86,7 +87,7 @@ def action():
8687
if conf.getPrivileges:
8788
try:
8889
conf.dumper.userSettings("database management system users privileges",
89-
conf.dbmsHandler.getPrivileges(), "privilege")
90+
conf.dbmsHandler.getPrivileges(), "privilege", API_CONTENT_TYPE.PRIVILEGES)
9091
except SqlmapNoneDataException, ex:
9192
logger.critical(ex)
9293
except:
@@ -95,7 +96,7 @@ def action():
9596
if conf.getRoles:
9697
try:
9798
conf.dumper.userSettings("database management system users roles",
98-
conf.dbmsHandler.getRoles(), "role")
99+
conf.dbmsHandler.getRoles(), "role", API_CONTENT_TYPE.ROLES)
99100
except SqlmapNoneDataException, ex:
100101
logger.critical(ex)
101102
except:
@@ -111,10 +112,10 @@ def action():
111112
conf.dumper.dbTables(tableExists(paths.COMMON_TABLES))
112113

113114
if conf.getSchema:
114-
conf.dumper.dbTableColumns(conf.dbmsHandler.getSchema())
115+
conf.dumper.dbTableColumns(conf.dbmsHandler.getSchema(), API_CONTENT_TYPE.SCHEMA)
115116

116117
if conf.getColumns:
117-
conf.dumper.dbTableColumns(conf.dbmsHandler.getColumns())
118+
conf.dumper.dbTableColumns(conf.dbmsHandler.getColumns(), API_CONTENT_TYPE.COLUMNS)
118119

119120
if conf.getCount:
120121
conf.dumper.dbTablesCount(conf.dbmsHandler.getCount())

lib/controller/controller.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from lib.core.data import conf
3737
from lib.core.data import kb
3838
from lib.core.data import logger
39+
from lib.core.enums import API_CONTENT_TYPE
3940
from lib.core.enums import HASHDB_KEYS
4041
from lib.core.enums import HEURISTIC_TEST
4142
from lib.core.enums import HTTPMETHOD
@@ -151,9 +152,11 @@ def _showInjections():
151152
header = "sqlmap identified the following injection points with "
152153
header += "a total of %d HTTP(s) requests" % kb.testQueryCount
153154

154-
data = "".join(set(map(lambda x: _formatInjection(x), kb.injections))).rstrip("\n")
155-
156-
conf.dumper.string(header, data)
155+
if hasattr(conf, "api"):
156+
conf.dumper.string("", kb.injections, content_type=API_CONTENT_TYPE.TECHNIQUES)
157+
else:
158+
data = "".join(set(map(lambda x: _formatInjection(x), kb.injections))).rstrip("\n")
159+
conf.dumper.string(header, data)
157160

158161
if conf.tamper:
159162
warnMsg = "changes made by tampering scripts are not "

lib/core/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
760760
message = data
761761

762762
if hasattr(conf, "api"):
763-
sys.stdout.write(message, status=status, content_type=content_type)
763+
if content_type and status:
764+
sys.stdout.write(message, status, content_type)
764765
else:
765766
sys.stdout.write(setColor(message, bold))
766767

@@ -772,7 +773,7 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
772773
if kb.get("multiThreadMode"):
773774
logging._releaseLock()
774775

775-
kb.prependFlag = len(data) == 1 and data not in ('\n', '\r') or len(data) > 2 and data[0] == '\r' and data[-1] != '\n'
776+
kb.prependFlag = isinstance(data, basestring) and (len(data) == 1 and data not in ('\n', '\r') or len(data) > 2 and data[0] == '\r' and data[-1] != '\n')
776777

777778
def dataToTrafficFile(data):
778779
if not conf.trafficFile:

lib/core/dump.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Dump(object):
4646
"""
4747
This class defines methods used to parse and output the results
4848
of SQL injection actions
49-
5049
"""
5150

5251
def __init__(self):
@@ -85,8 +84,8 @@ def setOutputFile(self):
8584
def getOutputFile(self):
8685
return self._outputFile
8786

88-
def singleString(self, data):
89-
self._write(data)
87+
def singleString(self, data, content_type=None):
88+
self._write(data, content_type=content_type)
9089

9190
def string(self, header, data, content_type=None, sort=True):
9291
kb.stickyLevel = None
@@ -161,16 +160,20 @@ def users(self, users):
161160
def userSettings(self, header, userSettings, subHeader, content_type=None):
162161
self._areAdmins = set()
163162

164-
if userSettings:
165-
self._write("%s:" % header)
166-
167163
if isinstance(userSettings, (tuple, list, set)):
168164
self._areAdmins = userSettings[1]
169165
userSettings = userSettings[0]
170166

171167
users = userSettings.keys()
172168
users.sort(key=lambda x: x.lower() if isinstance(x, basestring) else x)
173169

170+
if hasattr(conf, "api"):
171+
self._write(userSettings, content_type=content_type)
172+
return
173+
174+
if userSettings:
175+
self._write("%s:" % header)
176+
174177
for user in users:
175178
settings = userSettings[user]
176179

@@ -196,8 +199,12 @@ def userSettings(self, header, userSettings, subHeader, content_type=None):
196199
def dbs(self, dbs):
197200
self.lister("available databases", dbs, content_type=API_CONTENT_TYPE.DBS)
198201

199-
def dbTables(self, dbTables, content_type=API_CONTENT_TYPE.TABLES):
202+
def dbTables(self, dbTables):
200203
if isinstance(dbTables, dict) and len(dbTables) > 0:
204+
if hasattr(conf, "api"):
205+
self._write(dbTables, content_type=API_CONTENT_TYPE.TABLES)
206+
return
207+
201208
maxlength = 0
202209

203210
for tables in dbTables.values():
@@ -230,12 +237,16 @@ def dbTables(self, dbTables, content_type=API_CONTENT_TYPE.TABLES):
230237

231238
self._write("+%s+\n" % lines)
232239
elif dbTables is None or len(dbTables) == 0:
233-
self.singleString("No tables found")
240+
self.singleString("No tables found", content_type=API_CONTENT_TYPE.TABLES)
234241
else:
235-
self.string("tables", dbTables)
242+
self.string("tables", dbTables, content_type=API_CONTENT_TYPE.TABLES)
236243

237-
def dbTableColumns(self, tableColumns, content_type=API_CONTENT_TYPE.COLUMNS):
244+
def dbTableColumns(self, tableColumns, content_type=None):
238245
if isinstance(tableColumns, dict) and len(tableColumns) > 0:
246+
if hasattr(conf, "api"):
247+
self._write(tableColumns, content_type=content_type)
248+
return
249+
239250
for db, tables in tableColumns.items():
240251
if not db:
241252
db = "All"
@@ -301,8 +312,12 @@ def dbTableColumns(self, tableColumns, content_type=API_CONTENT_TYPE.COLUMNS):
301312
else:
302313
self._write("+%s+\n" % lines1)
303314

304-
def dbTablesCount(self, dbTables, content_type=API_CONTENT_TYPE.COUNT):
315+
def dbTablesCount(self, dbTables):
305316
if isinstance(dbTables, dict) and len(dbTables) > 0:
317+
if hasattr(conf, "api"):
318+
self._write(dbTables, content_type=API_CONTENT_TYPE.COUNT)
319+
return
320+
306321
maxlength1 = len("Table")
307322
maxlength2 = len("Entries")
308323

@@ -343,7 +358,7 @@ def dbTablesCount(self, dbTables, content_type=API_CONTENT_TYPE.COUNT):
343358
else:
344359
logger.error("unable to retrieve the number of entries for any table")
345360

346-
def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE):
361+
def dbTableValues(self, tableValues):
347362
replication = None
348363
rtable = None
349364
dumpFP = None
@@ -356,6 +371,10 @@ def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE):
356371
db = "All"
357372
table = tableValues["__infos__"]["table"]
358373

374+
if hasattr(conf, "api"):
375+
self._write(tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE)
376+
return
377+
359378
if conf.dumpFormat == DUMP_FORMAT.SQLITE:
360379
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
361380
elif conf.dumpFormat in (DUMP_FORMAT.CSV, DUMP_FORMAT.HTML):
@@ -549,7 +568,11 @@ def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE):
549568
dumpFP.close()
550569
logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName))
551570

552-
def dbColumns(self, dbColumnsDict, colConsider, dbs, content_type=API_CONTENT_TYPE.COLUMNS):
571+
def dbColumns(self, dbColumnsDict, colConsider, dbs):
572+
if hasattr(conf, "api"):
573+
self._write(dbColumnsDict, content_type=API_CONTENT_TYPE.COLUMNS)
574+
return
575+
553576
for column in dbColumnsDict.keys():
554577
if colConsider == "1":
555578
colConsiderStr = "s like '" + column + "' were"

lib/core/enums.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,29 +246,30 @@ class WEB_API:
246246

247247
class API_CONTENT_TYPE:
248248
TECHNIQUES = 0
249-
BANNER = 1
250-
CURRENT_USER = 2
251-
CURRENT_DB = 3
252-
HOSTNAME = 4
253-
IS_DBA = 5
254-
USERS = 6
255-
PASSWORDS = 7
256-
PRIVILEGES = 8
257-
ROLES = 9
258-
DBS = 10
259-
TABLES = 11
260-
COLUMNS = 12
261-
SCHEMA = 13
262-
COUNT = 14
263-
DUMP_TABLE = 15
264-
SEARCH = 16
265-
SQL_QUERY = 17
266-
COMMON_TABLES = 18
267-
COMMON_COLUMNS = 19
268-
FILE_READ = 20
269-
FILE_WRITE = 21
270-
OS_CMD = 22
271-
REG_READ = 23
249+
DBMS_FINGERPRINT = 1
250+
BANNER = 2
251+
CURRENT_USER = 3
252+
CURRENT_DB = 4
253+
HOSTNAME = 5
254+
IS_DBA = 6
255+
USERS = 7
256+
PASSWORDS = 8
257+
PRIVILEGES = 9
258+
ROLES = 10
259+
DBS = 11
260+
TABLES = 12
261+
COLUMNS = 13
262+
SCHEMA = 14
263+
COUNT = 15
264+
DUMP_TABLE = 16
265+
SEARCH = 17
266+
SQL_QUERY = 18
267+
COMMON_TABLES = 19
268+
COMMON_COLUMNS = 20
269+
FILE_READ = 21
270+
FILE_WRITE = 22
271+
OS_CMD = 23
272+
REG_READ = 24
272273

273274
class API_CONTENT_STATUS:
274275
IN_PROGRESS = 0

lib/core/option.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
from lib.request.rangehandler import HTTPRangeHandler
137137
from lib.request.redirecthandler import SmartRedirectHandler
138138
from lib.request.templates import getPageTemplate
139-
from lib.utils.api import setRestAPILog
140139
from lib.utils.crawler import crawl
141140
from lib.utils.deps import checkDependencies
142141
from lib.utils.google import Google
@@ -2052,21 +2051,22 @@ def _resolveCrossReferences():
20522051
lib.core.common.getPageTemplate = getPageTemplate
20532052
lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage
20542053

2055-
def init(inputOptions=AttribDict(), overrideOptions=False):
2056-
"""
2057-
Set attributes into both configuration and knowledge base singletons
2058-
based upon command line and configuration file options.
2059-
"""
2060-
2054+
def initOptions(inputOptions=AttribDict(), overrideOptions=False):
20612055
if not inputOptions.disableColoring:
20622056
coloramainit()
20632057

20642058
_setConfAttributes()
20652059
_setKnowledgeBaseAttributes()
20662060
_mergeOptions(inputOptions, overrideOptions)
2061+
2062+
def init():
2063+
"""
2064+
Set attributes into both configuration and knowledge base singletons
2065+
based upon command line and configuration file options.
2066+
"""
2067+
20672068
_useWizardInterface()
20682069
setVerbosity()
2069-
setRestAPILog()
20702070
_saveCmdline()
20712071
_setRequestFromFile()
20722072
_cleanupOptions()

lib/core/testing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.core.exception import SqlmapNotVulnerableException
3030
from lib.core.log import LOGGER_HANDLER
3131
from lib.core.option import init
32+
from lib.core.option import initOptions
3233
from lib.core.optiondict import optDict
3334
from lib.core.settings import UNICODE_ENCODING
3435
from lib.parse.cmdline import cmdLineParser
@@ -243,7 +244,8 @@ def initCase(switches=None):
243244
if key in cmdLineOptions.__dict__:
244245
cmdLineOptions.__dict__[key] = value
245246

246-
init(cmdLineOptions, True)
247+
initOptions(cmdLineOptions, True)
248+
init()
247249

248250
def cleanCase():
249251
shutil.rmtree(paths.SQLMAP_OUTPUT_PATH, True)

0 commit comments

Comments
 (0)