improvement of --common-tables and --common-columns

This commit is contained in:
Miroslav Stampar 2010-11-11 20:37:25 +00:00
parent 2d872f850a
commit 8aefd0bbf7
2 changed files with 79 additions and 110 deletions

View File

@ -138,32 +138,7 @@ class Dump:
self.lister("available databases", dbs)
def dbTables(self, dbTables):
if isinstance(dbTables, list) and len(dbTables) > 0:
maxlength = 0
for table in dbTables:
maxlength = max(maxlength, len(table))
lines = "-" * (int(maxlength) + 2)
dbTables.sort(key=lambda x: x.lower())
self.__write("Database: %s" % conf.db)
if len(dbTables) == 1:
self.__write("[1 table]")
else:
self.__write("[%d tables]" % len(dbTables))
self.__write("+%s+" % lines)
for table in dbTables:
blank = " " * (maxlength - len(table))
self.__write("| %s%s |" % (table, blank))
self.__write("+%s+\n" % lines)
elif isinstance(dbTables, dict) and len(dbTables) > 0:
if isinstance(dbTables, dict) and len(dbTables) > 0:
maxlength = 0
for tables in dbTables.values():
@ -199,33 +174,6 @@ class Dump:
self.string("tables", dbTables)
def dbTableColumns(self, tableColumns):
if isinstance(tableColumns, list) and len(tableColumns) > 0:
maxlength = 0
for table in tableColumns:
maxlength = max(maxlength, len(table))
lines = "-" * (int(maxlength) + 2)
tableColumns.sort(key=lambda x: x.lower())
self.__write("Database: %s\nTable: %s" % (conf.db if conf.db else 'All', conf.tbl))
if len(tableColumns) == 1:
self.__write("[1 column]")
else:
self.__write("[%d columns]" % len(tableColumns))
self.__write("+%s+" % lines)
for table in tableColumns:
blank = " " * (maxlength - len(table))
self.__write("| %s%s |" % (table, blank))
self.__write("+%s+\n" % lines)
elif isinstance(tableColumns, dict) and len(tableColumns) > 0:
for db, tables in tableColumns.items():
if not db:
db = "All"

View File

@ -18,6 +18,7 @@ from lib.core.common import pushValue
from lib.core.common import randomInt
from lib.core.common import safeStringFormat
from lib.core.data import conf
from lib.core.data import kb
from lib.core.data import logger
from lib.core.exception import sqlmapMissingMandatoryOptionException
from lib.request.connect import Connect as Request
@ -55,8 +56,14 @@ def tableExists(tableFile):
if not retVal:
warnMsg = "no table found"
logger.warn(warnMsg)
else:
for item in retVal:
if not kb.data.cachedTables.has_key(conf.db):
kb.data.cachedTables[conf.db] = [item]
else:
kb.data.cachedTables[conf.db].append(item)
return retVal
return kb.data.cachedTables
def columnExists(columnFile):
if not conf.tbl:
@ -96,5 +103,19 @@ def columnExists(columnFile):
if not retVal:
warnMsg = "no column found"
logger.warn(warnMsg)
else:
columns = {}
return retVal
for column in retVal:
query = agent.prefixQuery("%s" % safeStringFormat("AND EXISTS(SELECT %s FROM %s WHERE %s>0)", (column, table, column)))
query = agent.postfixQuery(query)
result = Request.queryPage(agent.payload(newValue=query))
if result:
columns[column] = 'numeric'
else:
columns[column] = 'non-numeric'
kb.data.cachedColumns[conf.db] = {conf.tbl: columns}
return kb.data.cachedColumns