SSTI 服务器端模板注入(Server-Side Template Injection)

本文介绍了Flask框架的基本运作流程,包括route装饰器的应用、render_template与render_template_string的使用,以及模板渲染引擎Jinja2的介绍。同时提到了Web安全中的模板注入问题及其在Flask中的潜在风险,关注了Tornado和Confusion1等相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.flask的运作流程(原理) 

from flask import flask 
@app.route('/index/')
def hello_word():
    return 'hello word'

route装饰器的作用是将函数与url绑定起来。例子中的代码的作用就是当你访问http://127.0.0.1:5000/index 的时候,flask会返回hello word。

2.渲染方法

flask的渲染方法有render_template和render_template_string两种。

render_template()是用来渲染一个指定的文件的。使用如下

return render_template('index.html')

render_template_string则是用来渲染一个字符串的。SSTI与这个方法密不可分。

使用方法如下

html = '<h1>This is index page</h1>'
return render_template_string(html)

 3.模板

flask是使用Jinja2来作为渲染引擎的。看例子

在网站的根目录下新建templates文件夹,这里是用来存放html文件,也就是模板文件。

test.py

from flask import Flask,url_for,redirect,render_template,render_template_string
@app.route('/index/')
def user_login():
    return render_template('index.html')

/templates/index.html

<h1>This is index page</h1>

访问127.0.0.1:5000/index/的时候,flask就会渲染出index.html的页面。

前置知识-python魔法方法

object是所有数据类型的最终的父类

__class__                        查找当前类型所属的对象

__base__                        上一个父类

__mro__                          查找当前类的所继承的所有类

__subclasses__()            查找父类下的所有子类 

一般思路:找到父类<type ‘object’>–>寻找子类–>找关于命令执行或者文件操作的模块。  

 

1.【攻防世界】Web_python_template_injection

【攻防世界】Web_python_template_injection-优快云博客

2.【攻防世界】easytornado

【攻防世界】easytornado-优快云博客

3.【攻防世界】Confusion1

【攻防世界】Confusion1-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值