Today's write up is not the success story I was hoping it would be. Despite the room showing as being "easy" on TryHackMe, I didn't complete it without referring to the official write-up a couple of times.
It's possible that it's ranked "easy" because it comes with an official write-up which is displayed within Task #1's text.
Still, I thought I'd document it as I feel that, despite referring to the write-up, I have learned some valuable skills and lessons from having completed it and I wanted to get that down here. It's all part of the journey, after all. My hope is that next time I'm faced with a similar challenge I won't need to refer to the write up. Part of my plan for writing these blog posts is to try to cement in my own mind the learnings I take away from these challenges.
Other than the link to and description of the official walkthrough, the opening text gives very little away as to what needs to be done here. It simply states "Are you able to compromise this Terminator themed machine?".
Question #1
The questions give you some guidance on what you're looking for:
So, we have a rough idea of what username we're looking for and the fact there is some kind of e-mail service running on here.
Given the lack of any other information, I started, like usual, with a quick nmap:
So, we have e-mail services (POP3 and IMAP4 running on ports 110 and 143, respectively), a web server (Apache on port 80), ssh (port 22) and Samba (ports 139 and 445). No SMTP port, so the server's not geared to accept external mail.
First port of call would be to fire up the old browser and see what's showing on the web server:
Looks like it's a search engine. The layout/style feels familiar, but I can't quite place where...
After probably less than a minute poking around at this, I came to the conclusion it wasn't particularly useful. I moved on to another tool which I'd usually run after encountering a web server, GoBuster:
Looks like we've found something which might be of use, a squrrelmail install. Navigating to this shows us a standard SquirrelMail login:
So we now have an endpoint for our credentials, should we be able to find the required credentials. I tried running sqlmap against it, despite having had a quick look around the web for known exploits and not seeing any SQLi listed. Unsurprisingly, this didn't turn anything up.
At this point I tried turning to some other ports to try. I considered running hydra against the SSH port but decided against it as a) I wasn't 100% sure on what username was likely to be used (the "Miles" in the question was capitalised and so I didn't want to trust that it should be just "miles" for the username), and b) hydra against SSH takes a really long time.
I thought the Samba ports may be useful and these tend to be pretty quick to enumerate, so I fired off a quick smbclient command:
Looks like I may have been right not to trust what the username was going to be. Next step was to try to open the shares:
Within the root of the anonymous share, we can see a file called attention.txt and within a subfolder called logs there are three log files, of which only one contained any data. There was also a books folder, but that appeared to only contain PDF and epub files. I thought it best to take a look at the text files first.
log1.txt looked like it could be a fairly handy password list.
Given that I still didn't know what the username was likely to be, I thought it best to try both miles and milesdyson, so I through these into a text file I called users:
I then fired up hydra to try to brute force the SquirrelMail login page:
Success! We now have the username and password to get into the mailbox, with the password being the answer to question #1.
Question #2
Given that GoBuster failed to find a hidden directory which met the mask given in the answer, I'm assuming that we probably need to go looking in Miles' mail for the next part. Even if it had turned up another directory, I'd probably still have snooped around Miles' mail anyway through natural curiosity.
So, three e-mails in the mailbox. The last one contains some gibberish:
The second one contained some binary:
I ran this through CyberChef and obtained the following insightful text:
With the first e-mail, however, we find something which may help:
Back to smbclient we go then:
In Miles' share there were some more PDFs and a folder called notes. Within the notes folder there were a load of markdown files, and a txt file called important.txt. This looked important, so I grabbed a copy of it and had a quick look at it:
I had no time to worry about the state of Miles' relationship as I had just found the answer to question #2.
Question #3
Question #3 was actually the first question I answered as it was pretty simple and I like getting points quickly:
Question #4
I had a look at the content of the hidden directory:
There didn't seem to be a great deal which could be done here and an examination of the page source didn't reveal much.
This was around this point where my troubles started. My initial approach took me down a rabbit hole of trying to exploit SquirrelMail. The research I'd done had suggested that a version of SquirrelMail close to the version number we were running here (SquirrelMail version 1.4.23 [SVN]) had an RCE (Remote Code Execution) attack vector possible. Unfortunately, the research showed conflicting information regarding exactly which version was vulnerable:
I grabbed the script anyway, and tried to run it (after sense checking it to make sure it didn't look like it was going to try to take over my machine).
Initially the script didn't work as expected as one of the pages it scraped wasn't in quite the same format as it was expecting (looking back, I should have taken the hint that this maybe wasn't the exploit I was looking for).
I modified the script and got it to run, but it never actually got me in.
Not to be put off once I've decided to try it, I then tried to emulate the script's steps by hand to see if I could get it to work. I couldn't.
As I'm not one to give up on a good idea once I think I've had one, I then went and scoured the internet (by which I mean I did a couple of minutes of Googling) and found a python script which was meant to exploit CVE-2017-7692. This would have been an excellent plan if only this install of SquirrelMail had been vulnerable to this CVE.
Again, I should have taken a proper look at the header in the python file:
After dissecting and fighting with this script, I came to the conclusion that perhaps this system wasn't susceptible to this vulnerability and maybe I should have tried something else. Like an hour ago or something.
Still, it wasn't a complete waste as the time I spent looking at the two POCs for the exploit taught me a thing or two about how to script access to websites.
It was around this point where I realised I was struggling and went to the write-up. I'm disappointed that I did, as the answer I found was pretty obvious and was something I should have tried:
Oh, there's a subdirectory here called administrator. Looks much more promising than my attempt to compromise SquirrelMail.
We've found something we can log into! I tried all the passwords I had found up to this point with both combinations of miles and milesdyson. Nada!
I inspected the source code to the HTML and found that there was a password recovery function, but the code to activate it was commented out:
I tried putting in the e-mail address for Miles which we had a login for, but this went nowhere.
Well, doesn't that just sound exactly like the thing Question #3 was asking about?
I threw together a quick URL using this information:
So, we've found a local file inclusion exploit. Question #3 mentioned a remote file exploit though. Can we do that?
We know we're on PHP so we'll just write a very basic PHP script:
We'll also fire up our trusty python3 http server:
Craft a nice URL:
So, we're now including remote files. Shall we try something a little more useful?
Let's go grab a nice PHP reverse shell from pentestmonkey, modify it to point to the right host/port, start a listener and call the appropriate URL:
It's just simply a case now of getting the user.txt:
Although this is in Miles' home folder and we're not Miles (we're www-data) we can access this due to the permissions on it. The same is not true of /root/root.txt
We could also do this using LFI:
Question #5
Now that we have the ability to launch a shell, I thought I'd fire up msfconsole and generate a meterpreter connection:
From here we can upgrade to a meterpreter shell:
From here I ran metasploit's local_exploit_suggester:
This turned out to be useless as none of the suggestions worked.
I dropped back into a shell and ran LinEnum.sh (I won't reproduce the output here as it's far too long).
The only thing which stuck out was a cron job which runs a script within Miles' home folder:
Although the cron job was running a user controlled script it, unfortunately, wasn't controlled by the user we have access to.
We could view the script, but not modify it:
After a while messing around, I went back to the write-up as I could not work out what I was meant to do from here.
It turns out that the clue was the * in the script which, by the time execution reached this point, was running in a directory we did have control over.
The only piece of information I was lacking now was how to exploit this.
It turns out that tar can take some command line parameters which cause it to execute a command at certain points during the process. As the process was running as root at this point, all we needed to do was have a reverse TCP shell script and create the files needed so that bash globbing would cause the names of the files to be used as parameters for tar:
As the script executes every minute, once you've done this and set up a listener, you'll very quickly get a root shell:
And there we have the 5th and final answer. Room completed!
Lessons Learned
There are a few things I'll take away from having completed this room:
Pay more attention to the info available in the room text/questions. I went down a rabbit hole looking for an exploit where there was none. Still, I learned something from that.
If I find a directory with GoBuster, I should re-run GoBuster against that directory as well.
Bare * glob expansions in shell scripts are a Bad ThingTM. Prior to this room I had no idea that this was even possible, so I would never have finished the room without having read the write-up. Next time I'll know better.
Summary
Again, another really nice, interesting room on TryHackMe. Some new skills were learned which I hopefully won't forget too quickly.
Looking forward to my next room and the lessons it'll teach me.