(dbms, sfile, **variables)
return retVal
Returns content of SQL snippet located inside 'procs/' directory
Returns content of SQL snippet located inside 'procs/' directory
Returns content of SQL snippet located inside procs / directory
def getSQLSnippet(dbms, sfile, **variables):
    """
    Returns content of SQL snippet located inside 'procs/' directory
    """

    if sfile.endswith('.sql') and os.path.exists(sfile):
        filename = sfile
    elif not sfile.endswith('.sql') and os.path.exists("%s.sql" % sfile):
        filename = "%s.sql" % sfile
    else:
        filename = os.path.join(paths.SQLMAP_PROCS_PATH, DBMS_DIRECTORY_DICT[dbms], sfile if sfile.endswith('.sql') else "%s.sql" % sfile)
        checkFile(filename)

    retVal = readCachedFileContent(filename)
    retVal = re.sub(r"#.+", "", retVal)
    retVal = re.sub(r"(?s);\s+", "; ", retVal).strip("\r\n")

    for _ in variables.keys():
        retVal = re.sub(r"%%%s%%" % _, variables[_], retVal)

    for _ in re.findall(r"%RANDSTR\d+%", retVal, re.I):
        retVal = retVal.replace(_, randomStr())

    for _ in re.findall(r"%RANDINT\d+%", retVal, re.I):
        retVal = retVal.replace(_, randomInt())

    variables = re.findall(r"(?<!\bLIKE ')%(\w+)%", retVal, re.I)

    if variables:
        errMsg = "unresolved variable%s '%s' in SQL file '%s'" % ("s" if len(variables) > 1 else "", ", ".join(variables), sfile)
        logger.error(errMsg)

        msg = "do you want to provide the substitution values? [y/N] "
        choice = readInput(msg, default="N")

        if choice and choice[0].lower() == "y":
            for var in variables:
                msg = "insert value for variable '%s': " % var
                val = readInput(msg, default="")
                retVal = retVal.replace(r"%%%s%%" % var, val)

    return retVal
def getSQLSnippet ( dbms , sfile , * * variables ) : if sfile . endswith ( '.sql' ) and os . path . exists ( sfile ) : filename = sfile elif not sfile . endswith ( '.sql' ) and os . path . exists ( "%s.sql" % sfile ) : filename = "%s.sql" % sfile else : filename = os . path . join ( paths . SQLMAP_PROCS_PATH , DBMS_DIRECTORY_DICT [ dbms ] , sfile if sfile . endswith ( '.sql' ) else "%s.sql" % sfile ) checkFile ( filename ) retVal = readCachedFileContent ( filename ) retVal = re . sub ( r"#.+" , "" , retVal ) retVal = re . sub ( r"(?s);\s+" , "; " , retVal ) . strip ( "\r\n" ) for _ in variables . keys ( ) : retVal = re . sub ( r"%%%s%%" % _ , variables [ _ ] , retVal ) for _ in re . findall ( r"%RANDSTR\d+%" , retVal , re . I ) : retVal = retVal . replace ( _ , randomStr ( ) ) for _ in re . findall ( r"%RANDINT\d+%" , retVal , re . I ) : retVal = retVal . replace ( _ , randomInt ( ) ) variables = re . findall ( r"(?<!\bLIKE ')%(\w+)%" , retVal , re . I ) if variables : errMsg = "unresolved variable%s '%s' in SQL file '%s'" % ( "s" if len ( variables ) > 1 else "" , ", " . join ( variables ) , sfile ) logger . error ( errMsg ) msg = "do you want to provide the substitution values? [y/N] " choice = readInput ( msg , default = "N" ) if choice and choice [ 0 ] . lower ( ) == "y" : for var in variables : msg = "insert value for variable '%s': " % var val = readInput ( msg , default = "" ) retVal = retVal . replace ( r"%%%s%%" % var , val ) return retVal