Compare commits

...

9 Commits
1.5.8 ... 1.5.9

Author SHA1 Message Date
Miroslav Stampar
6e968584f6 Minor refactoring 2021-09-02 21:44:41 +02:00
Miroslav Stampar
cc5ba4753c Fixes #4784 2021-08-31 13:07:38 +02:00
Miroslav Stampar
afa4d2c514 Fixes #4783 2021-08-31 13:04:45 +02:00
Miroslav Stampar
d63401632c Fixes #4776 2021-08-26 18:08:48 +02:00
Miroslav Stampar
45553f0efc Fixes #4779 2021-08-26 17:46:56 +02:00
Miroslav Stampar
f1dbe9e388 Minor bug fix 2021-08-18 23:16:19 +02:00
Miroslav Stampar
3977be9c9e Fixing falling back (aka query2) for --tables 2021-08-18 23:08:54 +02:00
Miroslav Stampar
9da558f041 Minor revert (accidental change) 2021-08-18 22:39:32 +02:00
Miroslav Stampar
b3bc401f2e Fixing #4768 2021-08-17 15:16:05 +02:00
8 changed files with 88 additions and 78 deletions

View File

@@ -127,8 +127,8 @@
<blind query="SELECT DISTINCT(schemaname) FROM pg_tables ORDER BY schemaname OFFSET %d LIMIT 1" count="SELECT COUNT(DISTINCT(schemaname)) FROM pg_tables"/> <blind query="SELECT DISTINCT(schemaname) FROM pg_tables ORDER BY schemaname OFFSET %d LIMIT 1" count="SELECT COUNT(DISTINCT(schemaname)) FROM pg_tables"/>
</dbs> </dbs>
<tables> <tables>
<inband query="SELECT schemaname,tablename FROM pg_tables" condition="schemaname"/> <inband query="SELECT schemaname,tablename FROM pg_tables" condition="schemaname" query2="SELECT table_schema,table_name FROM information_schema.tables" condition2="table_schema"/>
<blind query="SELECT tablename FROM pg_tables WHERE schemaname='%s' ORDER BY tablename OFFSET %d LIMIT 1" count="SELECT COUNT(tablename) FROM pg_tables WHERE schemaname='%s'"/> <blind query="SELECT tablename FROM pg_tables WHERE schemaname='%s' ORDER BY tablename OFFSET %d LIMIT 1" count="SELECT COUNT(tablename) FROM pg_tables WHERE schemaname='%s'" query2="SELECT table_name FROM information_schema.tables WHERE table_schema='%s' OFFSET %d LIMIT 1" count2="SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema='%s'"/>
</tables> </tables>
<columns> <columns>
<inband query="SELECT attname,typname FROM pg_attribute b JOIN pg_class a ON a.oid=b.attrelid JOIN pg_type c ON c.oid=b.atttypid JOIN pg_namespace d ON a.relnamespace=d.oid WHERE b.attnum>0 AND a.relname='%s' AND nspname='%s' ORDER BY attname" condition="attname"/> <inband query="SELECT attname,typname FROM pg_attribute b JOIN pg_class a ON a.oid=b.attrelid JOIN pg_type c ON c.oid=b.atttypid JOIN pg_namespace d ON a.relnamespace=d.oid WHERE b.attnum>0 AND a.relname='%s' AND nspname='%s' ORDER BY attname" condition="attname"/>

View File

@@ -295,10 +295,12 @@ def start():
infoMsg = "found a total of %d targets" % len(kb.targets) infoMsg = "found a total of %d targets" % len(kb.targets)
logger.info(infoMsg) logger.info(infoMsg)
hostCount = 0 targetCount = 0
initialHeaders = list(conf.httpHeaders) initialHeaders = list(conf.httpHeaders)
for targetUrl, targetMethod, targetData, targetCookie, targetHeaders in kb.targets: for targetUrl, targetMethod, targetData, targetCookie, targetHeaders in kb.targets:
targetCount += 1
try: try:
if conf.checkInternet: if conf.checkInternet:
infoMsg = "checking for Internet connection" infoMsg = "checking for Internet connection"
@@ -375,12 +377,10 @@ def start():
continue continue
if conf.multipleTargets: if conf.multipleTargets:
hostCount += 1
if conf.forms and conf.method: if conf.forms and conf.method:
message = "[#%d] form:\n%s %s" % (hostCount, conf.method, targetUrl) message = "[%d/%s] Form:\n%s %s" % (targetCount, len(kb.targets) if isListLike(kb.targets) else '?', conf.method, targetUrl)
else: else:
message = "URL %d:\n%s %s" % (hostCount, HTTPMETHOD.GET, targetUrl) message = "[%d/%s] URL:\n%s %s" % (targetCount, len(kb.targets) if isListLike(kb.targets) else '?', HTTPMETHOD.GET, targetUrl)
if conf.cookie: if conf.cookie:
message += "\nCookie: %s" % conf.cookie message += "\nCookie: %s" % conf.cookie
@@ -738,7 +738,7 @@ def start():
if conf.multipleTargets: if conf.multipleTargets:
_saveToResultsFile() _saveToResultsFile()
errMsg += ", skipping to the next %s" % ("form" if conf.forms else "URL") errMsg += ", skipping to the next target"
logger.error(errMsg.lstrip(", ")) logger.error(errMsg.lstrip(", "))
else: else:
logger.critical(errMsg) logger.critical(errMsg)

