|
23 | 23 | """ |
24 | 24 |
|
25 | 25 | import re |
| 26 | +import time |
26 | 27 |
|
27 | 28 | from lib.core.agent import agent |
| 29 | +from lib.core.common import dataToStdout |
28 | 30 | from lib.core.common import getRange |
29 | 31 | from lib.core.common import getCompiledRegex |
| 32 | +from lib.core.common import getConsoleWidth |
| 33 | +from lib.core.common import getFileItems |
30 | 34 | from lib.core.common import getUnicode |
31 | 35 | from lib.core.common import parsePasswordHash |
| 36 | +from lib.core.common import popValue |
| 37 | +from lib.core.common import pushValue |
32 | 38 | from lib.core.common import readInput |
33 | 39 | from lib.core.common import safeStringFormat |
34 | 40 | from lib.core.convert import urlencode |
|
47 | 53 | from lib.core.unescaper import unescaper |
48 | 54 | from lib.parse.banner import bannerParser |
49 | 55 | from lib.request import inject |
| 56 | +from lib.request.connect import Connect as Request |
50 | 57 | from lib.techniques.inband.union.test import unionTest |
51 | 58 | from lib.techniques.outband.stacked import stackedTest |
52 | 59 |
|
@@ -801,6 +808,41 @@ def getTables(self): |
801 | 808 |
|
802 | 809 | return kb.data.cachedTables |
803 | 810 |
|
| 811 | + def tableExists(self, tableFile): |
| 812 | + tables = getFileItems(tableFile) |
| 813 | + retVal = [] |
| 814 | + infoMsg = "checking tables existence using items from '%s'" % tableFile |
| 815 | + logger.info(infoMsg) |
| 816 | + |
| 817 | + pushValue(conf.verbose) |
| 818 | + conf.verbose = 0 |
| 819 | + count = 0 |
| 820 | + length = len(tables) |
| 821 | + |
| 822 | + for table in tables: |
| 823 | + query = agent.prefixQuery(" %s" % safeStringFormat("AND EXISTS(SELECT 1 FROM %s)", table)) |
| 824 | + query = agent.postfixQuery(query) |
| 825 | + result = Request.queryPage(urlencode(agent.payload(newValue=query))) |
| 826 | + |
| 827 | + if result: |
| 828 | + infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), table) |
| 829 | + infoMsg = "%s%s\n" % (infoMsg, " "*(getConsoleWidth()-1-len(infoMsg))) |
| 830 | + dataToStdout(infoMsg, True) |
| 831 | + retVal.append(table) |
| 832 | + |
| 833 | + count += 1 |
| 834 | + status = '%d/%d (%d%s)' % (count, length, round(100.0*count/length), '%') |
| 835 | + dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%X"), status), True) |
| 836 | + |
| 837 | + conf.verbose = popValue() |
| 838 | + |
| 839 | + dataToStdout("\r%s\n" % (" "*(getConsoleWidth()-1)), True) |
| 840 | + if not retVal: |
| 841 | + warnMsg = "no table found" |
| 842 | + logger.warn(warnMsg) |
| 843 | + |
| 844 | + return retVal |
| 845 | + |
804 | 846 | def getColumns(self, onlyColNames=False): |
805 | 847 | if kb.dbms == "MySQL" and not kb.data.has_information_schema: |
806 | 848 | errMsg = "information_schema not available, " |
|
0 commit comments