2022 Hacky Holidays: UnlockTheCity CTF— History Repeats, Stop The Heist, Cloud Escalator Part 1

Khris Tolbert
Maveris Labs
18 min readJul 29, 2022

--

Recently, I participated in the Hackazon Hacky Holidays: UnlockTheCity CTF (say that three times fast). UnlockTheCity was a somewhat different experience than I was used to as the CTF released challenges in 4 separate phases, limited teams to no more than 4 participants, and ran for almost 3 weeks (from July 8th-26th, 2022).

Team Dolphin Riders (don’t ask, it is a silly and really nonsensical story), rallied hard, peaking somewhere around 10th place through 3 phases before finishing 13th overall.

I thoroughly enjoyed most of the challenges I partook in except for that dreaded Port Authority (stupid captain must have got NASCAR and the seven seas mixed up — ok, I’ll even admit that was fun too). Anyway, here is a writeup of my top three (3) favorite challenges I attempted and solved!

3. History Repeats [#network #exploit] — 250 points
2. Stop The Heist [#forensics #ir] — 225 points
1. Cloud Escalator, Part 1 [#web #cloud] — 300 points

3. History Repeats [ HARD #network #exploit ]

CHALLENGE INFORMATION
The AI locked us out of our Core Infra System running on 10.6.0.2, if only we had installed our updates… Can you find a way to get in?
Author information: This challenge is developed by BHemida@DeloitteNL.

ENTER FLAGS [250 POINTS]
RECOVERY ACCESS
Can you find a way to get back into the core infrastructure system

The challenge contained one (1) subtask for all 250 points and required access via the CTF VPN.

This was one kicked over the fence to me from Matt “Rudy” Benton after some initial (frustrating) recon. The challenge description and title clued us in that this was very likely something relatively notorious. A few nmap scans reinforced this preconception as NETBIOS and SMB were found open:

Next, a hunch led to trying out MS17–010 (CVE-2017–0144). Full disclosure, MS17–010 is one of my guilty pleasures to mess with. Brings me back to my days during an exercise where my custom WannaCry emulator ran amuck creating the ultimate cyber nuclear winter on those poor VMs.

Live footage from the bare metal servers during the exercise

Anyway, back to the task at hand. Metasploit’s MS17–010 checker very quickly seemed to confirm our hunch:

But alas, after numerous exploitation attempts using MSF’s MS17–010 eternalblue module, nothing proved fruitful:

My experiences with this exploit knew that exploitation of MS17–010 could be tricky at times. The challenge being rated HARD also suggested that this would not be a turn-key exploit. Digging in, I revisited the nmap smb-enum output and assumed that the lack of available SMB shares might be preventing successful exploitation. What now?

While I still leaned that the eternalblue version of MS17–010 was going to be the key, I flirted with the idea of trying the other flavors. Metasploit has a few available by default:

And here’s where the multiverse forks. During the CTF, I had used the MSF auxiliary/admin/smb/ms17_010_command to issue a simple ping command back to my system in order to confirm successful code execution. The module uses MS17–010 eternalromance for exploitation, and instead of pushing a file over to C$, merely executes the command requested:

But in the CTF afterparty (to allow players to fine-tune writeups), where one isn’t downing Red Bulls and listening to the latest haxxor rave playlist on Spotify well late into the night, this did not work. In fact, a slight modification to the infamous zzz python script by wowrit was successful:

ZZZ using svcctl to execute my ping command, proving RCE

Those of you who work for Marvel’s TVA, fret not. The post exploitation utilized in both cases very quickly provided the flag in the same fashion. I initially thought about echoing out line by line some sort of WScript download and execute utility, but then rejected that idea because, well, I have a history of messing up command line escape sequences (quasi related, relevant XKCD).

So adding a user and a share it is! I simply changed the command each subsequent exploitation attempt to add a user, escalate the user, and finally open a share so I could access all of the all-mighty C drive:

Next, using smbclient and navigating to the Administrator’s Desktop, the flag could be found:

FLAG: CTF{N0t_4_Scr1pt_K1dd13s}

2. Stop The Heist [MEDIUM #forensics #ir]

CHALLENGE INFORMATION

Oh no! Attackers might have stolen our precious documents from the super secret share. We need to know what they took exactly…

Author information: This challenge is developed by OHaalstra@deloitteNL.

This challenge contained four (4) files and had three (3) subtasks for a total of 225 points. The four files were:

[75 POINTS]LOCATE THE PAYLOAD.

The attackers seem to have gotten a foothold on our system. And executed some malicious code. We need to know what the code does.

The first subtask states we need to find the payload on the system. Digging through the provided files, it was discovered that the provided ZIP is some sort of dump of the C drive:

In this dump, my expert sleuthing skills found some windows event logs. Additional scouring in the provided JSON hints to powershell execution being the initial infection point. So opening up the following confirmed such:

  • .\C\windows\system32\winevt\Logs\Windows PowerShell.evtx
  • .\C\windows\system32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx

After using the ultimate cheat-code known as Ctrl+F for the string “CTF{“ on the Microsoft Powershell Operational log presents the flag in one of the entries:

I got mad “Find” skills, yo

Easy to miss if you aren’t paying attention. The provided unlockthecity.json contains nearly the same output, except the flag is “CTF{XXXXXXXXXXX}”, so my mind just assumed this was the exact same string. Thankfully Matt “Rudy” Benton was following a screen share as I was bouncing through these and promptly pointed out the real flag.

FLAG: CTF{You_Found_The_EVIL_AI_Payload}

[75 POINTS]STOLEN FILES

To report to the authorities we must know exactly which files have been taken by the attacker. Are you able to figure this out?

The next subtask required hunting down the exfiltrated files. Due to the previous challenge, this task proved to be somewhat easy as we already knew what the C&C TCP port was being used: 4444.

Opening up the greatest free packet analyzer I have, aka Wireshark, on the provided PCAP and filtering to display TCP port 4444, the following is shown:

tcp.port==4444 FTW as all my haxxor friends use 4444

Thus, following the TCP stream the flag is made pretty apparent:

Who knew `{` would give Powershell fits?

FLAG: CTF{EXFILTRATE_ALL_THE_FILES}

[75 POINTS]PASSWORD CRACKING

Can you please find out whether the attack was caused by a weak password? We need to know whether the users are adhering to our password policy. Our password policy for the domain is CTF{[ROCKYOU_1]_[ROCKYOU_2]!} where [ROCKYOU_1] and [ROCKYOU_2] are distinct words from the rockyou.txt list.

And the next segment is brought to you by More Password Cracking! A pretty simple solve… …if you carefully read the description. There’s about an hour or two of cracking time wasted because I initially didn’t, and omitted the trailing ! .

My approach to this challenge was to use hashcat’s combinator attack as it should allow use of two separate dictionaries to combine into a single one. The catch is, I believe only a single character can be appended to each list (this could be a false assumption btw). The challenge states that the passwords should be in the following format:

Enter sed to save the day! Using Kali WSL (don’t laugh, it is perfect for these kinds of tasks), the provided rockyou.txt was modified into two (2) separate dictionaries: one with CTF{ prepended ( ^ denotes line start) and the other with !} appended ( $ denotes line end). If you are curious, “sth” translates to “Start The Hack” / I just didn’t feel like calling it rockyou_prepend.txt for some reason — read my comment about red bull and haxxor techno earlier for context.

So… what hashes are we auditing??? Going back to the JSON and Powershell event logs, we see that the attacker attempted and failed (and I would presume at some point successfully) numerous credential dumps using mimikatz:

Defender is the trap and the creds are the cheese, man

This guided me over to the unzipped contents of the C drive dump. Surprise, surprise, there’s a dump.txt sitting in C:\Temp. The contents are typical mimikatz sekurlsa outputs containing hashed credentials of the poor schmuck “unlockthecity”:

After placing just the NTLM hash in its own file, my hashcat command looked something like this:

Add a dash of fried laptop GPU and about 50 minutes later our password flambé is served in an exquisite blue shell:

Its actually probably pretty dangerous to disable hashcat’s hardware monitor at this point, but does it get results!

FLAG: CTF{city123_unlocked!}

1. Cloud Escalator Part 1 [HARD #web #cloud ]

CHALLENGE INFORMATION
The AI managed to get into our secure smart city portal, but we have no clue how it got there.

Author information: This challenge is developed by Ankit Parashar, Vivek Mukkam Palavila Vijayan, Ralph van den Hoff and Fouad Aljaber.

Another multitask challenge with 4 subtasks for a total of 300 points. This challenge was initially accessed via an on-demand public instance spun up through the hackazon portal, but as the tags would imply, parts were indeed on other public cloud/internet platforms. This was by far my favorite challenge that I completed, and with more time to compete in the CTF, I think I would have rather enjoyed Part 2 as well.

[25 POINTS]IT’S THERE BUT NOT REALLY

Take a real close look

First glance would obviously hint that this by point total would be the easiest subtask to achieve, but the provided task text was left (intentionally?) somewhat vague. Upon accessing the on-demand instance web page we were met with a massive “UNDER CONSTRUCTION” image.

Looking in the source didn’t provide much, so the thought was probably start gobuster while I manually poke at some things. /login was a lucky guess, which then after some poking around lead to the forgotten password page:

Login page with forgot password link at the bottom
Screenshot of the infamous /forgotpassword.html

In the forgotten password page source, creds to an assumed SQL db can be seen in the errorMessage function:

Our teammate Allen felt like Rockwell and MJ with these creds. As if… they already knew him

Piping these into mysql led to a handful of databases that might prove useful:

Using the users database, and viewing the tables, the first flag of the challenge can be captured by a simple select * from data;:

FLAG: CTF{!_p@wn3d_db_4_fu9}

[50 POINTS]THROW EVERYTHING IN THERE

Don’t add too much or it’ll overflow

Oh… like a play on everything but the kitchen sink? I was wondering what the task hint was getting at. I guess I get it now, anyway…

Dumping the config db, the aptly named aws_env table is present with some bad news for poor ol’ Allen Butler… ok, not our Allen Butler, but their allen:

Adding this key into my aws testing environment ends up providing access to some sort of logging file:

Searching for the known string CTF{ (CTRL+F FTW again!!!) the flag can be spotted on line 64 in an informational message:

FLAG: CTF{S3eing_T3r0ugh_!t}

[75 POINTS]FOLLOW THROUGH

It takes commitment, but if you follow through you’ll find it

OMG!!! COMMIT(ment)! Just put that together… I guess I should actually read the hints before I start the tasks next, time.

Another nugget mined from the Logs.txt file is an error complaining about not being able to pull some git repository:

Visiting the cloudhopper-sec github page,we are able to see a recent commit, but no public repos:

Where were you on June 22nd, 2022? Huh? Huh? HUH?

And then back to the kitchen sink-there is a db named env which contains a deploy_key in the .git table:

Copying the key over to ~/.ssh/cloud_rsa and then following a guide found on github related to using SSH for accessing repositories, I quickly fired up <insert you favorite editor here> and threw together a sloppy, yet I guess effective SSH config that would allow access to the private repo:

Cloning the repo locally, I was now armed with the source to the great “UNDER CONSTRUCTION” banner. Oh and the rest of the app, of course. And then, looking at CookieHandler.java , then the username and password fields which are compared to LoginServlet.java inputs are blank? Has this been scrubbed???

Mentioning my theory over to Allen Butler, he just non-chalantly says, “ Oh yeah, you using VSCode bro? Dude, it can like pull previous commits and show the diffs between them.” (I’m paraphrasing). So installing Github Pull Requests and Issues extension on my VSCode, and then selecting “Source Control” on the left hand side, displays a tell-tell commit properly named “sanitisation”. Clicking on such shows that CookieHandler.java has indeed been cleaned and used to have admin credentials present:

“admin” / “C@llTh3PluMM3r” you got credential leaks!!!

Logging in using the /login page on the webapp, we were met with a beautiful flag:

FLAG: CTF{Y0u_G0t_A_l3ak}

[150 POINTS]SECURITY CHECK

Can you make sure that you got all the vulnerabilities?

The final and hardest task of this challenge. Right away, while we were working our way figuring out the last steps of the previous task, we made note of the fact that log4j was indeed package with the webapp. The dependency entry in pom.xml showed version 2.14.1, which is a known vulnerable version of log4j to log4jshell (CVE -2021-44228):

To prove our theory, Matt “Rudy” Benton suggested we utilize huntress’s log4shell tester:

Next, we needed to identify what was being logged and how. As we raced one another digging through the webapp source, I eventually stumbled on a block of code present in ProfileServlet.java(I’m telling the story here, so I won of course):

Yeah, take that Allen Butler and Matt “Rudy” Benton

The code is looking for an optional cookie named debug, then logging the base64 decoded value on it. Additionally , the code was checking to ensure the LoggedIn cookie was present, so the valid admin login from earlier helped:

Logging in, using Burp, and sending my request over to repeater, I was able to easily add the debug cookie and received a response on the huntress log4shell tester (pictured earlier):

It was important to note that html encoding = characters would cause the server to rip a hole in time and space and throw a http 500 status (Only wasted about an hour or 17 trying to troubleshoot that).

After a few tests, I then sought out how to achieve a reverse shell on the webapp system. My first attempt was trying to re-use joswr1ght’s log4shell payload from SANS Holiday Hack 2021, obviously with a few minor edits to point at my cloud based redirector. Unfortunately, as the payload requires nc, this was not successful. I then found a payload that relied on just sockets and a command execution application (such as /bin/bash or cmd.exe for you windows types). Carving out just the java bits I needed, I felt I was ready to try again:

And… nothing. Oh wait, I’m sure I have the wrong java loaded. Pulling down jdk8, and compiling again (here’s how, since I very blatantly glossed over this):

I was met with some better success, and found the flag:

FLAG: CTF{H3aT_th3_L0GF0rg3}

Summary

As I said at the top, UnlockTheCity was a blast! The tasks contained interesting challenges about Quantum Computing, Crypto, Forensics, Cloud computing, Network Exploiation, Programming Challenges, Incident Response, and much more! My teammates and I fully cleared 2 of the 4 districts (darn Port Authority, or it would have been 3), solved 64/81 subtasks, scored 4650 points, and placed #13th overall, #5th amongst professional teams, #3 in the US, and #1 amongst professional teams in the US. Congrats to winners of the CTF, who will be officially announced August 2nd on the HackyHolidays twitter.

Maveris is an IT and cybersecurity company committed to helping organizations create secure digital solutions to accelerate their mission. We are Veteran-owned and proud to serve customers across the Federal Government and private sector. Maveris Labs is a space for employees and customers to ask and explore answers to their burning “what if…” questions and to expand the limits of what is possible in IT and cybersecurity. To learn more, go to maveris.com/#maveris-labs.

--

--

Khris Tolbert
Maveris Labs

Sometimes things break and I happen to be behind the keyboard. I’m just as confused as you are.