View File

@@ -20,7 +20,7 @@ from thirdparty import six
from thirdparty.six import unichr as _unichr from thirdparty.six import unichr as _unichr
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.5.8.0" VERSION = "1.5.9.0"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@@ -695,7 +695,7 @@ class Connect(object):
except SqlmapConnectionException as ex: except SqlmapConnectionException as ex:
if conf.proxyList and not kb.threadException: if conf.proxyList and not kb.threadException:
warnMsg = "unable to connect to the target URL ('%s')" % ex warnMsg = "unable to connect to the target URL ('%s')" % getSafeExString(ex)
logger.critical(warnMsg) logger.critical(warnMsg)
threadData.retriesCount = conf.retries threadData.retriesCount = conf.retries
return Connect._retryProxy(**kwargs) return Connect._retryProxy(**kwargs)
@@ -978,7 +978,7 @@ class Connect(object):
if conf.httpHeaders: if conf.httpHeaders:
headers = OrderedDict(conf.httpHeaders) headers = OrderedDict(conf.httpHeaders)
contentType = max(headers[_] if _.upper() == HTTP_HEADER.CONTENT_TYPE.upper() else "" for _ in headers) or None contentType = max(headers[_] or "" if _.upper() == HTTP_HEADER.CONTENT_TYPE.upper() else "" for _ in headers) or None
if (kb.postHint or conf.skipUrlEncode) and postUrlEncode: if (kb.postHint or conf.skipUrlEncode) and postUrlEncode:
postUrlEncode = False postUrlEncode = False

View File

@@ -773,7 +773,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
if not isinstance(ex, _urllib.error.HTTPError) or ex.code == _http_client.UNAUTHORIZED: if not isinstance(ex, _urllib.error.HTTPError) or ex.code == _http_client.UNAUTHORIZED:
errMsg = "There has been a problem while connecting to the " errMsg = "There has been a problem while connecting to the "
errMsg += "REST-JSON API server at '%s' " % addr errMsg += "REST-JSON API server at '%s' " % addr
errMsg += "(%s)" % ex errMsg += "(%s)" % getSafeExString(ex)
logger.critical(errMsg) logger.critical(errMsg)
return return
@@ -825,7 +825,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
try: try:
argv = ["sqlmap.py"] + shlex.split(command)[1:] argv = ["sqlmap.py"] + shlex.split(command)[1:]
except Exception as ex: except Exception as ex:
logger.error("Error occurred while parsing arguments ('%s')" % ex) logger.error("Error occurred while parsing arguments ('%s')" % getSafeExString(ex))
taskid = None taskid = None
continue continue

View File

@@ -636,7 +636,10 @@ def storeHashesToFile(attack_dict):
with openFile(filename, "w+") as f: with openFile(filename, "w+") as f:
for item in items: for item in items:
try:
f.write(item) f.write(item)
except (UnicodeError, TypeError):
pass
def attackCachedUsersPasswords(): def attackCachedUsersPasswords():
if kb.data.cachedUsersPasswords: if kb.data.cachedUsersPasswords:

View File

@@ -51,7 +51,7 @@ class Takeover(GenericTakeover):
banVer = kb.bannerFp["dbmsVersion"] banVer = kb.bannerFp["dbmsVersion"]
if not banVer: if not banVer or not banVer[0].isdigit():
errMsg = "unsupported feature on unknown version of PostgreSQL" errMsg = "unsupported feature on unknown version of PostgreSQL"
raise SqlmapUnsupportedFeatureException(errMsg) raise SqlmapUnsupportedFeatureException(errMsg)
elif distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("10"): elif distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("10"):

View File

