If the user provided an asterisk rather than the column(s) name, sqlmap will retrieve the columns itself and reprocess the SQL query string (expression)
(expression)
| 1832 | return retVal |
| 1833 | |
| 1834 | def expandAsteriskForColumns(expression): |
| 1835 | """ |
| 1836 | If the user provided an asterisk rather than the column(s) |
| 1837 | name, sqlmap will retrieve the columns itself and reprocess |
| 1838 | the SQL query string (expression) |
| 1839 | """ |
| 1840 | |
| 1841 | match = re.search(r"(?i)\ASELECT(\s+TOP\s+[\d]+)?\s+\*\s+FROM\s+(([`'\"][^`'\"]+[`'\"]|[\w.]+)+)(\s|\Z)", expression) |
| 1842 | |
| 1843 | if match: |
| 1844 | infoMsg = "you did not provide the fields in your query. " |
| 1845 | infoMsg += "sqlmap will retrieve the column names itself" |
| 1846 | logger.info(infoMsg) |
| 1847 | |
| 1848 | _ = match.group(2).replace("..", '.').replace(".dbo.", '.') |
| 1849 | db, conf.tbl = _.split('.', 1) if '.' in _ else (None, _) |
| 1850 | |
| 1851 | if db is None: |
| 1852 | if expression != conf.sqlQuery: |
| 1853 | conf.db = db |
| 1854 | elif conf.db: |
| 1855 | expression = re.sub(r"([^\w])%s" % re.escape(conf.tbl), r"\g<1>%s.%s" % (conf.db, conf.tbl), expression) |
| 1856 | else: |
| 1857 | conf.db = db |
| 1858 | |
| 1859 | conf.db = safeSQLIdentificatorNaming(conf.db) |
| 1860 | conf.tbl = safeSQLIdentificatorNaming(conf.tbl, True) |
| 1861 | |
| 1862 | columnsDict = conf.dbmsHandler.getColumns(onlyColNames=True) |
| 1863 | |
| 1864 | if columnsDict and conf.db in columnsDict and conf.tbl in columnsDict[conf.db]: |
| 1865 | columns = list(columnsDict[conf.db][conf.tbl].keys()) |
| 1866 | columns.sort() |
| 1867 | columnsStr = ", ".join(column for column in columns) |
| 1868 | expression = expression.replace('*', columnsStr, 1) |
| 1869 | |
| 1870 | infoMsg = "the query with expanded column name(s) is: " |
| 1871 | infoMsg += "%s" % expression |
| 1872 | logger.info(infoMsg) |
| 1873 | |
| 1874 | return expression |
| 1875 | |
| 1876 | def getLimitRange(count, plusOne=False): |
| 1877 | """ |
no test coverage detected
searching dependent graphs…