(self)
| 97 | return kb.data.currentDb |
| 98 | |
| 99 | def getDbs(self): |
| 100 | if len(kb.data.cachedDbs) > 0: |
| 101 | return kb.data.cachedDbs |
| 102 | |
| 103 | infoMsg = None |
| 104 | |
| 105 | if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema: |
| 106 | warnMsg = "information_schema not available, " |
| 107 | warnMsg += "back-end DBMS is MySQL < 5. database " |
| 108 | warnMsg += "names will be fetched from 'mysql' database" |
| 109 | logger.warning(warnMsg) |
| 110 | |
| 111 | elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.PGSQL, DBMS.MONETDB, DBMS.DERBY, DBMS.VERTICA, DBMS.PRESTO, DBMS.MIMERSQL, DBMS.CRATEDB, DBMS.CACHE, DBMS.FRONTBASE): |
| 112 | warnMsg = "schema names are going to be used on %s " % Backend.getIdentifiedDbms() |
| 113 | warnMsg += "for enumeration as the counterpart to database " |
| 114 | warnMsg += "names on other DBMSes" |
| 115 | logger.warning(warnMsg) |
| 116 | |
| 117 | infoMsg = "fetching database (schema) names" |
| 118 | |
| 119 | elif Backend.getIdentifiedDbms() in (DBMS.ALTIBASE, DBMS.CUBRID): |
| 120 | warnMsg = "user names are going to be used on %s " % Backend.getIdentifiedDbms() |
| 121 | warnMsg += "for enumeration as the counterpart to database " |
| 122 | warnMsg += "names on other DBMSes" |
| 123 | logger.warning(warnMsg) |
| 124 | |
| 125 | infoMsg = "fetching database (user) names" |
| 126 | |
| 127 | else: |
| 128 | infoMsg = "fetching database names" |
| 129 | |
| 130 | if infoMsg: |
| 131 | logger.info(infoMsg) |
| 132 | |
| 133 | rootQuery = queries[Backend.getIdentifiedDbms()].dbs |
| 134 | |
| 135 | if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR, PAYLOAD.TECHNIQUE.QUERY)) or conf.direct: |
| 136 | if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema: |
| 137 | query = rootQuery.inband.query2 |
| 138 | else: |
| 139 | query = rootQuery.inband.query |
| 140 | values = inject.getValue(query, blind=False, time=False) |
| 141 | |
| 142 | if not isNoneValue(values): |
| 143 | kb.data.cachedDbs = arrayizeValue(values) |
| 144 | |
| 145 | if not kb.data.cachedDbs and isInferenceAvailable() and not conf.direct: |
| 146 | infoMsg = "fetching number of databases" |
| 147 | logger.info(infoMsg) |
| 148 | |
| 149 | if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema: |
| 150 | query = rootQuery.blind.count2 |
| 151 | else: |
| 152 | query = rootQuery.blind.count |
| 153 | count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) |
| 154 | |
| 155 | if not isNumPosStrValue(count): |
| 156 | errMsg = "unable to retrieve the number of databases" |
no test coverage detected