As I said in part I, I participated in this year’s FooBarCTF. This writeup will include all the challenges from the most interesting category: shell. As a wanna-be pentester, I would love to see more CTFs include this category.
This was very similar to a challenge that I’ve done before on pwnable.[something], but I didn’t search for it because the solution is easy. The script will ask for a key, which will be used to calculate a file descriptor that will be used to read a string. My target was to set the fd variable to 0, because on Linux that represents stdin. That means that read() would read the string from the console. My solution is as follows:
Note that 201527 is just the base 10 representation of 0x31337.
Flag: GLUG{pwn_i$_e@$y}
shell2: -La -La -land
This was the challenge where things started to get interesting. Because the filenames start with -, the cat program would interpret them as switches instead of files to read. In order to get around this, I passed them as ./-filename instead of -filename:
Flag: GLUG{sykswfynlvdc}
shell3: Bridge of Spies
‘Look bigger or change your perspective’ means also looking at hidden files. However, a simple ‘ls -la’ command returned 1027 entries, meaning that there are 1024 hidden files (1027 – flag.txt – the . and .. directories). I used grep to get the flag:
Flag: GLUG{70m_h4nk5_15_17?}
shell4: Alibaba aur uske 64 chor
Even though I didn’t fully understand the title, this challenge was very easy. There were 2 files that contained base64-encoded string. I decoded those strings and got the flag.
Flag: GLUG{Y0u_g07_m3_7h1s_71m3}
shell5: He X-men
As the title suggest, the flag was encoded in hex. I used xxd to decode it.
Flag: GLUG{Y0u_f0und_h3x_h3r3}
shell6: time travel is dangerous
Since there weren’t any other files, I looked into .bash_history and found some interesting commands. I then recreated the contents of Time_ticket and got the flag.
Flag: GLUG{51c_Mundu5_Cr347u5_357}
shell7: I am different
There’s really not much I can say about this challenge. The diff command does exactly what it suggest: it prints the difference between two files.
Flag: GLUG{489ca541-56b6-4bf9-9632-037b6ea481ab}
shell8: clock under pressure
The flag was compressed, so I transferred it to my computer in order to be able to process the file. I did that by using scp (the name stands for ssh-copy):
After transferring the file, I just decompressed it two times: once using gunzip and once using bzip2.
Flag: TYHT{L0b_E0g@gr_q_J0eYQ}
shell9: Show me more
This was one of my favorite challenges. Every time that a user connected via ssh, some ASCII art would be printed and the connection would close immediately:
I got the idea of using echo to try to execute commands only to find out that the message is being printed from a file named ‘text.txt’:
Looking at the challenge title, I guessed the server uses ‘more’ to print that file. I knew that ‘more’ would keep itself opened and let the user scroll through the file if it was too big to be displayed in the terminal. However, I didn’t have control over the file’s contents, so I had to shrink my terminal window:
I then used this writeup to read ‘flag.txt’ by issuing the following commands to vi:
Flag: GLUG{54luch4n_n4h1_m1l3g4}
shell10: Worst time complexity
Since the program asks only for 4 digits, I made a bash one-liner that would try all possible inputs and print the flag once it is printed:
Flag: GLUG{c5_15_5h17}
shell11: Water overflow
This was a basic buffer overflow vulnerability. If the input is longer than 64 characters, it will start overwriting values on the stack. If it is long enough, it will eventually overwrite the numLitre variable.
Flag: GLUG{60_w17h_7h3_fl0w}
shell12: Stacks are cool
As soon as I started reading the source, I noticed the insecure ‘printf(in);’ instruction, which makes the application vulnerable to format string attack. I quickly tested to see if I was right:
It worked! That meant I could leak values from the stack. I just needed to find the correct offset to print the flag. I wrote a bash one-liner to bruteforce the it:
Flag: GLUG{n0_57r1n65_4774ched}
shell13: Auth is easy
The person who wrote the program probably thought nobody will be able to call it from a folder different than ~, as he/she used relative paths. I made my own folder in the /tmp directory and managed to fool the program into reading a file that I just created instead of the real ‘auth’ file:
Flag: GLUG{auth_is_easy}
shell14: Wrong user
This was another interesting challenge. The first step was to identify an unusual SUID binary (a binray that runs with root privileges no matter who executes it):
The command returned an unexpected result: ‘/bin/damn’. I never heard of it, and a quick Google search confirmed the program didn’t exist. However, I was able to quickly determine that the binary is just ‘xxd’ by calling it directly and passing the –version flag:
I thought that the program could allow me to read any file on disk given that it is a SUID, so I used it to dump the contents of /etc/passwd and /etc/shadow. While copying them to my local machine, I noticed an unusual user named ‘fyodor’ and remembered the Crime and Punishment author (Fyodor Dostoyevsky):
After that, I used the unshadow program to create a hash that can be cracked with johnTheRipper. After a lot of work, I discovered the password for ‘fyodor’ was just ‘123’. I then used su to switch over to his account and get the flag:
Flag: GLUG{w1nd0w5_5uck5}
shell15: Cant touch this
As the hint suggests, the flag file has been corrupted, so I transferred it to my computer and opened it in hexedit to see if I can determine the file type:
The first 4 bytes of the file seemed to have been replaced with ‘XXXX’, meaning that the file was corrupted. I also saw ‘IDHR’ and ‘gAMA’, which are headers specific to the PNG image type. In order to see the image, I had to replace the ‘XXXX’ characters with the magic bytes for PNG, which can be found on this list.
After that, I just opened the image and read the flag:
Flag: GLUG{corrupt_but_works}
shell17: Stacks are cool. Again?
This problem was released because there was an unintended way to get the flag for ‘Stacks are cool’. However, I did not describe that method, so you can just read the writeup for that challenge.
Footnote
I cannot post this article without including the picture below 🙂