2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2010-11-09 12:42:43 +03:00
|
|
|
|
|
|
|
"""
|
2019-01-05 23:38:52 +03:00
|
|
|
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-11-09 12:42:43 +03:00
|
|
|
"""
|
|
|
|
|
2019-06-04 13:15:39 +03:00
|
|
|
from __future__ import division
|
|
|
|
|
2019-06-27 18:28:43 +03:00
|
|
|
import logging
|
2010-11-09 12:42:43 +03:00
|
|
|
import time
|
|
|
|
|
2019-06-04 15:44:06 +03:00
|
|
|
from lib.core.common import Backend
|
2010-11-24 00:00:42 +03:00
|
|
|
from lib.core.common import clearConsoleLine
|
2010-11-09 12:42:43 +03:00
|
|
|
from lib.core.common import dataToStdout
|
2010-12-27 02:50:16 +03:00
|
|
|
from lib.core.common import filterListValue
|
2010-11-09 12:42:43 +03:00
|
|
|
from lib.core.common import getFileItems
|
2011-06-18 19:47:19 +04:00
|
|
|
from lib.core.common import getPageWordSet
|
2012-02-24 17:07:20 +04:00
|
|
|
from lib.core.common import hashDBWrite
|
2019-06-27 18:28:43 +03:00
|
|
|
from lib.core.common import isNoneValue
|
2019-06-28 14:56:48 +03:00
|
|
|
from lib.core.common import ntToPosixSlashes
|
2019-06-27 18:28:43 +03:00
|
|
|
from lib.core.common import popValue
|
|
|
|
from lib.core.common import pushValue
|
2010-11-09 12:42:43 +03:00
|
|
|
from lib.core.common import randomInt
|
2011-07-04 23:58:41 +04:00
|
|
|
from lib.core.common import randomStr
|
2014-05-13 02:50:36 +04:00
|
|
|
from lib.core.common import readInput
|
2011-03-30 01:54:15 +04:00
|
|
|
from lib.core.common import safeSQLIdentificatorNaming
|
2019-06-04 15:44:06 +03:00
|
|
|
from lib.core.common import safeStringFormat
|
2019-06-27 18:28:43 +03:00
|
|
|
from lib.core.common import unArrayizeValue
|
2013-02-15 17:48:24 +04:00
|
|
|
from lib.core.common import unsafeSQLIdentificatorNaming
|
2010-11-09 12:42:43 +03:00
|
|
|
from lib.core.data import conf
|
2010-11-11 23:37:25 +03:00
|
|
|
from lib.core.data import kb
|
2010-11-09 12:42:43 +03:00
|
|
|
from lib.core.data import logger
|
2019-06-27 18:28:43 +03:00
|
|
|
from lib.core.decorators import stackedmethod
|
2010-12-26 14:15:02 +03:00
|
|
|
from lib.core.enums import DBMS
|
2011-12-28 17:50:03 +04:00
|
|
|
from lib.core.enums import HASHDB_KEYS
|
2014-05-13 02:50:36 +04:00
|
|
|
from lib.core.enums import PAYLOAD
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapDataException
|
|
|
|
from lib.core.exception import SqlmapMissingMandatoryOptionException
|
2019-06-27 18:28:43 +03:00
|
|
|
from lib.core.exception import SqlmapNoneDataException
|
2011-07-04 23:58:41 +04:00
|
|
|
from lib.core.settings import BRUTE_COLUMN_EXISTS_TEMPLATE
|
|
|
|
from lib.core.settings import BRUTE_TABLE_EXISTS_TEMPLATE
|
2015-09-22 12:28:56 +03:00
|
|
|
from lib.core.settings import METADB_SUFFIX
|
2011-06-07 13:50:00 +04:00
|
|
|
from lib.core.threads import getCurrentThreadData
|
|
|
|
from lib.core.threads import runThreads
|
2010-12-09 01:14:42 +03:00
|
|
|
from lib.request import inject
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _addPageTextWords():
|
2011-06-18 16:30:26 +04:00
|
|
|
wordsList = []
|
2011-02-08 03:02:54 +03:00
|
|
|
|
2010-12-26 12:40:40 +03:00
|
|
|
infoMsg = "adding words used on web page to the check list"
|
2010-12-25 12:37:33 +03:00
|
|
|
logger.info(infoMsg)
|
2011-06-18 19:47:19 +04:00
|
|
|
pageWords = getPageWordSet(kb.originalPage)
|
2011-01-07 19:36:32 +03:00
|
|
|
|
2010-12-25 12:37:33 +03:00
|
|
|
for word in pageWords:
|
2010-12-25 13:42:36 +03:00
|
|
|
word = word.lower()
|
2011-01-07 19:36:32 +03:00
|
|
|
|
2011-06-18 16:30:26 +04:00
|
|
|
if len(word) > 2 and not word[0].isdigit() and word not in wordsList:
|
|
|
|
wordsList.append(word)
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2011-06-18 16:30:26 +04:00
|
|
|
return wordsList
|
|
|
|
|
2019-08-13 13:23:45 +03:00
|
|
|
@stackedmethod
|
2011-06-18 16:30:26 +04:00
|
|
|
def tableExists(tableFile, regex=None):
|
2014-08-21 02:12:19 +04:00
|
|
|
if kb.tableExistsChoice is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
|
2014-05-13 02:50:36 +04:00
|
|
|
warnMsg = "it's not recommended to use '%s' and/or '%s' " % (PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.TIME], PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.STACKED])
|
|
|
|
warnMsg += "for common table existence check"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
message = "are you sure you want to continue? [y/N] "
|
2017-04-18 16:48:05 +03:00
|
|
|
kb.tableExistsChoice = readInput(message, default='N', boolean=True)
|
2014-05-13 02:50:36 +04:00
|
|
|
|
|
|
|
if not kb.tableExistsChoice:
|
|
|
|
return None
|
|
|
|
|
2011-07-04 23:58:41 +04:00
|
|
|
result = inject.checkBooleanExpression("%s" % safeStringFormat(BRUTE_TABLE_EXISTS_TEMPLATE, (randomInt(1), randomStr())))
|
2013-01-23 19:52:03 +04:00
|
|
|
|
2011-07-04 23:58:41 +04:00
|
|
|
if result:
|
|
|
|
errMsg = "can't use table existence check because of detected invalid results "
|
2017-02-28 00:14:52 +03:00
|
|
|
errMsg += "(most likely caused by inability of the used injection "
|
2017-02-28 00:03:15 +03:00
|
|
|
errMsg += "to distinguish erroneous results)"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapDataException(errMsg)
|
2011-07-04 23:58:41 +04:00
|
|
|
|
2019-08-13 13:23:45 +03:00
|
|
|
pushValue(conf.db)
|
|
|
|
|
|
|
|
if conf.db and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
|
|
|
|
conf.db = conf.db.upper()
|
|
|
|
|
2017-04-19 14:56:29 +03:00
|
|
|
message = "which common tables (wordlist) file do you want to use?\n"
|
|
|
|
message += "[1] default '%s' (press Enter)\n" % tableFile
|
|
|
|
message += "[2] custom"
|
|
|
|
choice = readInput(message, default='1')
|
|
|
|
|
|
|
|
if choice == '2':
|
|
|
|
message = "what's the custom common tables file location?\n"
|
|
|
|
tableFile = readInput(message) or tableFile
|
2011-06-18 16:30:26 +04:00
|
|
|
|
2019-08-13 13:23:45 +03:00
|
|
|
infoMsg = "performing table existence using items from '%s'" % tableFile
|
2011-06-18 16:30:26 +04:00
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2017-04-19 14:56:29 +03:00
|
|
|
tables = getFileItems(tableFile, lowercase=Backend.getIdentifiedDbms() in (DBMS.ACCESS,), unique=True)
|
2012-12-06 17:14:19 +04:00
|
|
|
tables.extend(_addPageTextWords())
|
2010-12-27 02:50:16 +03:00
|
|
|
tables = filterListValue(tables, regex)
|
2011-06-07 14:08:12 +04:00
|
|
|
|
2019-08-13 13:23:45 +03:00
|
|
|
for conf.db in (conf.db.split(',') if conf.db else [conf.db]):
|
|
|
|
if conf.db:
|
|
|
|
infoMsg = "checking database '%s'" % conf.db
|
|
|
|
logger.info(infoMsg)
|
2010-12-21 13:31:56 +03:00
|
|
|
|
2011-06-07 14:08:12 +04:00
|
|
|
threadData = getCurrentThreadData()
|
2019-08-13 13:23:45 +03:00
|
|
|
threadData.shared.count = 0
|
|
|
|
threadData.shared.limit = len(tables)
|
|
|
|
threadData.shared.files = []
|
|
|
|
threadData.shared.unique = set()
|
|
|
|
|
|
|
|
def tableExistsThread():
|
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
|
|
|
while kb.threadContinue:
|
|
|
|
kb.locks.count.acquire()
|
|
|
|
if threadData.shared.count < threadData.shared.limit:
|
|
|
|
table = safeSQLIdentificatorNaming(tables[threadData.shared.count], True)
|
|
|
|
threadData.shared.count += 1
|
|
|
|
kb.locks.count.release()
|
|
|
|
else:
|
|
|
|
kb.locks.count.release()
|
|
|
|
break
|
|
|
|
|
|
|
|
if conf.db and METADB_SUFFIX not in conf.db and Backend.getIdentifiedDbms() not in (DBMS.SQLITE, DBMS.ACCESS, DBMS.FIREBIRD):
|
|
|
|
fullTableName = "%s.%s" % (conf.db, table)
|
|
|
|
else:
|
|
|
|
fullTableName = table
|
|
|
|
|
|
|
|
result = inject.checkBooleanExpression("%s" % safeStringFormat(BRUTE_TABLE_EXISTS_TEMPLATE, (randomInt(1), fullTableName)))
|
|
|
|
|
|
|
|
kb.locks.io.acquire()
|
|
|
|
|
|
|
|
if result and table.lower() not in threadData.shared.unique:
|
|
|
|
threadData.shared.files.append(table)
|
|
|
|
threadData.shared.unique.add(table.lower())
|
|
|
|
|
|
|
|
if conf.verbose in (1, 2) and not conf.api:
|
|
|
|
clearConsoleLine(True)
|
|
|
|
infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), unsafeSQLIdentificatorNaming(table))
|
|
|
|
dataToStdout(infoMsg, True)
|
|
|
|
|
|
|
|
if conf.verbose in (1, 2):
|
|
|
|
status = '%d/%d items (%d%%)' % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit))
|
|
|
|
dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True)
|
|
|
|
|
|
|
|
kb.locks.io.release()
|
|
|
|
|
|
|
|
try:
|
|
|
|
runThreads(conf.threads, tableExistsThread, threadChoice=True)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
warnMsg = "user aborted during table existence "
|
|
|
|
warnMsg += "check. sqlmap will display partial output"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
clearConsoleLine(True)
|
|
|
|
dataToStdout("\n")
|
|
|
|
|
|
|
|
if not threadData.shared.files:
|
|
|
|
warnMsg = "no table(s) found"
|
|
|
|
if conf.db:
|
2019-10-17 12:53:53 +03:00
|
|
|
warnMsg += " for database '%s'" % conf.db
|
2019-08-13 13:23:45 +03:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
else:
|
|
|
|
for item in threadData.shared.files:
|
|
|
|
if conf.db not in kb.data.cachedTables:
|
|
|
|
kb.data.cachedTables[conf.db] = [item]
|
|
|
|
else:
|
|
|
|
kb.data.cachedTables[conf.db].append(item)
|
|
|
|
|
|
|
|
for _ in ((conf.db, item) for item in threadData.shared.files):
|
|
|
|
if _ not in kb.brute.tables:
|
|
|
|
kb.brute.tables.append(_)
|
|
|
|
|
|
|
|
conf.db = popValue()
|
2012-02-24 17:07:20 +04:00
|
|
|
hashDBWrite(HASHDB_KEYS.KB_BRUTE_TABLES, kb.brute.tables, True)
|
2011-12-28 17:50:03 +04:00
|
|
|
|
2010-11-11 23:37:25 +03:00
|
|
|
return kb.data.cachedTables
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2010-12-27 02:50:16 +03:00
|
|
|
def columnExists(columnFile, regex=None):
|
2014-08-21 02:12:19 +04:00
|
|
|
if kb.columnExistsChoice is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
|
2014-05-13 02:50:36 +04:00
|
|
|
warnMsg = "it's not recommended to use '%s' and/or '%s' " % (PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.TIME], PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.STACKED])
|
|
|
|
warnMsg += "for common column existence check"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
message = "are you sure you want to continue? [y/N] "
|
2017-04-18 16:48:05 +03:00
|
|
|
kb.columnExistsChoice = readInput(message, default='N', boolean=True)
|
2014-05-13 02:50:36 +04:00
|
|
|
|
|
|
|
if not kb.columnExistsChoice:
|
|
|
|
return None
|
|
|
|
|
2010-11-09 19:15:55 +03:00
|
|
|
if not conf.tbl:
|
|
|
|
errMsg = "missing table parameter"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2010-11-09 19:15:55 +03:00
|
|
|
|
2013-01-23 20:22:28 +04:00
|
|
|
if conf.db and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
|
|
|
|
conf.db = conf.db.upper()
|
|
|
|
|
2011-07-04 23:58:41 +04:00
|
|
|
result = inject.checkBooleanExpression(safeStringFormat(BRUTE_COLUMN_EXISTS_TEMPLATE, (randomStr(), randomStr())))
|
2013-01-23 20:22:28 +04:00
|
|
|
|
2011-07-04 23:58:41 +04:00
|
|
|
if result:
|
|
|
|
errMsg = "can't use column existence check because of detected invalid results "
|
2017-02-28 00:14:52 +03:00
|
|
|
errMsg += "(most likely caused by inability of the used injection "
|
2017-02-28 00:03:15 +03:00
|
|
|
errMsg += "to distinguish erroneous results)"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapDataException(errMsg)
|
2011-07-04 23:58:41 +04:00
|
|
|
|
2017-04-19 14:56:29 +03:00
|
|
|
message = "which common columns (wordlist) file do you want to use?\n"
|
|
|
|
message += "[1] default '%s' (press Enter)\n" % columnFile
|
|
|
|
message += "[2] custom"
|
|
|
|
choice = readInput(message, default='1')
|
|
|
|
|
|
|
|
if choice == '2':
|
|
|
|
message = "what's the custom common columns file location?\n"
|
|
|
|
columnFile = readInput(message) or columnFile
|
|
|
|
|
2011-06-18 16:30:26 +04:00
|
|
|
infoMsg = "checking column existence using items from '%s'" % columnFile
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2010-12-26 14:15:02 +03:00
|
|
|
columns = getFileItems(columnFile, unique=True)
|
2012-12-06 17:14:19 +04:00
|
|
|
columns.extend(_addPageTextWords())
|
2010-12-27 02:50:16 +03:00
|
|
|
columns = filterListValue(columns, regex)
|
|
|
|
|
2012-11-28 03:03:17 +04:00
|
|
|
table = safeSQLIdentificatorNaming(conf.tbl, True)
|
2013-01-23 19:52:03 +04:00
|
|
|
|
|
|
|
if conf.db and METADB_SUFFIX not in conf.db and Backend.getIdentifiedDbms() not in (DBMS.SQLITE, DBMS.ACCESS, DBMS.FIREBIRD):
|
2012-11-28 03:03:17 +04:00
|
|
|
table = "%s.%s" % (safeSQLIdentificatorNaming(conf.db), table)
|
2010-11-12 01:26:36 +03:00
|
|
|
|
2010-12-24 23:17:53 +03:00
|
|
|
kb.threadContinue = True
|
2011-04-08 15:02:21 +04:00
|
|
|
kb.bruteMode = True
|
2010-12-24 23:17:53 +03:00
|
|
|
|
2011-06-07 13:50:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
threadData.shared.count = 0
|
|
|
|
threadData.shared.limit = len(columns)
|
2019-07-18 15:59:42 +03:00
|
|
|
threadData.shared.files = []
|
2011-06-07 13:50:00 +04:00
|
|
|
|
2010-12-24 23:17:53 +03:00
|
|
|
def columnExistsThread():
|
2011-06-07 13:50:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
|
|
|
while kb.threadContinue:
|
2011-12-28 20:27:17 +04:00
|
|
|
kb.locks.count.acquire()
|
2011-06-07 13:50:00 +04:00
|
|
|
if threadData.shared.count < threadData.shared.limit:
|
|
|
|
column = safeSQLIdentificatorNaming(columns[threadData.shared.count])
|
|
|
|
threadData.shared.count += 1
|
2011-12-28 20:27:17 +04:00
|
|
|
kb.locks.count.release()
|
2011-06-07 13:50:00 +04:00
|
|
|
else:
|
2011-12-28 20:27:17 +04:00
|
|
|
kb.locks.count.release()
|
2011-06-07 13:50:00 +04:00
|
|
|
break
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2011-07-04 23:58:41 +04:00
|
|
|
result = inject.checkBooleanExpression(safeStringFormat(BRUTE_COLUMN_EXISTS_TEMPLATE, (column, table)))
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2011-12-28 20:27:17 +04:00
|
|
|
kb.locks.io.acquire()
|
2011-01-07 19:36:32 +03:00
|
|
|
|
2010-12-24 23:17:53 +03:00
|
|
|
if result:
|
2019-07-18 15:59:42 +03:00
|
|
|
threadData.shared.files.append(column)
|
2010-12-24 23:17:53 +03:00
|
|
|
|
2017-04-10 20:21:22 +03:00
|
|
|
if conf.verbose in (1, 2) and not conf.api:
|
2010-12-24 23:17:53 +03:00
|
|
|
clearConsoleLine(True)
|
2014-10-01 15:59:51 +04:00
|
|
|
infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), unsafeSQLIdentificatorNaming(column))
|
2010-12-24 23:17:53 +03:00
|
|
|
dataToStdout(infoMsg, True)
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2010-12-14 00:37:12 +03:00
|
|
|
if conf.verbose in (1, 2):
|
2014-10-01 15:59:51 +04:00
|
|
|
status = "%d/%d items (%d%%)" % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit))
|
2011-01-16 03:15:30 +03:00
|
|
|
dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True)
|
2011-01-07 19:36:32 +03:00
|
|
|
|
2011-12-28 20:27:17 +04:00
|
|
|
kb.locks.io.release()
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2010-12-24 23:17:53 +03:00
|
|
|
try:
|
2011-06-07 13:50:00 +04:00
|
|
|
runThreads(conf.threads, columnExistsThread, threadChoice=True)
|
2010-12-24 23:17:53 +03:00
|
|
|
except KeyboardInterrupt:
|
2011-06-07 13:50:00 +04:00
|
|
|
warnMsg = "user aborted during column existence "
|
|
|
|
warnMsg += "check. sqlmap will display partial output"
|
2011-03-31 18:26:14 +04:00
|
|
|
logger.warn(warnMsg)
|
2019-06-27 18:28:43 +03:00
|
|
|
finally:
|
|
|
|
kb.bruteMode = False
|
2011-03-31 18:26:14 +04:00
|
|
|
|
2010-11-24 00:00:42 +03:00
|
|
|
clearConsoleLine(True)
|
2011-01-16 03:15:30 +03:00
|
|
|
dataToStdout("\n")
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2019-07-18 15:59:42 +03:00
|
|
|
if not threadData.shared.files:
|
2011-05-31 03:04:49 +04:00
|
|
|
warnMsg = "no column(s) found"
|
2010-11-09 12:42:43 +03:00
|
|
|
logger.warn(warnMsg)
|
2010-11-11 23:37:25 +03:00
|
|
|
else:
|
|
|
|
columns = {}
|
2010-11-09 12:42:43 +03:00
|
|
|
|
2019-07-18 15:59:42 +03:00
|
|
|
for column in threadData.shared.files:
|
2013-05-16 17:12:36 +04:00
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL,):
|
2013-05-16 17:23:20 +04:00
|
|
|
result = not inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE %s REGEXP '[^0-9]')", (column, table, column)))
|
2019-11-28 02:02:08 +03:00
|
|
|
elif Backend.getIdentifiedDbms() in (DBMS.SQLITE,):
|
|
|
|
result = inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE %s NOT GLOB '*[^0-9]*')", (column, table, column)))
|
2013-05-16 17:12:36 +04:00
|
|
|
else:
|
|
|
|
result = inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE ROUND(%s)=ROUND(%s))", (column, table, column, column)))
|
2010-11-11 23:37:25 +03:00
|
|
|
|
|
|
|
if result:
|
2014-10-01 15:59:51 +04:00
|
|
|
columns[column] = "numeric"
|
2010-11-11 23:37:25 +03:00
|
|
|
else:
|
2014-10-01 15:59:51 +04:00
|
|
|
columns[column] = "non-numeric"
|
2010-11-11 23:37:25 +03:00
|
|
|
|
|
|
|
kb.data.cachedColumns[conf.db] = {conf.tbl: columns}
|
|
|
|
|
2017-11-10 15:03:24 +03:00
|
|
|
for _ in ((conf.db, conf.tbl, item[0], item[1]) for item in columns.items()):
|
2011-12-28 17:50:03 +04:00
|
|
|
if _ not in kb.brute.columns:
|
|
|
|
kb.brute.columns.append(_)
|
|
|
|
|
2012-02-24 17:07:20 +04:00
|
|
|
hashDBWrite(HASHDB_KEYS.KB_BRUTE_COLUMNS, kb.brute.columns, True)
|
2011-12-28 17:50:03 +04:00
|
|
|
|
2010-11-11 23:37:25 +03:00
|
|
|
return kb.data.cachedColumns
|
2019-06-27 18:28:43 +03:00
|
|
|
|
|
|
|
@stackedmethod
|
|
|
|
def fileExists(pathFile):
|
|
|
|
retVal = []
|
2019-06-28 14:56:48 +03:00
|
|
|
|
|
|
|
message = "which common files file do you want to use?\n"
|
|
|
|
message += "[1] default '%s' (press Enter)\n" % pathFile
|
|
|
|
message += "[2] custom"
|
|
|
|
choice = readInput(message, default='1')
|
|
|
|
|
|
|
|
if choice == '2':
|
|
|
|
message = "what's the custom common files file location?\n"
|
|
|
|
pathFile = readInput(message) or pathFile
|
|
|
|
|
|
|
|
infoMsg = "checking files existence using items from '%s'" % pathFile
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2019-06-27 18:28:43 +03:00
|
|
|
paths = getFileItems(pathFile, unique=True)
|
|
|
|
|
|
|
|
kb.bruteMode = True
|
|
|
|
|
|
|
|
try:
|
|
|
|
conf.dbmsHandler.readFile(randomStr())
|
|
|
|
except SqlmapNoneDataException:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
kb.bruteMode = False
|
|
|
|
raise
|
|
|
|
|
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
threadData.shared.count = 0
|
|
|
|
threadData.shared.limit = len(paths)
|
2019-07-18 15:59:42 +03:00
|
|
|
threadData.shared.files = []
|
2019-06-27 18:28:43 +03:00
|
|
|
|
|
|
|
def fileExistsThread():
|
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
|
|
|
while kb.threadContinue:
|
|
|
|
kb.locks.count.acquire()
|
|
|
|
if threadData.shared.count < threadData.shared.limit:
|
2019-06-28 14:56:48 +03:00
|
|
|
path = ntToPosixSlashes(paths[threadData.shared.count])
|
2019-06-27 18:28:43 +03:00
|
|
|
threadData.shared.count += 1
|
|
|
|
kb.locks.count.release()
|
|
|
|
else:
|
|
|
|
kb.locks.count.release()
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = unArrayizeValue(conf.dbmsHandler.readFile(path))
|
|
|
|
except SqlmapNoneDataException:
|
|
|
|
result = None
|
|
|
|
|
|
|
|
kb.locks.io.acquire()
|
|
|
|
|
|
|
|
if not isNoneValue(result):
|
2019-07-18 15:59:42 +03:00
|
|
|
threadData.shared.files.append(result)
|
2019-06-27 18:28:43 +03:00
|
|
|
|
2019-07-18 15:59:42 +03:00
|
|
|
if not conf.api:
|
2019-06-27 18:28:43 +03:00
|
|
|
clearConsoleLine(True)
|
|
|
|
infoMsg = "[%s] [INFO] retrieved: '%s'\n" % (time.strftime("%X"), path)
|
|
|
|
dataToStdout(infoMsg, True)
|
|
|
|
|
|
|
|
if conf.verbose in (1, 2):
|
|
|
|
status = '%d/%d items (%d%%)' % (threadData.shared.count, threadData.shared.limit, round(100.0 * threadData.shared.count / threadData.shared.limit))
|
|
|
|
dataToStdout("\r[%s] [INFO] tried %s" % (time.strftime("%X"), status), True)
|
|
|
|
|
|
|
|
kb.locks.io.release()
|
|
|
|
|
|
|
|
try:
|
|
|
|
pushValue(logger.getEffectiveLevel())
|
|
|
|
logger.setLevel(logging.CRITICAL)
|
|
|
|
|
|
|
|
runThreads(conf.threads, fileExistsThread, threadChoice=True)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
warnMsg = "user aborted during file existence "
|
|
|
|
warnMsg += "check. sqlmap will display partial output"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
finally:
|
|
|
|
kb.bruteMode = False
|
|
|
|
logger.setLevel(popValue())
|
|
|
|
|
|
|
|
clearConsoleLine(True)
|
|
|
|
dataToStdout("\n")
|
|
|
|
|
2019-07-18 15:59:42 +03:00
|
|
|
if not threadData.shared.files:
|
2019-06-27 18:28:43 +03:00
|
|
|
warnMsg = "no file(s) found"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
else:
|
2019-07-18 15:59:42 +03:00
|
|
|
retVal = threadData.shared.files
|
2019-06-27 18:28:43 +03:00
|
|
|
|
|
|
|
return retVal
|