Skip to content

Commit dbb0d7f

Browse files
committed
Important fix (Issue sqlmapproject#489) - we had a bad presumption than only public schema could be used for enumeration (while all schemas inside a current db could be used)
1 parent 86b62dc commit dbb0d7f

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

lib/core/dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def currentUser(self, data):
143143
def currentDb(self, data):
144144
if Backend.isDbms(DBMS.MAXDB):
145145
self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data, content_type=CONTENT_TYPE.CURRENT_DB)
146-
elif Backend.isDbms(DBMS.ORACLE):
146+
elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL):
147147
self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data, content_type=CONTENT_TYPE.CURRENT_DB)
148148
else:
149149
self.string("current database", data, content_type=CONTENT_TYPE.CURRENT_DB)

plugins/dbms/postgresql/fingerprint.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,3 @@ def checkDbmsOs(self, detailed=False):
171171
logger.info(infoMsg)
172172

173173
self.cleanup(onlyFileTbl=True)
174-
175-
def forceDbmsEnum(self):
176-
if conf.db not in PGSQL_SYSTEM_DBS and conf.db != "public":
177-
conf.db = "public"
178-
179-
warnMsg = "on %s it is possible to enumerate " % DBMS.PGSQL
180-
warnMsg += "only on the current schema and/or system databases. "
181-
warnMsg += "sqlmap is going to use 'public' schema as a "
182-
warnMsg += "database name"
183-
singleTimeWarnMessage(warnMsg)

plugins/generic/databases.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from lib.core.common import pushValue
2121
from lib.core.common import readInput
2222
from lib.core.common import safeSQLIdentificatorNaming
23+
from lib.core.common import singleTimeWarnMessage
2324
from lib.core.common import unArrayizeValue
2425
from lib.core.common import unsafeSQLIdentificatorNaming
2526
from lib.core.data import conf
@@ -62,6 +63,12 @@ def getCurrentDb(self):
6263
if not kb.data.currentDb:
6364
kb.data.currentDb = unArrayizeValue(inject.getValue(query, safeCharEncode=False))
6465

66+
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.PGSQL):
67+
warnMsg = "on %s you'll need to use " % Backend.getIdentifiedDbms()
68+
warnMsg += "schema names for enumeration as the counterpart to database "
69+
warnMsg += "names on other DBMSes"
70+
singleTimeWarnMessage(warnMsg)
71+
6572
return kb.data.currentDb
6673

6774
def getDbs(self):
@@ -76,20 +83,14 @@ def getDbs(self):
7683
warnMsg += "names will be fetched from 'mysql' database"
7784
logger.warn(warnMsg)
7885

79-
elif Backend.isDbms(DBMS.ORACLE):
80-
warnMsg = "schema names are going to be used on Oracle "
86+
elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.PGSQL):
87+
warnMsg = "schema names are going to be used on %s " % Backend.getIdentifiedDbms()
8188
warnMsg += "for enumeration as the counterpart to database "
8289
warnMsg += "names on other DBMSes"
8390
logger.warn(warnMsg)
8491

8592
infoMsg = "fetching database (schema) names"
86-
elif Backend.isDbms(DBMS.DB2):
87-
warnMsg = "schema names are going to be used on IBM DB2 "
88-
warnMsg += "for enumeration as the counterpart to database "
89-
warnMsg += "names on other DBMSes"
90-
logger.warn(warnMsg)
9193

92-
infoMsg = "fetching database (schema) names"
9394
else:
9495
infoMsg = "fetching database names"
9596

xml/queries.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<inference query="ASCII(SUBSTRING((%s)::text FROM %d FOR 1))>%d"/>
9191
<banner query="VERSION()"/>
9292
<current_user query="CURRENT_USER"/>
93-
<current_db query="CURRENT_DATABASE()"/>
93+
<current_db query="CURRENT_SCHEMA()"/>
9494
<hostname/>
9595
<is_dba query="(SELECT usesuper=true FROM pg_user WHERE usename=CURRENT_USER OFFSET 0 LIMIT 1)"/>
9696
<check_udf query="(SELECT proname='%s' FROM pg_proc WHERE proname='%s' OFFSET 0 LIMIT 1)"/>
@@ -108,8 +108,8 @@
108108
</privileges>
109109
<roles/>
110110
<dbs>
111-
<inband query="SELECT datname FROM pg_database"/>
112-
<blind query="SELECT DISTINCT(datname) FROM pg_database OFFSET %d LIMIT 1" count="SELECT COUNT(DISTINCT(datname)) FROM pg_database"/>
111+
<inband query="SELECT schemaname FROM pg_tables"/>
112+
<blind query="SELECT DISTINCT(schemaname) FROM pg_tables OFFSET %d LIMIT 1" count="SELECT COUNT(DISTINCT(schemaname)) FROM pg_tables"/>
113113
</dbs>
114114
<tables>
115115
<inband query="SELECT schemaname,tablename FROM pg_tables" condition="schemaname"/>

0 commit comments

Comments
 (0)