|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +$Id$ |
| 5 | +
|
| 6 | +Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/) |
| 7 | +See the file 'doc/COPYING' for copying permission |
| 8 | +""" |
| 9 | + |
| 10 | +import time |
| 11 | + |
| 12 | +from lib.core.agent import agent |
| 13 | +from lib.core.common import dataToStdout |
| 14 | +from lib.core.common import getConsoleWidth |
| 15 | +from lib.core.common import getFileItems |
| 16 | +from lib.core.common import popValue |
| 17 | +from lib.core.common import pushValue |
| 18 | +from lib.core.common import randomInt |
| 19 | +from lib.core.common import safeStringFormat |
| 20 | +from lib.core.data import conf |
| 21 | +from lib.core.data import logger |
| 22 | +from lib.request.connect import Connect as Request |
| 23 | + |
| 24 | +def tableExists(tableFile): |
| 25 | + tables = getFileItems(tableFile, None) |
| 26 | + retVal = [] |
| 27 | + infoMsg = "checking tables existence using items from '%s'" % tableFile |
| 28 | + logger.info(infoMsg) |
| 29 | + |
| 30 | + pushValue(conf.verbose) |
| 31 | + conf.verbose = 0 |
| 32 | + count = 0 |
| 33 | + length = len(tables) |
| 34 | + |
| 35 | + for table in tables: |
| 36 | + query = agent.prefixQuery("%s" % safeStringFormat("AND EXISTS(SELECT %d FROM %s)", (randomInt(1), table))) |
| 37 | + query = agent.postfixQuery(query) |
| 38 | + result = Request.queryPage(agent.payload(newValue=query)) |
| 39 | + |
| 40 | + if result: |
| 41 | + infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), table) |
| 42 | + infoMsg = "%s%s\n" % (infoMsg, " "*(getConsoleWidth()-1-len(infoMsg))) |
| 43 | + dataToStdout(infoMsg, True) |
| 44 | + retVal.append(table) |
| 45 | + |
| 46 | + count += 1 |
| 47 | + status = '%d/%d items (%d%s)' % (count, length, round(100.0*count/length), '%') |
| 48 | + dataToStdout("\r[%s] [INFO] tried: %s" % (time.strftime("%X"), status), True) |
| 49 | + |
| 50 | + conf.verbose = popValue() |
| 51 | + |
| 52 | + dataToStdout("\n", True) |
| 53 | + |
| 54 | + if not retVal: |
| 55 | + warnMsg = "no table found" |
| 56 | + logger.warn(warnMsg) |
| 57 | + |
| 58 | + return retVal |
| 59 | + |
| 60 | +def columnExists(table, columnFile): |
| 61 | + tables = getFileItems(columnFile, None) |
| 62 | + retVal = [] |
| 63 | + infoMsg = "checking column existence for table '%s' using items from '%s'" % (table, columnFile) |
| 64 | + logger.info(infoMsg) |
| 65 | + |
| 66 | + pushValue(conf.verbose) |
| 67 | + conf.verbose = 0 |
| 68 | + count = 0 |
| 69 | + length = len(tables) |
| 70 | + |
| 71 | + for column in columns: |
| 72 | + query = agent.prefixQuery("%s" % safeStringFormat("AND EXISTS(SELECT %s FROM %s)", (column, table))) |
| 73 | + query = agent.postfixQuery(query) |
| 74 | + result = Request.queryPage(agent.payload(newValue=query)) |
| 75 | + |
| 76 | + if result: |
| 77 | + infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), column) |
| 78 | + infoMsg = "%s%s\n" % (infoMsg, " "*(getConsoleWidth()-1-len(infoMsg))) |
| 79 | + dataToStdout(infoMsg, True) |
| 80 | + retVal.append(column) |
| 81 | + |
| 82 | + count += 1 |
| 83 | + status = '%d/%d items (%d%s)' % (count, length, round(100.0*count/length), '%') |
| 84 | + dataToStdout("\r[%s] [INFO] tried: %s" % (time.strftime("%X"), status), True) |
| 85 | + |
| 86 | + conf.verbose = popValue() |
| 87 | + |
| 88 | + dataToStdout("\n", True) |
| 89 | + |
| 90 | + if not retVal: |
| 91 | + warnMsg = "no column found" |
| 92 | + logger.warn(warnMsg) |
| 93 | + |
| 94 | + return retVal |
0 commit comments