@@ -363,14 +363,18 @@ class Databases(object):
singleTimeLogMessage(infoMsg) singleTimeLogMessage(infoMsg)
continue continue
for _query, _count in ((rootQuery.blind.query, rootQuery.blind.count), (getattr(rootQuery.blind, "query2", None), getattr(rootQuery.blind, "count2", None))):
if _query is None:
break
infoMsg = "fetching number of tables for " infoMsg = "fetching number of tables for "
infoMsg += "database '%s'" % unsafeSQLIdentificatorNaming(db) infoMsg += "database '%s'" % unsafeSQLIdentificatorNaming(db)
logger.info(infoMsg) logger.info(infoMsg)
if Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.FIREBIRD, DBMS.MAXDB, DBMS.ACCESS, DBMS.MCKOI, DBMS.EXTREMEDB): if Backend.getIdentifiedDbms() not in (DBMS.SQLITE, DBMS.FIREBIRD, DBMS.MAXDB, DBMS.ACCESS, DBMS.MCKOI, DBMS.EXTREMEDB):
query = rootQuery.blind.count query = _count % unsafeSQLIdentificatorNaming(db)
else: else:
query = rootQuery.blind.count % unsafeSQLIdentificatorNaming(db) query = _count
count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
@@ -378,12 +382,12 @@ class Databases(object):
warnMsg = "database '%s' " % unsafeSQLIdentificatorNaming(db) warnMsg = "database '%s' " % unsafeSQLIdentificatorNaming(db)
warnMsg += "appears to be empty" warnMsg += "appears to be empty"
logger.warn(warnMsg) logger.warn(warnMsg)
continue break
elif not isNumPosStrValue(count): elif not isNumPosStrValue(count):
warnMsg = "unable to retrieve the number of " warnMsg = "unable to retrieve the number of "
warnMsg += "tables for database '%s'" % unsafeSQLIdentificatorNaming(db) warnMsg += "tables for database '%s'" % unsafeSQLIdentificatorNaming(db)
logger.warn(warnMsg) singleTimeWarnMessage(warnMsg)
continue continue
tables = [] tables = []
@@ -393,15 +397,15 @@ class Databases(object):
for index in indexRange: for index in indexRange:
if Backend.isDbms(DBMS.SYBASE): if Backend.isDbms(DBMS.SYBASE):
query = rootQuery.blind.query % (db, (kb.data.cachedTables[-1] if kb.data.cachedTables else " ")) query = _query % (db, (kb.data.cachedTables[-1] if kb.data.cachedTables else " "))
elif Backend.getIdentifiedDbms() in (DBMS.MAXDB, DBMS.ACCESS, DBMS.MCKOI, DBMS.EXTREMEDB): elif Backend.getIdentifiedDbms() in (DBMS.MAXDB, DBMS.ACCESS, DBMS.MCKOI, DBMS.EXTREMEDB):
query = rootQuery.blind.query % (kb.data.cachedTables[-1] if kb.data.cachedTables else " ") query = _query % (kb.data.cachedTables[-1] if kb.data.cachedTables else " ")
elif Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.FIREBIRD): elif Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.FIREBIRD):
query = rootQuery.blind.query % index query = _query % index
elif Backend.getIdentifiedDbms() in (DBMS.HSQLDB, DBMS.INFORMIX, DBMS.FRONTBASE, DBMS.VIRTUOSO): elif Backend.getIdentifiedDbms() in (DBMS.HSQLDB, DBMS.INFORMIX, DBMS.FRONTBASE, DBMS.VIRTUOSO):
query = rootQuery.blind.query % (index, unsafeSQLIdentificatorNaming(db)) query = _query % (index, unsafeSQLIdentificatorNaming(db))
else: else:
query = rootQuery.blind.query % (unsafeSQLIdentificatorNaming(db), index) query = _query % (unsafeSQLIdentificatorNaming(db), index)
table = unArrayizeValue(inject.getValue(query, union=False, error=False)) table = unArrayizeValue(inject.getValue(query, union=False, error=False))
@@ -410,7 +414,11 @@ class Databases(object):
table = safeSQLIdentificatorNaming(table, True) table = safeSQLIdentificatorNaming(table, True)
tables.append(table) tables.append(table)
if tables:
kb.data.cachedTables[db] = tables
if conf.getComments: if conf.getComments:
for table in tables:
_ = queries[Backend.getIdentifiedDbms()].table_comment _ = queries[Backend.getIdentifiedDbms()].table_comment
if hasattr(_, "query"): if hasattr(_, "query"):
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.DERBY, DBMS.ALTIBASE): if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.DERBY, DBMS.ALTIBASE):
@@ -429,8 +437,7 @@ class Databases(object):
warnMsg += "possible to get table comments" warnMsg += "possible to get table comments"
singleTimeWarnMessage(warnMsg) singleTimeWarnMessage(warnMsg)
if tables: break
kb.data.cachedTables[db] = tables
else: else:
warnMsg = "unable to retrieve the table names " warnMsg = "unable to retrieve the table names "
warnMsg += "for database '%s'" % unsafeSQLIdentificatorNaming(db) warnMsg += "for database '%s'" % unsafeSQLIdentificatorNaming(db)