美文网首页CTF
[CTF_web]exec/exec2.php

[CTF_web]exec/exec2.php

作者: 王一航 | 来源:发表于2017-08-14 15:19 被阅读90次

CTF_web

CTF_web


源码如下 :

<?php 
$ip = isset($_GET['ip'])?$_GET['ip']:die();
if(!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i',$ip)){
    die("ip 格式错误!");
}
echo strlen($ip);
if(strlen($ip)<7||strlen($ip)>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  "<pre>{$cmd}</pre>";
## 要求,利用命令执行getshell
image.png

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


参考资料 :

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

相关文章

网友评论

    本文标题:[CTF_web]exec/exec2.php

    本文链接:https://www.haomeiwen.com/subject/obuurxtx.html