一、文件包含漏洞
- 原理
文件包含漏洞主要发生在PHP中,当使用文件包含函数(如include、require等)时,若未对包含的文件名进行严格限制,攻击者可能会利用这一点来包含恶意文件,从而导致敏感信息泄露或其他安全问题。
常见文件包含产生函数:
<?php
include 'hello2.php';
echo "hello include";
require 'hello.php';
echo "hello require";
include_once 'hello.php';
//增加once的可以避免重复包含
?>
- 防御方法
在DVWA靶场的中级难度中,我们可以通过限制http://来防御文件包含漏洞。例如:
<?php
// 限制http://
$file =$_GET['file'];
if(strpos($file, 'http://') === false) {
include $file;
} else {
echo "非法文件包含";
}
?>
绕过方法:使用重写绕过:hthttp://tp://...
大小写绕过:HTTP://
二、反序列化漏洞
- 概念
序列化:将代码拆分成方便传输的块。反序列化:将序列化后的字符串恢复成原始对象。
- 实例分析
以下是一个反序列化漏洞的示例:
如果将反序列化的参数改为用户输入的数据就会产生漏洞
<?php
class Person {
public $name;
public $age;
public function __construct($name,$age) {
$this->name =$name;
$this->age =$age;
}
}
$wang = new Person("王小二", 18);
echo '<br>';
var_dump($wang);
echo '<br>';
$wang_str = serialize($wang);
var_dump($wang_str);
echo '<br>';
$wang_obj = unserialize($wang_str);
var_dump($wang_obj);
?>
在这个例子中,我们将一个Person对象序列化成字符串,然后再反序列化成对象。
- 安全风险
反序列化漏洞可能导致攻击者篡改对象属性,从而执行恶意代码。因此,在实际开发中,我们需要对反序列化的数据进行严格校验。