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

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 = '

This is index page

'
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

This is index page

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

前置知识-python魔法方法

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

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

__base__                        上一个父类

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

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

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

 

1.【攻防世界】Web_python_template_injection

【攻防世界】Web_python_template_injection-CSDN博客

2.【攻防世界】easytornado

【攻防世界】easytornado-CSDN博客

3.【攻防世界】Confusion1

【攻防世界】Confusion1-CSDN博客

你可能感兴趣的:(安全,python,php)