MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / expandAsteriskForColumns

Function expandAsteriskForColumns

lib/core/common.py:1834–1874  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1832 return retVal
1833
1834def 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
1876def getLimitRange(count, plusOne=False):
1877 """

Callers 1

getValueFunction · 0.90

Calls 7

infoMethod · 0.80
searchMethod · 0.45
replaceMethod · 0.45
escapeMethod · 0.45
getColumnsMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…