[CISCN2019 华北赛区 Day1 Web1]Dropbox
3.实验原理
文件读取漏洞,Phar反序列化,改包下载源代码,
4.实验步骤
打开靶场,首页是登陆注册页,先注册一个登陆一下

进去后看到是文件上传,这里先随便上传一下,这里上传php文件不行,上传png可以
看到又下载/删除按键,然后点击一下就可以下载了


这里就有漏洞疑点了文件泄露,通过下载改包得到网页源代码,网页一般源代码位置:/var/www/html然后加上创建的项目文件(index.php,down.php,upload.php,register.php,login.php,class.php,delete.php)

查看后,看到关键代码


这里的class.php十分重要,就是攻击出发点经典的Phar反序列化RCE /任意文件读取漏洞

User::__destruct()
↓
$this->db->close();
↓
(如果 $db 是 FileList 对象)
↓
FileList::__call("close", ...)
↓
循环调用 $file->close()
↓
File::close()
↓
file_get_contents($this->filename)
如果把db` 控制成 FileList 对象就会触发 FileList 的 __call () 魔术方法最终调用 File 类的 close () = file_get_contents ()
构造的POP链
User
└─ $db = FileList
└─ $files = [ File ]
└─ $filename = /flag.txt
$phar->setMetadata($o);
$phar->stopBuffering();
?>
然后命令执行生成攻击文件
"D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe" -d phar.readonly=0 4.php

然后文件上传,上传时候要抓包修改后缀以及文件接收类型,不然上传不了

然后去删除它,也要抓包,修改filename的参数:phar://test.png得到flag

这样传filename=phar://test.png/../../flag.txt也是可以的


浙公网安备 33010602011771号