17 April 2020
Node 1Challenge Source: TryHackMe
Challenge Category: boot2root
- First, we start out with some basic enumeration:
We find that SSH is open as well as port 3000.
Inspection of the source code for website hosted at 10.10.123.120:3000 reveals some interesting script names:
- In particular, home.js reveals an internal path, which we’re able to access via the browser.
- Shaving off a bit of this path reveals an admin account as well:
- Next, we can use hash-identifier to determine that this probably SHA-256:
- Then we can proceed to use hashcat to try to crack the admin account (1400 corresponds to SHA-256).
- We can now go back to the main page and log in with these credentials.
- Checking out the file that we can download after logging in, it looks to be encoded.
- Throwing the file up on CyberChef and using the Magic function with defaults reveals that this was a B64 encoded zip file.
- You can then click to load the recipe as noted in the first output field and download the result, renaming it as filename.zip. However, as Zeddicus Zu’l Zorander once said: “Nothing is ever easy.” - the zip is also password protected.
- Ok, well maybe that was easy, but there’s a lot more to go still. Now we can dig through the files. We find some fantastic artwork in app.js…
- …but don’t let that distract us from the user mark’s mongodb credentials in plaintext on top.
As it turns out, these are also the SSH credentials for mark. This password is actually the TryHackMe user flag too, even though you’ll find a file called user.txt in the user tom’s directory upon logging in as mark.
Once inside, checking out the processes reveals that tom is running that app.js file using the binary /usr/bin/node from two spots: /var/www (which is the path we had the backup file for), but also /var/scheduler. The version of this in /var/scheduler is really interesting, however.
It appears that this version of app.js connects to the database, reads from ‘tasks’, executes whatever command is there, then deletes the entry, on a 30 second cycle.
We now need to figure out the syntax needed to actually make a connection to the database with the intent of adding a task that opens up a shell to our machine. It seems like it should be as simple as using the contents of the url variable, but authMechanism actually needs to be removed for this to work correctly.
Before we go further, we can grab some code here for a reverse shell.
One strategy is to add a command that runs netcat, since that is actually installed on the target machine. As information in the link above provides, since the target machine doesn’t allow the -e flag, we have to use the syntax:
Another approach, if we don’t want to rely on netcat being available, is to use a pair of Python scripts as found here.
This code goes on the target machine in the /tmp directory:
- This code goes on your machine:
- As a test before using it as a payload to run as the user tom, we can try this using mark’s account first.
- Now we can try to run this by modifying the mongo db task list. We need to make sure to run the listener on our machine first else we might miss that 30 second window.
- Note: syntax errors may show up due to non-printable characters depending on where you copy/paste code from. Try to manually enter the command if this happens.
- If you want to use the netcat method since it is available to us (and it is admittedly cleaner and less buggy while poking around), you can enter:
- Either way, we wind up with this piece of information after getting done with all the other rabbit holes:
- Using searchsploit, we can find some privilege escalation scripts for this kernel version. Note: 41457 doesn’t seem to work correctly and causes the target to hang up, but 44298 works with no problems.
- We can copy the source over and build it. (Sublime Text 3 was used in the image below).
- Then we can set up a local web server to make it easy to grab the compiled exploit.
- We cd into the tmp directory again, download the exploit, change the permissions appropriately, execute the binary to get root and cd into the /root directory to finally find the flag. Whew!
This was a fun, educational and challenging room; totally worth pushing through to complete.Tags: TryHackMe