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

Skip to content

Commit 9329f8c

Browse files
committed
Minor enhancement to be able to enumerate table columns and dump table
entries also if the database name is not provided by using the current database on MySQL and MSSQL, the 'public' scheme on PostgreSQL and the 'USERS' TABLESPACE_NAME on Oracle. Minor bug fix so that when the user provide as SELECT statement to be processed an asterisk, now it also work if in the FROM there is no database name specified. Minor layout adjustments.
1 parent 81ed7c2 commit 9329f8c

6 files changed

Lines changed: 26 additions & 15 deletions

File tree

lib/core/common.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,15 +507,20 @@ def expandAsteriskForColumns(expression):
507507
# If the user provided an asterisk rather than the column(s)
508508
# name, sqlmap will retrieve the columns itself and reprocess
509509
# the SQL query string (expression)
510-
asterisk = re.search("^SELECT\s+\*\s+FROM\s+(\w+)[\.]+(\w+)\s*", expression, re.I)
510+
asterisk = re.search("^SELECT\s+\*\s+FROM\s+([\w\.\_]+)\s*", expression, re.I)
511511

512512
if asterisk:
513513
infoMsg = "you did not provide the fields in your query. "
514514
infoMsg += "sqlmap will retrieve the column names itself"
515515
logger.info(infoMsg)
516516

517-
conf.db = asterisk.group(1)
518-
conf.tbl = asterisk.group(2)
517+
dbTbl = asterisk.group(1)
518+
519+
if dbTbl and "." in dbTbl:
520+
conf.db, conf.tbl = dbTbl.split(".")
521+
else:
522+
conf.tbl = dbTbl
523+
519524
columnsDict = conf.dbmsHandler.getColumns(onlyColNames=True)
520525

521526
if columnsDict and conf.db in columnsDict and conf.tbl in columnsDict[conf.db]:

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
MSSQL_SYSTEM_DBS = ( "Northwind", "model", "msdb", "pubs", "tempdb" )
5757
MYSQL_SYSTEM_DBS = ( "information_schema", "mysql" ) # Before MySQL 5.0 only "mysql"
5858
PGSQL_SYSTEM_DBS = ( "information_schema", "pg_catalog" )
59-
ORACLE_SYSTEM_DBS = ( "SYSTEM", "SYSAUX" )
59+
ORACLE_SYSTEM_DBS = ( "SYSTEM", "SYSAUX" ) # These are TABLESPACE_NAME
6060

6161
MSSQL_ALIASES = [ "microsoft sql server", "mssqlserver", "mssql", "ms" ]
6262
MYSQL_ALIASES = [ "mysql", "my" ]

lib/core/shell.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def queriesForAutoCompletion():
5454
autoComplQuery = query
5555
elif isinstance(query, dict) and "inband" in query:
5656
autoComplQuery = query["inband"]["query"]
57+
else:
58+
continue
5759

5860
autoComplQueries[autoComplQuery] = None
5961

lib/parse/cmdline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ def cmdLineParser():
168168

169169
enumeration.add_option("--columns", dest="getColumns", action="store_true",
170170
help="Enumerate DBMS database table columns "
171-
"(req: -T, -D)")
171+
"(req:-T opt:-D)")
172172

173173
enumeration.add_option("--dump", dest="dumpTable", action="store_true",
174174
help="Dump DBMS database table entries "
175-
"(req: -T, -D opt: -C, --start, --stop)")
175+
"(req: -T, opt: -D, -C, --start, --stop)")
176176

177177
enumeration.add_option("--dump-all", dest="dumpAll", action="store_true",
178178
help="Dump all DBMS databases tables entries")

lib/request/inject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def getValue(expression, blind=True, inband=True, fromUser=False, expected=None)
372372

373373
expression = cleanQuery(expression)
374374
expression = expandAsteriskForColumns(expression)
375-
value = None
375+
value = None
376376

377377
if inband and conf.unionUse and kb.dbms:
378378
value = __goInband(expression, expected)

plugins/generic/enumeration.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,12 @@ def getColumns(self, onlyColNames=False):
730730
self.forceDbmsEnum()
731731

732732
if not conf.db:
733-
errMsg = "missing database parameter"
734-
raise sqlmapMissingMandatoryOptionException, errMsg
733+
warnMsg = "missing database parameter, sqlmap is going to "
734+
warnMsg += "use the current database to enumerate table "
735+
warnMsg += "'%s' columns" % conf.tbl
736+
logger.warn(warnMsg)
737+
738+
conf.db = self.getCurrentDb()
735739

736740
infoMsg = "fetching columns "
737741
infoMsg += "for table '%s' " % conf.tbl
@@ -740,10 +744,6 @@ def getColumns(self, onlyColNames=False):
740744

741745
rootQuery = queries[kb.dbms].columns
742746

743-
if kb.dbms == "Oracle":
744-
conf.db = conf.db.upper()
745-
conf.tbl = conf.tbl.upper()
746-
747747
if conf.unionUse:
748748
if kb.dbms in ( "MySQL", "PostgreSQL" ):
749749
query = rootQuery["inband"]["query"] % (conf.tbl, conf.db)
@@ -840,8 +840,12 @@ def dumpTable(self):
840840
self.forceDbmsEnum()
841841

842842
if not conf.db:
843-
errMsg = "missing database parameter"
844-
raise sqlmapMissingMandatoryOptionException, errMsg
843+
warnMsg = "missing database parameter, sqlmap is going to "
844+
warnMsg += "use the current database to dump table "
845+
warnMsg += "'%s' entries" % conf.tbl
846+
logger.warn(warnMsg)
847+
848+
conf.db = self.getCurrentDb()
845849

846850
rootQuery = queries[kb.dbms].dumpTable
847851

0 commit comments

Comments
 (0)