Skip to content

Commit de31688

Browse files
committed
Update for an Issue sqlmapproject#481
1 parent b921ff0 commit de31688

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"dumpTable": "boolean",
122122
"dumpAll": "boolean",
123123
"search": "boolean",
124+
"getComments": "boolean",
124125
"db": "string",
125126
"tbl": "string",
126127
"col": "string",

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ def cmdLineParser():
386386
enumeration.add_option("--search", dest="search", action="store_true",
387387
help="Search column(s), table(s) and/or database name(s)")
388388

389+
enumeration.add_option("--comments", dest="getComments", action="store_true",
390+
help="Retrieve DBMS comments")
391+
389392
enumeration.add_option("-D", dest="db",
390393
help="DBMS database to enumerate")
391394

plugins/generic/databases.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,19 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
554554
name = safeSQLIdentificatorNaming(columnData[0])
555555

556556
if name:
557+
if conf.getComments:
558+
_ = queries[Backend.getIdentifiedDbms()].column_comment
559+
if hasattr(_, "query"):
560+
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
561+
query = _.query % (unsafeSQLIdentificatorNaming(conf.db.upper()), unsafeSQLIdentificatorNaming(tbl.upper()), unsafeSQLIdentificatorNaming(name.upper()))
562+
else:
563+
query = _.query % (unsafeSQLIdentificatorNaming(conf.db), unsafeSQLIdentificatorNaming(tbl), unsafeSQLIdentificatorNaming(name))
564+
comment = unArrayizeValue(inject.getValue(query, blind=False, time=False))
565+
else:
566+
warnMsg = "on %s it is not " % Backend.getIdentifiedDbms()
567+
warnMsg += "possible to get column comments"
568+
singleTimeWarnMessage(warnMsg)
569+
557570
if len(columnData) == 1:
558571
columns[name] = None
559572
else:
@@ -666,6 +679,19 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
666679
column = unArrayizeValue(inject.getValue(query, union=False, error=False))
667680

668681
if not isNoneValue(column):
682+
if conf.getComments:
683+
_ = queries[Backend.getIdentifiedDbms()].column_comment
684+
if hasattr(_, "query"):
685+
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
686+
query = _.query % (unsafeSQLIdentificatorNaming(conf.db.upper()), unsafeSQLIdentificatorNaming(tbl.upper()), unsafeSQLIdentificatorNaming(column.upper()))
687+
else:
688+
query = _.query % (unsafeSQLIdentificatorNaming(conf.db), unsafeSQLIdentificatorNaming(tbl), unsafeSQLIdentificatorNaming(column))
689+
comment = unArrayizeValue(inject.getValue(query, union=False, error=False))
690+
else:
691+
warnMsg = "on %s it is not " % Backend.getIdentifiedDbms()
692+
warnMsg += "possible to get column comments"
693+
singleTimeWarnMessage(warnMsg)
694+
669695
if not onlyColNames:
670696
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
671697
query = rootQuery.blind.query2 % (unsafeSQLIdentificatorNaming(tbl), column, unsafeSQLIdentificatorNaming(conf.db))

sqlmap.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ dumpAll = False
429429
# Valid: True or False
430430
search = False
431431

432+
# Retrieve back-end database management system comments.
433+
# Valid: True or False
434+
getComments = False
435+
432436
# Back-end database management system database to enumerate.
433437
db =
434438

xml/queries.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@
240240
NOTE: in Oracle to check if the session user is DBA you can use:
241241
SELECT USERENV('ISDBA') FROM DUAL
242242
-->
243-
<hostname query="SELECT UTL_INADDR.get_host_name FROM DUAL"/>
244-
<table_comment query="SELECT comments FROM user_tab_comments WHERE table_name='%s'"/>
245-
<column_comment query="SELECT comments FROM user_col_comments WHERE table_name='%s' AND column_name='%s'"/>
243+
<hostname query="SELECT UTL_INADDR.GET_HOST_NAME FROM DUAL"/>
244+
<table_comment query="SELECT COMMENTS FROM ALL_TAB_COMMENTS WHERE OWNER='%s' AND TABLE_NAME='%s'"/>
245+
<column_comment query="SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE OWNER='%s' AND TABLE_NAME='%s' AND COLUMN_NAME='%s'"/>
246246
<is_dba query="(SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE=USER AND GRANTED_ROLE='DBA')='DBA'"/>
247247
<users>
248248
<inband query="SELECT USERNAME FROM SYS.ALL_USERS"/>
@@ -324,6 +324,8 @@
324324
<current_user/>
325325
<current_db/>
326326
<hostname/>
327+
<table_comment/>
328+
<column_comment/>
327329
<is_dba/>
328330
<check_udf/>
329331
<users/>
@@ -374,6 +376,8 @@
374376
<current_user/>
375377
<current_db/>
376378
<hostname/>
379+
<table_comment/>
380+
<column_comment/>
377381
<is_dba/>
378382
<dbs/>
379383
<!--MSysObjects have no read permission by default-->
@@ -415,6 +419,8 @@
415419
<current_user query="SELECT CURRENT_USER FROM RDB$DATABASE"/>
416420
<current_db query="SELECT RDB$GET_CONTEXT('SYSTEM','DB_NAME') FROM RDB$DATABASE"/>
417421
<hostname/>
422+
<table_comment/>
423+
<column_comment/>
418424
<is_dba query="CURRENT_USER='SYSDBA'"/>
419425
<users>
420426
<inband query="SELECT RDB$USER FROM RDB$USER_PRIVILEGES"/>
@@ -471,6 +477,8 @@
471477
<current_user query="SELECT USER() FROM DUAL"/>
472478
<current_db query="SELECT DATABASE() FROM DUAL"/>
473479
<hostname/>
480+
<table_comment/>
481+
<column_comment/>
474482
<is_dba/>
475483
<users>
476484
<inband query="SELECT username FROM domain.users"/>
@@ -521,6 +529,8 @@
521529
<current_user query="SELECT SUSER_NAME()"/>
522530
<current_db query="SELECT DB_NAME()"/>
523531
<hostname/>
532+
<table_comment/>
533+
<column_comment/>
524534
<is_dba query="PATINDEX('%sa_role%',SHOW_ROLE())>0" query2="EXISTS(SELECT * FROM master..syslogins,master..sysloginroles WHERE srid=0 and name='%s')"/>
525535
<users>
526536
<inband query="SELECT name FROM master..syslogins"/>
@@ -592,6 +602,8 @@
592602
<!-- NOTE: On DB2 we use the current user as default schema (database) -->
593603
<current_db query="SELECT current server FROM SYSIBM.SYSDUMMY1"/>
594604
<hostname query="SELECT host_name FROM TABLE(sysproc.env_get_sys_info())"/>
605+
<table_comment/>
606+
<column_comment/>
595607
<is_dba query="(SELECT dbadmauth FROM syscat.dbauth WHERE grantee=current user)='Y'"/>
596608
<users>
597609
<inband query="SELECT grantee FROM sysibm.sysdbauth WHERE grantee!='SYSTEM' AND grantee!='PUBLIC'"/>
@@ -657,6 +669,8 @@
657669
<current_user query="CURRENT_USER"/>
658670
<current_db query="DATABASE()"/>
659671
<hostname/>
672+
<table_comment/>
673+
<column_comment/>
660674
<is_dba query="SELECT ADMIN FROM INFORMATION_SCHEMA.SYSTEM_USERS WHERE USER=CURRENT_USER"/>
661675
<check_udf/>
662676
<users>

0 commit comments

Comments
 (0)