PHP代码审计


环境搭建

推荐用 phpstudy 搭建 php 代码审计的环境,简单快捷,切换 php 版本也很方便,再配置好 Xdebug 在 PHPstorm 即可远程调试。

相关文章

如果是云服务器,推荐使用 aapanel 部署 lnmp 环境,很方便

相关工具

  • LoRexxar/Kunlun-M
    git clone --depth 1 https://github.com/LoRexxar/Kunlun-M.git
    cd Kunlun-M
    pip3 install -r requirements.txt
    cp Kunlun_M/settings.py.bak Kunlun_M/settings.py    # 配置文件迁移
    python3 kunlun.py init initialize                   # 初始化数据库,默认采用sqlite作为数据库
    python3 kunlun.py config load                       # 加载规则进数据库(每次修改规则文件都需要加载)
    python3 kunlun.py -h
    python3 kunlun.py scan -t ./tests/vulnerabilities/
    
  • ecriminal/phpvuln

相关文章

相关靶场

php代码解密


硬编码

通用关键词


文件包含

描述

include 将会包含语句并执行指定文件

条件

PHP 的配置文件 allow_url_fopen 和 allow_url_include 设置为 ON

漏洞示例

<?php
    highlight_file('index.php');
    $file = $_GET['file'];
    include $file;
?>

更多内容


文件操作

相关文章

相关工具

相关案例

ctf writeup

文件操作类威胁函数

file_put_contents
file_put_contents($file, $string);
copy highlight_file()
fopen()
read file()
fread()
fgetss()
fgets()
parse_ini_file()
show_source()
file()
file_get_contents

关键词

+filename+
+file+
&file_name=
&filename=
&file=

PHP反序列化

反序列化威胁函数

__construct()
__destruct()
__sleep()
__wakeup()
__toString()
__get()
__set()
__isset()
__unset()
__invoke()
__call()
__callStatic()

更多内容


SSRF

漏洞示例

curl()

function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
}

$url = $_GET['url'];
curl($url);

file_get_contents()

$url = $_GET['url'];;
echo file_get_contents($url);

fsockopen()

function GetFile($host,$port,$link)
{
    $fp = fsockopen($host, intval($port), $errno, $errstr, 30);
    if (!$fp)
    {
        echo "$errstr (error number $errno) \n";
    }
    else
    {
        $out = "GET $link HTTP/1.1\r\n";
        $out .= "Host: $host\r\n";
        $out .= "Connection: Close\r\n\r\n";
        $out .= "\r\n";
        fwrite($fp, $out);
        $contents='';
        while (!feof($fp))
        {
            $contents.= fgets($fp, 1024);
        }
        fclose($fp);
        return $contents;
    }
}

审计函数

cURL
file_get_contents
fsockopen()
curl_exec()

关键词

file_get_contents($

更多内容

cURL

cURL 支持 http、https、ftp、gopher、telnet、dict、file 和 ldap 等协议,利用 gopher,dict 协议,我们可以构造出相应 payload 直接攻击内网的 redis 服务。

curl/libcurl 7.43 版本上 Gopher 协议存在 bug 即 %00 截断,经测试 7.49 版本可用;

curl_exec() 默认不跟踪跳转;

file_get_contents

file_get_contents() 支持 php://input 协议

file_get_contents 的 gopher 协议不能 UrlEncode


PHP弱类型


PHP变量覆盖


PHP伪协议


PHP反序列化


命令执行

审计函数

exec()
system()
shell_exec()
passthru()
pcntl_exec()
popen()
proc_open()

代码执行

审计函数

eval()
assert()
create_function()
array_map()
call_user_func()
call_user_func_array()
array_filter()
usort()
uasort()

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

github haidragon

https://github.com/haidragon

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

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