ctf中flask_ssti的各种绕过技巧
2021-01-13 17:32:52 Author: xz.aliyun.com(查看原文) 阅读量:198 收藏

相信在ctf中大家遇到flask_ssti已经很多次了,这篇文章就研究和探讨一下绕过的方法。
python的字符串表达
flask_ssti的过滤一般是过滤某些字符串,既然是字符串,那么我们去找找字符串有哪些特性不就可以得到很多的trick了吗?我们先找到python的手册,然后找到字符串的一些解释

https://docs.python.org/zh-cn/3/tutorial/introduction.html#strings

这里我们就发现了2个trick了,字符串拼接和字符串截取,字符串拼接可以是直接相邻的两个字符串会自动拼接到一起,或者使用+来进行拼接,比如说过滤了__,我们可以通过"_""_"或者"_"+"_"来绕过,这里写个测试ssti的代码:
from flask import Flask,render_template,request,session,url_for,redirect,render_template_string

app = Flask(__name__)
app.config['SECRET_KEY'] = "password"
@app.route("/",methods=["POST"])
def index():
    ssti = request.form.get('ssti')
    return render_template_string('''%s '''% (ssti))
if __name__ == "__main__":
    app.run()
可以看到成功解析了

继续看看字符串还有什么特性,发现了格式化字符串,不过f"a{name}"这种用不了,因为所有字符串首先都会在jinja2(jinja2.parser.Parser)进行解析,这里直接就过不了语法的解析,因为匹配解析模式里面就没有f"*"这样的格式,所以用不了,不过字符串的属性还是继承了的

https://docs.python.org/zh-cn/3/tutorial/inputoutput.html#formatted-string-literals

不过还有其他格式化的方式



找到了格式化的方式,那么就看看格式化的特点吧

https://docs.python.org/zh-cn/3/library/string.html#formatstrings

那么我们就可以通过数字来绕过某些单个字符的过滤了


文章来源: http://xz.aliyun.com/t/9008
如有侵权请联系:admin#unsafe.sh