Skip to the content.

Insecure

Challenge Description:

I don’t remember the exact challenge description, but it had to do with how the executable had SUID bit set, which allowed you to run commands with the same permissions as the owner of the file. In our case, since the owner of the insecure file is root (UID 0), this meant that we could also read the /flag.txt file that was also owned by root (At least, I think it was root. I cannot remember).

Files Attached:

Solution:

First, let’s take a look at what setting the SUID bit on a file does:

With a typical file, it would probably have the following permissions:

-rw-rw-r-- :

However, there are other special bits that can be set for that third bit of each set of permissions (User/Group/Others):

The following image (and the linked article) gives a pretty good summary: bits-images

Tools used:

Given the binary to download, we are able to use IDA64 to disassemble the insecure binary, as we can see below (Thanks to Sean for teaching me this - I had no idea how to start):

From the disassembly, we can see that the program calls the id command with a systemcall (which…you would also be able to see if I kept a screenshot of the original command output…oops!)

Once I spent 5 hours pulling my hair out and trying to understand what this program was trying to do and trying to understand what SUID was for, I finally realised that I could just…hijack the id application!

Going into /tmp, which is usually a directory that anyone could write files into, I decided that it was here that I will store my temporary application that could read the file at /flag.txt when id was called.

However, I realised that there were no text editors on the system…which made me rethink how I wanted to approach this challenge. Until I realised that I could simply cat the contents of my file into a file using stdout redirection and a version of cat that supports newlines (the shell was bash, after all)

The following shell program was written and used (formatted for better readablility):

#!/bin/bash
echo "HELLO THIS IS THE SCRIPT"
cat /flag.txt

The screaming was necessary. I assure you.

But we did find our flag!

Flag:

DSO-NUS{b4fcfe57b8d2b05ff3310c663a0497b1026cf039baeee18669957152cdc276da}