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

Function getSQLSnippet

lib/core/common.py:2423–2466  ·  view source on GitHub ↗

Returns content of SQL snippet located inside 'procs/' directory >>> 'RECONFIGURE' in getSQLSnippet(DBMS.MSSQL, "activate_sp_oacreate") True

(dbms, sfile, **variables)

Source from the content-addressed store, hash-verified

2421 raise SqlmapInstallationException(errMsg)
2422
2423def getSQLSnippet(dbms, sfile, **variables):
2424 """
2425 Returns content of SQL snippet located inside 'procs/' directory
2426
2427 >>> 'RECONFIGURE' in getSQLSnippet(DBMS.MSSQL, "activate_sp_oacreate")
2428 True
2429 """
2430
2431 if sfile.endswith('.sql') and os.path.exists(sfile):
2432 filename = sfile
2433 elif not sfile.endswith('.sql') and os.path.exists("%s.sql" % sfile):
2434 filename = "%s.sql" % sfile
2435 else:
2436 filename = os.path.join(paths.SQLMAP_PROCS_PATH, DBMS_DIRECTORY_DICT[dbms], sfile if sfile.endswith('.sql') else "%s.sql" % sfile)
2437 checkFile(filename)
2438
2439 retVal = readCachedFileContent(filename)
2440 retVal = re.sub(r"#.+", "", retVal)
2441 retVal = re.sub(r";\s+", "; ", retVal).strip("\r\n")
2442
2443 for _ in variables:
2444 retVal = re.sub(r"%%%s%%" % _, variables[_].replace('\\', r'\\'), retVal)
2445
2446 for _ in re.findall(r"%RANDSTR\d+%", retVal, re.I):
2447 retVal = retVal.replace(_, randomStr())
2448
2449 for _ in re.findall(r"%RANDINT\d+%", retVal, re.I):
2450 retVal = retVal.replace(_, randomInt())
2451
2452 variables = re.findall(r"(?<!\bLIKE ')%(\w+)%", retVal, re.I)
2453
2454 if variables:
2455 errMsg = "unresolved variable%s '%s' in SQL file '%s'" % ("s" if len(variables) > 1 else "", ", ".join(variables), sfile)
2456 logger.error(errMsg)
2457
2458 msg = "do you want to provide the substitution values? [y/N] "
2459
2460 if readInput(msg, default='N', boolean=True):
2461 for var in variables:
2462 msg = "insert value for variable '%s': " % var
2463 val = readInput(msg, default="")
2464 retVal = retVal.replace(r"%%%s%%" % var, val)
2465
2466 return retVal
2467
2468def readCachedFileContent(filename, mode="rb"):
2469 """

Callers 10

runAsDBMSUserMethod · 0.90
_xpCmdshellCreateMethod · 0.90
_webFileInjectMethod · 0.90
_initRunAsMethod · 0.90
dnsUseFunction · 0.90
sqlFileMethod · 0.90
readFileMethod · 0.90

Calls 7

checkFileFunction · 0.85
readCachedFileContentFunction · 0.85
randomStrFunction · 0.85
randomIntFunction · 0.85
readInputFunction · 0.70
replaceMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…