刷题Phuck2--data协议差异

刷题Phuck2

使用arjun扫出hl参数,获取到源码

image-20240704231439-teiap68

源码:

<?php
    stream_wrapper_unregister('php');
    if(isset($_GET['hl'])) highlight_file(__FILE__);

    $mkdir = function($dir) {
        system('mkdir -- '.escapeshellarg($dir));
    };
    $randFolder = bin2hex(random_bytes(16));
    $mkdir('users/'.$randFolder);
    chdir('users/'.$randFolder);

    $userFolder = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
    $userFolder = basename(str_replace(['.','-'],['',''],$userFolder));

    $mkdir($userFolder);
    chdir($userFolder);
    file_put_contents('profile',print_r($_SERVER,true));
    chdir('..');
    $_GET['page']=str_replace('.','',$_GET['page']);
    if(!stripos(file_get_contents($_GET['page']),'<?') && !stripos(file_get_contents($_GET['page']),'php')) {
        include($_GET['page']);
    }

    chdir(__DIR__);
    system('rm -rf users/'.$randFolder);

?>

这里学到的知识:

  1. stream_wrapper_unregister('php');禁用php流(php开头的伪协议)
  2. allow_url_include=Off时,include函数不支持 include data URI 的,也就是说:file_get_contents在处理data:,xxx时会直接取xxx ,而include会包含文件名为data:,xxx****的文件

本题就是在头部进行RCE,头部信息会写进profile文件,我们再利用include包含profile文件

但是需要绕过对profile文件内容的检测

    if(!stripos(file_get_contents($_GET['page']),'<?') && !stripos(file_get_contents($_GET['page']),'php')) {
        include($_GET['page']);

这里的话就是data协议处理差异

当allow_url_include=Off时,include不支持data伪协议。
file_get_contents是读取而include是包含
这两者还是有区别的。所以我们传file_get_contents('data://text/plain,aa/profile')​时会得到aa/profile​字符串
而include因为不包含data伪协议。就会把data://text/plain,aa​当作一个目录,去包含下面的profile文件

但是这里出现一个问题,我们名字里有斜杠,是不合法的,其实直接使用data:,aa或者时data:aa就行
我们可以传值XFF为data:aa
就会创建data:aa​这个文件夹。然后包含data:aa/profile

image-20240704215616-3cgceg3

posted @ 2024-07-04 23:52  m1xian  阅读(59)  评论(0)    收藏  举报