1、任意代码执行
任意代码执行需关注的函数,可使用正则搜索:
eval\(|exec\(|execfile\(|compile\(
需关注的危险库文件及函数有:
os.system/popentimeit.timeitplatform.popencommands.getstatusoutputsubprocess.popen/call/check_output__import__("os").system("ls")importlib.import_module('os').system('ls')
其中subprocess较为常见,防御办法需保证shell=True未设置 转义变量:Python 2.x使用pipes.quote(),Python 3.3或更高版本使用shlex.quote();错误示例代码:
subprocess.Popen('ls',shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read()importsubprocessdef transcode_file():filename = raw_input('Please provide the path for the file totranscode: ')command = 'ffmpeg -i "{source}"output_file.mpg'.format(source=filename)subprocess.call(command, shell=True)
除此之外需还关注模板注入(SSTI),全局搜