当前位置:网站首页>[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
边栏推荐
- Basis of deep learning neural network
- How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
- Review notes of compilation principles
- Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
- Viewing and modifying volume group attributes of Aix storage management (II)
- Entrepreneurship is a little risky. Read the data and do a business analysis
- RFID makes the inventory of fixed assets faster and more accurate
- Source code of Qiwei automatic card issuing system
- 测试员8年工资变动,令网友羡慕不已:你一个月顶我一年工资
- How do Lenovo computers connect Bluetooth headsets?
猜你喜欢

How to type spaces in latex

What skills does an excellent software tester need to master?
![[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login](/img/c1/23be4399119f42d85a7b86fc8a59fc.png)
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login

Excel search and reference function

Slf4j print abnormal stack information

Schrodinger's Japanese learning applet source code

2022 operation of simulated examination platform for melting welding and thermal cutting work license

一名优秀的软件测试人员,需要掌握哪些技能?

How to extract login cookies when JMeter performs interface testing

Output results of convolution operation with multiple tensors and multiple convolution kernels
随机推荐
JS -- image to base code, base to file object
Global and Chinese market of ancillary software 2022-2028: Research Report on technology, participants, trends, market size and share
2022拼多多详情/拼多多商品详情/拼多多sku详情
SSO single sign on implementation.
449-原码、补码、反码
Global and Chinese market of safety detection systems 2022-2028: Research Report on technology, participants, trends, market size and share
The new version of graphic network PDF will be released soon
You probably haven't noticed the very important testing strategy in your work
Node -- egg implements the interface of uploading files
What skills does an excellent software tester need to master?
Powerful calendar wechat applet source code - support the main mode of doing more traffic
js 公共库 cdn 推荐
Global and Chinese markets of edge AI software 2022-2028: Research Report on technology, participants, trends, market size and share
2022 high altitude installation, maintenance and removal of test question simulation test platform operation
AIX存储管理之总结篇
Leetcode skimming: stack and queue 01 (realizing queue with stack)
Deb file installation
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
Node——生成微信权限验证配置
449 original code, complement code, inverse code