mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-29 04:53:48 +03:00
improvements to the dump library to output to the API data fetched properly formatted (issue #297)
This commit is contained in:
parent
eeecb3fe2c
commit
bfce7210e6
|
@ -12,6 +12,7 @@ from lib.core.data import conf
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
from lib.core.data import paths
|
from lib.core.data import paths
|
||||||
|
from lib.core.enums import API_CONTENT_TYPE
|
||||||
from lib.core.exception import SqlmapNoneDataException
|
from lib.core.exception import SqlmapNoneDataException
|
||||||
from lib.core.exception import SqlmapUnsupportedDBMSException
|
from lib.core.exception import SqlmapUnsupportedDBMSException
|
||||||
from lib.core.settings import SUPPORTED_DBMS
|
from lib.core.settings import SUPPORTED_DBMS
|
||||||
|
@ -77,7 +78,7 @@ def action():
|
||||||
if conf.getPasswordHashes:
|
if conf.getPasswordHashes:
|
||||||
try:
|
try:
|
||||||
conf.dumper.userSettings("database management system users password hashes",
|
conf.dumper.userSettings("database management system users password hashes",
|
||||||
conf.dbmsHandler.getPasswordHashes(), "password hash")
|
conf.dbmsHandler.getPasswordHashes(), "password hash", API_CONTENT_TYPE.PASSWORDS)
|
||||||
except SqlmapNoneDataException, ex:
|
except SqlmapNoneDataException, ex:
|
||||||
logger.critical(ex)
|
logger.critical(ex)
|
||||||
except:
|
except:
|
||||||
|
@ -86,7 +87,7 @@ def action():
|
||||||
if conf.getPrivileges:
|
if conf.getPrivileges:
|
||||||
try:
|
try:
|
||||||
conf.dumper.userSettings("database management system users privileges",
|
conf.dumper.userSettings("database management system users privileges",
|
||||||
conf.dbmsHandler.getPrivileges(), "privilege")
|
conf.dbmsHandler.getPrivileges(), "privilege", API_CONTENT_TYPE.PRIVILEGES)
|
||||||
except SqlmapNoneDataException, ex:
|
except SqlmapNoneDataException, ex:
|
||||||
logger.critical(ex)
|
logger.critical(ex)
|
||||||
except:
|
except:
|
||||||
|
@ -95,7 +96,7 @@ def action():
|
||||||
if conf.getRoles:
|
if conf.getRoles:
|
||||||
try:
|
try:
|
||||||
conf.dumper.userSettings("database management system users roles",
|
conf.dumper.userSettings("database management system users roles",
|
||||||
conf.dbmsHandler.getRoles(), "role")
|
conf.dbmsHandler.getRoles(), "role", API_CONTENT_TYPE.ROLES)
|
||||||
except SqlmapNoneDataException, ex:
|
except SqlmapNoneDataException, ex:
|
||||||
logger.critical(ex)
|
logger.critical(ex)
|
||||||
except:
|
except:
|
||||||
|
@ -111,10 +112,10 @@ def action():
|
||||||
conf.dumper.dbTables(tableExists(paths.COMMON_TABLES))
|
conf.dumper.dbTables(tableExists(paths.COMMON_TABLES))
|
||||||
|
|
||||||
if conf.getSchema:
|
if conf.getSchema:
|
||||||
conf.dumper.dbTableColumns(conf.dbmsHandler.getSchema())
|
conf.dumper.dbTableColumns(conf.dbmsHandler.getSchema(), API_CONTENT_TYPE.SCHEMA)
|
||||||
|
|
||||||
if conf.getColumns:
|
if conf.getColumns:
|
||||||
conf.dumper.dbTableColumns(conf.dbmsHandler.getColumns())
|
conf.dumper.dbTableColumns(conf.dbmsHandler.getColumns(), API_CONTENT_TYPE.COLUMNS)
|
||||||
|
|
||||||
if conf.getCount:
|
if conf.getCount:
|
||||||
conf.dumper.dbTablesCount(conf.dbmsHandler.getCount())
|
conf.dumper.dbTablesCount(conf.dbmsHandler.getCount())
|
||||||
|
|
|
@ -85,8 +85,8 @@ class Dump(object):
|
||||||
def getOutputFile(self):
|
def getOutputFile(self):
|
||||||
return self._outputFile
|
return self._outputFile
|
||||||
|
|
||||||
def singleString(self, data):
|
def singleString(self, data, content_type=None):
|
||||||
self._write(data)
|
self._write(data, content_type=content_type)
|
||||||
|
|
||||||
def string(self, header, data, content_type=None, sort=True):
|
def string(self, header, data, content_type=None, sort=True):
|
||||||
kb.stickyLevel = None
|
kb.stickyLevel = None
|
||||||
|
@ -161,9 +161,6 @@ class Dump(object):
|
||||||
def userSettings(self, header, userSettings, subHeader, content_type=None):
|
def userSettings(self, header, userSettings, subHeader, content_type=None):
|
||||||
self._areAdmins = set()
|
self._areAdmins = set()
|
||||||
|
|
||||||
if userSettings:
|
|
||||||
self._write("%s:" % header)
|
|
||||||
|
|
||||||
if isinstance(userSettings, (tuple, list, set)):
|
if isinstance(userSettings, (tuple, list, set)):
|
||||||
self._areAdmins = userSettings[1]
|
self._areAdmins = userSettings[1]
|
||||||
userSettings = userSettings[0]
|
userSettings = userSettings[0]
|
||||||
|
@ -171,6 +168,13 @@ class Dump(object):
|
||||||
users = userSettings.keys()
|
users = userSettings.keys()
|
||||||
users.sort(key=lambda x: x.lower() if isinstance(x, basestring) else x)
|
users.sort(key=lambda x: x.lower() if isinstance(x, basestring) else x)
|
||||||
|
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(userSettings, content_type=content_type)
|
||||||
|
return
|
||||||
|
|
||||||
|
if userSettings:
|
||||||
|
self._write("%s:" % header)
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
settings = userSettings[user]
|
settings = userSettings[user]
|
||||||
|
|
||||||
|
@ -196,8 +200,12 @@ class Dump(object):
|
||||||
def dbs(self, dbs):
|
def dbs(self, dbs):
|
||||||
self.lister("available databases", dbs, content_type=API_CONTENT_TYPE.DBS)
|
self.lister("available databases", dbs, content_type=API_CONTENT_TYPE.DBS)
|
||||||
|
|
||||||
def dbTables(self, dbTables, content_type=API_CONTENT_TYPE.TABLES):
|
def dbTables(self, dbTables):
|
||||||
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(dbTables, content_type=API_CONTENT_TYPE.TABLES)
|
||||||
|
return
|
||||||
|
|
||||||
maxlength = 0
|
maxlength = 0
|
||||||
|
|
||||||
for tables in dbTables.values():
|
for tables in dbTables.values():
|
||||||
|
@ -230,12 +238,16 @@ class Dump(object):
|
||||||
|
|
||||||
self._write("+%s+\n" % lines)
|
self._write("+%s+\n" % lines)
|
||||||
elif dbTables is None or len(dbTables) == 0:
|
elif dbTables is None or len(dbTables) == 0:
|
||||||
self.singleString("No tables found")
|
self.singleString("No tables found", content_type=API_CONTENT_TYPE.TABLES)
|
||||||
else:
|
else:
|
||||||
self.string("tables", dbTables)
|
self.string("tables", dbTables, content_type=API_CONTENT_TYPE.TABLES)
|
||||||
|
|
||||||
def dbTableColumns(self, tableColumns, content_type=API_CONTENT_TYPE.COLUMNS):
|
def dbTableColumns(self, tableColumns, content_type=None):
|
||||||
if isinstance(tableColumns, dict) and len(tableColumns) > 0:
|
if isinstance(tableColumns, dict) and len(tableColumns) > 0:
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(tableColumns, content_type=content_type)
|
||||||
|
return
|
||||||
|
|
||||||
for db, tables in tableColumns.items():
|
for db, tables in tableColumns.items():
|
||||||
if not db:
|
if not db:
|
||||||
db = "All"
|
db = "All"
|
||||||
|
@ -301,8 +313,12 @@ class Dump(object):
|
||||||
else:
|
else:
|
||||||
self._write("+%s+\n" % lines1)
|
self._write("+%s+\n" % lines1)
|
||||||
|
|
||||||
def dbTablesCount(self, dbTables, content_type=API_CONTENT_TYPE.COUNT):
|
def dbTablesCount(self, dbTables):
|
||||||
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(dbTables, content_type=API_CONTENT_TYPE.COUNT)
|
||||||
|
return
|
||||||
|
|
||||||
maxlength1 = len("Table")
|
maxlength1 = len("Table")
|
||||||
maxlength2 = len("Entries")
|
maxlength2 = len("Entries")
|
||||||
|
|
||||||
|
@ -343,7 +359,7 @@ class Dump(object):
|
||||||
else:
|
else:
|
||||||
logger.error("unable to retrieve the number of entries for any table")
|
logger.error("unable to retrieve the number of entries for any table")
|
||||||
|
|
||||||
def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE):
|
def dbTableValues(self, tableValues):
|
||||||
replication = None
|
replication = None
|
||||||
rtable = None
|
rtable = None
|
||||||
dumpFP = None
|
dumpFP = None
|
||||||
|
@ -356,6 +372,10 @@ class Dump(object):
|
||||||
db = "All"
|
db = "All"
|
||||||
table = tableValues["__infos__"]["table"]
|
table = tableValues["__infos__"]["table"]
|
||||||
|
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE)
|
||||||
|
return
|
||||||
|
|
||||||
if conf.dumpFormat == DUMP_FORMAT.SQLITE:
|
if conf.dumpFormat == DUMP_FORMAT.SQLITE:
|
||||||
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
|
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
|
||||||
elif conf.dumpFormat in (DUMP_FORMAT.CSV, DUMP_FORMAT.HTML):
|
elif conf.dumpFormat in (DUMP_FORMAT.CSV, DUMP_FORMAT.HTML):
|
||||||
|
@ -549,7 +569,11 @@ class Dump(object):
|
||||||
dumpFP.close()
|
dumpFP.close()
|
||||||
logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName))
|
logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName))
|
||||||
|
|
||||||
def dbColumns(self, dbColumnsDict, colConsider, dbs, content_type=API_CONTENT_TYPE.COLUMNS):
|
def dbColumns(self, dbColumnsDict, colConsider, dbs):
|
||||||
|
if hasattr(conf, "api"):
|
||||||
|
self._write(dbColumnsDict, content_type=API_CONTENT_TYPE.COLUMNS)
|
||||||
|
return
|
||||||
|
|
||||||
for column in dbColumnsDict.keys():
|
for column in dbColumnsDict.keys():
|
||||||
if colConsider == "1":
|
if colConsider == "1":
|
||||||
colConsiderStr = "s like '" + column + "' were"
|
colConsiderStr = "s like '" + column + "' were"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user