1.题目
题目叫Simple SSTI
打开网页,显示.
SSTI,即服务器端模板注入。
2.知识点
flask基础
在学习SSTI之前,先把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。
渲染方法
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)
模板
flask是使用Jinja2来作为渲染引擎的。看例子
在网站的根目录下新建templates文件夹,这里是用来存放html文件。也就是模板文件。
test.py
from flask import Flask,url_for,redirect,render_template,render_template_string
@app.route('/index/')
def