mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-06 20:51:31 +00:00
major enhancement, code refactoring for issue #297
This commit is contained in:
@@ -26,6 +26,8 @@ from lib.core.data import conf
|
||||
from lib.core.data import kb
|
||||
from lib.core.data import logger
|
||||
from lib.core.dicts import DUMP_REPLACEMENTS
|
||||
from lib.core.enums import API_CONTENT_STATUS
|
||||
from lib.core.enums import API_CONTENT_TYPE
|
||||
from lib.core.enums import DBMS
|
||||
from lib.core.enums import DUMP_FORMAT
|
||||
from lib.core.exception import SqlmapGenericException
|
||||
@@ -52,8 +54,13 @@ class Dump(object):
|
||||
self._outputFP = None
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def _write(self, data, newline=True, console=True):
|
||||
def _write(self, data, newline=True, console=True, content_type=None):
|
||||
if hasattr(conf, "api"):
|
||||
dataToStdout(data, content_type=content_type, status=API_CONTENT_STATUS.COMPLETE)
|
||||
return
|
||||
|
||||
text = "%s%s" % (data, "\n" if newline else " ")
|
||||
|
||||
if console:
|
||||
dataToStdout(text)
|
||||
|
||||
@@ -81,7 +88,7 @@ class Dump(object):
|
||||
def singleString(self, data):
|
||||
self._write(data)
|
||||
|
||||
def string(self, header, data, sort=True):
|
||||
def string(self, header, data, content_type=None, sort=True):
|
||||
kb.stickyLevel = None
|
||||
|
||||
if isListLike(data):
|
||||
@@ -92,18 +99,19 @@ class Dump(object):
|
||||
if _ and _[-1] == '\n':
|
||||
_ = _[:-1]
|
||||
|
||||
if "\n" in _:
|
||||
if hasattr(conf, "api"):
|
||||
self._write(data, content_type=content_type)
|
||||
elif "\n" in _:
|
||||
self._write("%s:\n---\n%s\n---" % (header, _))
|
||||
else:
|
||||
self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, basestring) else _))
|
||||
elif hasattr(conf, "api"):
|
||||
self._write(data, content_type=content_type)
|
||||
else:
|
||||
self._write("%s:\tNone" % header)
|
||||
|
||||
def lister(self, header, elements, sort=True):
|
||||
if elements:
|
||||
self._write("%s [%d]:" % (header, len(elements)))
|
||||
|
||||
if sort:
|
||||
def lister(self, header, elements, content_type=None, sort=True):
|
||||
if elements and sort:
|
||||
try:
|
||||
elements = set(elements)
|
||||
elements = list(elements)
|
||||
@@ -111,6 +119,13 @@ class Dump(object):
|
||||
except:
|
||||
pass
|
||||
|
||||
if hasattr(conf, "api"):
|
||||
self._write(elements, content_type=content_type)
|
||||
return
|
||||
|
||||
if elements:
|
||||
self._write("%s [%d]:" % (header, len(elements)))
|
||||
|
||||
for element in elements:
|
||||
if isinstance(element, basestring):
|
||||
self._write("[*] %s" % element)
|
||||
@@ -121,29 +136,29 @@ class Dump(object):
|
||||
self._write("")
|
||||
|
||||
def banner(self, data):
|
||||
self.string("banner", data)
|
||||
self.string("banner", data, content_type=API_CONTENT_TYPE.BANNER)
|
||||
|
||||
def currentUser(self, data):
|
||||
self.string("current user", data)
|
||||
self.string("current user", data, content_type=API_CONTENT_TYPE.CURRENT_USER)
|
||||
|
||||
def currentDb(self, data):
|
||||
if Backend.isDbms(DBMS.MAXDB):
|
||||
self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data)
|
||||
self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data, content_type=API_CONTENT_TYPE.CURRENT_DB)
|
||||
elif Backend.isDbms(DBMS.ORACLE):
|
||||
self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data)
|
||||
self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data, content_type=API_CONTENT_TYPE.CURRENT_DB)
|
||||
else:
|
||||
self.string("current database", data)
|
||||
self.string("current database", data, content_type=API_CONTENT_TYPE.CURRENT_DB)
|
||||
|
||||
def hostname(self, data):
|
||||
self.string("hostname", data)
|
||||
self.string("hostname", data, content_type=API_CONTENT_TYPE.HOSTNAME)
|
||||
|
||||
def dba(self, data):
|
||||
self.string("current user is DBA", data)
|
||||
self.string("current user is DBA", data, content_type=API_CONTENT_TYPE.IS_DBA)
|
||||
|
||||
def users(self, users):
|
||||
self.lister("database management system users", users)
|
||||
self.lister("database management system users", users, content_type=API_CONTENT_TYPE.USERS)
|
||||
|
||||
def userSettings(self, header, userSettings, subHeader):
|
||||
def userSettings(self, header, userSettings, subHeader, content_type=None):
|
||||
self._areAdmins = set()
|
||||
|
||||
if userSettings:
|
||||
@@ -179,9 +194,9 @@ class Dump(object):
|
||||
self.singleString("")
|
||||
|
||||
def dbs(self, dbs):
|
||||
self.lister("available databases", dbs)
|
||||
self.lister("available databases", dbs, content_type=API_CONTENT_TYPE.DBS)
|
||||
|
||||
def dbTables(self, dbTables):
|
||||
def dbTables(self, dbTables, content_type=API_CONTENT_TYPE.TABLES):
|
||||
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
||||
maxlength = 0
|
||||
|
||||
@@ -219,7 +234,7 @@ class Dump(object):
|
||||
else:
|
||||
self.string("tables", dbTables)
|
||||
|
||||
def dbTableColumns(self, tableColumns):
|
||||
def dbTableColumns(self, tableColumns, content_type=API_CONTENT_TYPE.COLUMNS):
|
||||
if isinstance(tableColumns, dict) and len(tableColumns) > 0:
|
||||
for db, tables in tableColumns.items():
|
||||
if not db:
|
||||
@@ -286,7 +301,7 @@ class Dump(object):
|
||||
else:
|
||||
self._write("+%s+\n" % lines1)
|
||||
|
||||
def dbTablesCount(self, dbTables):
|
||||
def dbTablesCount(self, dbTables, content_type=API_CONTENT_TYPE.COUNT):
|
||||
if isinstance(dbTables, dict) and len(dbTables) > 0:
|
||||
maxlength1 = len("Table")
|
||||
maxlength2 = len("Entries")
|
||||
@@ -328,7 +343,7 @@ class Dump(object):
|
||||
else:
|
||||
logger.error("unable to retrieve the number of entries for any table")
|
||||
|
||||
def dbTableValues(self, tableValues):
|
||||
def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE):
|
||||
replication = None
|
||||
rtable = None
|
||||
dumpFP = None
|
||||
@@ -534,7 +549,7 @@ class Dump(object):
|
||||
dumpFP.close()
|
||||
logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName))
|
||||
|
||||
def dbColumns(self, dbColumnsDict, colConsider, dbs):
|
||||
def dbColumns(self, dbColumnsDict, colConsider, dbs, content_type=API_CONTENT_TYPE.COLUMNS):
|
||||
for column in dbColumnsDict.keys():
|
||||
if colConsider == "1":
|
||||
colConsiderStr = "s like '" + column + "' were"
|
||||
@@ -565,13 +580,13 @@ class Dump(object):
|
||||
self.dbTableColumns(_)
|
||||
|
||||
def query(self, query, queryRes):
|
||||
self.string(query, queryRes)
|
||||
self.string(query, queryRes, content_type=API_CONTENT_TYPE.SQL_QUERY)
|
||||
|
||||
def rFile(self, fileData):
|
||||
self.lister("files saved to", fileData, sort=False)
|
||||
self.lister("files saved to", fileData, sort=False, content_type=API_CONTENT_TYPE.FILE_READ)
|
||||
|
||||
def registerValue(self, registerData):
|
||||
self.string("Registry key value data", registerData, sort=False)
|
||||
def registerValue(self):
|
||||
self.string("Registry key value data", registerData, registerData, content_type=API_CONTENT_TYPE.REG_READ, sort=False)
|
||||
|
||||
# object to manage how to print the retrieved queries output to
|
||||
# standard output and sessions file
|
||||
|
||||
Reference in New Issue
Block a user