Skip to main content

Mastardet CTF challenge

 All right, today I'm gonna try and explain to you guys a custom challenge that my dear mentor/friend created for our discord server.

Author:- mastardet

Challenge file:- challenge.tar.gz

  Ok, so let's begin

A description of the challenge:-

The .tar file includes a binary "challenge_linux" for Linux users and "challenge_mac" for mac users, they have the same functionality but different architecture. This binary is built with Go which makes it difficult for us to exploit and reverse engineer

#1 Exploiting Binary (Grabbing the password):-

Step 1:-

Ok, so after a quick "chmod +x" and running the binary ./challenge_linux, we are met with a login prompt for cyberwizards:- 

So, the next thing according to my methodology was to do,

strings challenge_linux > data.txt

and we got a lot of DATA.....


Ok so this gibberish data had 16347 lines, there was no way we were gonna find anything in this (At least That's what I thought)

Step 2:-

The next thing I tried was reverse-engineering the binary using tools radare2, gdb, etc.

But the problem was that this binary was a Go executable and it was really hard to read the assembly functions.

(I spent more than 2 hours trying to find some information or password in the assembly)

So, with a little hint from the author, I did,

strings challenge_linux | grep -i "cyberwizards"

And bingo, we found something!!

 

 Look's like this might be the password to log in;


#2 Exploiting the server:-

Ok, so now that we are in the machine let's find the flag,


Looks like we have the flag.txt but we don't have any tools t o read the file, i.e.

 

So turns out this is a very restricted SHELL,


And as the help command shows us we have very limited commands

Step 1:-

Ok, so now by looking at the commands I realized that maybe I can somehow export a variable and escape the restricted shell.


Nothing, there too as the export command was giving an error if fed with arguments

Step 2:-

Let's try the history command now,

 

I soon realized that no matter what I did, the history was not changing, so that seems something to look into,

Ok, recap so we have export and history available,  let's try to find something on these two commands together.

And by doing some quick google search, I figured out that there is an environment variable called "HISTFILE".

HISTFILE is an environment variable that, if set, points to the file in where our history will be saved.

So, I set the HISTFILE environment variable to,

export HISTFILE=/root/flag.txt

 we get no errors and the command is accepted!!!!

 

Nice, now we need to set make sure that history command reads the newly updated HISTFILE and to do that we will use:-

history -r

This will update the variable and now history command will read the contents of the file set in HISTFILE.

 And, Voila we have the flag!!!!


So, this was an emulation server that was entirely created on Go!!

I had a pretty fun and learning experience while solving this machine.

A big shout out to the author @mastardet for creating this amazing challenge, be sure to check out his youtube, he has great content and you will surely learn a thing or 2 ;-)


Comments