使用handler
例题:护网杯2018 easytornado
这道题关键就在于如何获取cookie_secret
通过搜索源码,在tornado/web.py中找到cookie_secret:
secret = self.application.settings["cookie_secret"]
那么只需要想办法通过模板注入得到self.application.settings即可得到cookie_secret。
这段代码定义在RequestHandler类中,查询文档,发现有这么一段:
表达式可以是任意的Python表达式, 包括函数调用. 模板代码会在包含以下对象 和函数的命名空间中执行
handler: 当前的RequestHandler对象
也就是说,在模板中使用handler,返回的就是当前页面的RequestHandler对象
测试一下看看:
http://220.249.52.134:32855/error?msg={{handler.request}}HTTPServerRequest(protocol='http', host='220.249.52.134:32855', method='GET', uri='/error?msg={{handler.request}}', version='HTTP/1.1', remote_ip='xx.xx.xxx.xxx')
想测试函数,但是很多特殊符号都被过滤了。
继续看手册,找到RequestHandler.application
RequestHandler.application
- 为请求提供服务的
Application对象
得到Application之后就简单了,使用handler.application.settings就可以得到cookie_secret。
