Returns content of SQL snippet located inside 'procs/' directory >>> 'RECONFIGURE' in getSQLSnippet(DBMS.MSSQL, "activate_sp_oacreate") True
(dbms, sfile, **variables)
| 2421 | raise SqlmapInstallationException(errMsg) |
| 2422 | |
| 2423 | def 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 | |
| 2468 | def readCachedFileContent(filename, mode="rb"): |
| 2469 | """ |
no test coverage detected
searching dependent graphs…