PHP代码审计之路——1.文件、目录、浏览查看相关

1.目录及文件查看
  • array glob ( string $pattern [, int $flags = 0 ] )
glob() 函数依照 libc glob() 函数使用的规则寻找所有与 pattern 匹配的文件路径,类似于一般 shells 所用的规则一样。不进行缩写扩展或参数替代.。
foreach (glob("./*") as $filename) {  echo $filename."<br>"; }
  • array scandir ( string $directory [, int $sorting_order [, resource$context ]] )
返回一个 array,包含有 directory 中的文件和目录。
  • DIRECTORY_SEPARATOR 目录分隔号,如‘/’,可能是为了兼容
  • Directorydir ( string$directory [, resource$context ] )
以面向对象的方式访问目录。打开 directory 参数指定的目录
$dir = dir('../template');
while(($file = $dir->read()) !== false){
echo $file."<br/>";
}

  • string readdir ([ resource $dir_handle ] )
返回目录中下一个文件的文件名。文件名以在文件系统中的排序返回
  • resource opendir ( string $path [, resource $context ] )
打开一个目录句柄,可用于之后的 closedir()readdir()rewinddir() 调用中
function feach_dir($dirname){
	$dir = opendir($dirname);
	while(($file = readdir($dir)) !== false){
		$filename = $dirname.'\\'.$file;
		if ($file != '.' && $file !== '..') {
			if (is_dir($filename)) {
				feach_dir($filename);
			} else {
				echo $filename.'<pre>';
			}
		}
	}
}


 
 
  • __FILE__ basename() dirname()
文件的绝对路径及文件名
  • __DIR__ C:\xampp\htdocs\Joomla
当前文件的所在目录
2.文件内容查看
  • mixed highlight_file ( string $filename [, bool $return = false ] )
使用PHP内置的语法高亮器所定义的颜色,打印输出或者返回 filename 文件中语法高亮版本的代码
  • string file_get_contents ( string $filename [, bool $use_include_path = false [, resource$context [, int$offset = -1 [, int$maxlen ]]]] )
重要,如果 filename 是url且类型为php,会读取并执行;如果是相对路径或是绝对路径加文件名则仅会读取文件中的内容而不会处理。
file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败, file_get_contents() 将返回 FALSE
3.文件操作
• copy — 拷贝文件
bool copy ( string $source , string $dest [, resource $context ] )
将文件从 source 拷贝到 dest
• file_get_contents — 将整个文件读入一个字符串
如果allow_url_fopen开启还可读取http等协议的文件
• file_put_contents — 将一个字符串写入文件
• file — 把整个文件读入一个数组中
array file ( string $filename [, int $flags = 0 [, resource $context ]] )
把整个文件读入一个数组中
• fopen — 打开文件或者 URL
• move_uploaded_file — 将上传的文件移动到新位置
• readfile — 输出文件
• rename — 重命名一个文件或目录
bool rename ( string $oldname , string $newname [, resource $context ] )
尝试把 oldname 重命名为 newname
• rmdir — 删除目录
• unlink & delete — 删除文件
•parse_ini_file
•tmpnam
以读写(w+)模式建立一个具有唯一文件名的临时文件,返回一个文件句柄。
文件会在关闭后(用 fclose())自动被删除,或当脚本结束后
•touch
•ZipArchive::open
•int fwrite ( resource $handle , string $string [, int $length ] )
把 string 的内容追加写入 文件指针 handle 处。
4.文件包含
  • include 包含文件找不到仅警告,即 Warning
  • include_once 文件若已经包含则不再包含,包含文件找不到仅警告
  • require 包含文件找不到将发生 Fatal error,程序到这行代码停止运行
  • require_once 文件若已经包含则不再包含,找不到文件发生致命错误
  • phar:// 数据流包装器自 PHP 5.3.0 起开始有效,仅支持zip
假如文件包含代码如下
就需要这样修改
  • file:// — 访问本地文件系统

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值