[CTF_web]exec/exec2.php


CTF_web

CTF_web


源码如下 :

21){
    die("ip 长度错误!");
}
    // Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
        // Windows
    $cmd = shell_exec( 'ping  ' .$ip );
}else {
        // *nix
        $cmd = shell_exec( 'ping  -c 1 ' .$ip );
}
    // Feedback for the end user
echo  "
{$cmd}
"; ## 要求,利用命令执行getshell
[CTF_web]exec/exec2.php_第1张图片
image.png

这个题目的缺陷在于 :
正则中并没有使用 $ 来限制字符串的结束
因此只要构造一个以正常形式 ip 开头的参数即可
然后在这个正常的 ip 之后利用管道或者逻辑运算就可以执行任意命令


参考资料 :

http://php.net/manual/zh/function.preg-match.php

你可能感兴趣的:([CTF_web]exec/exec2.php)