Introduction
In June of 2022 I was invited to play for CyberSCI Team Canada at the first International CyberSecurity Challenge, hosted by ENISA in Athens, Greece. Here are a few of the challenges I solved, some of them retroactively, at the event.
The website for the event cant be found at https://ecsc.eu/icc/.
Web of 64
Category: Web
Description
What is written in /flag.txt?
Code
Solution
Important things to consider:
/run/<cmd>
endpoint runs a command usingos.system()
.- Commands can only be 6 chars (10 in base64).
/cat/<file>
gets a file.- File names can only be 6 chars (10 in base64).
- The string “flag” can not be included in our base64-encoded data.
We needed to work around the 6 character limit. Using and example from https://blog.karatos.in/a?ID=01650-1b895396-acd4-461c-8a7e-fe8f5e7eee0e, we found that we could use a wildcard expansion exploit to increase the size of the commands we can run.
The process was the following:
- Tar the
/flag
directory and put the tarball in the/tmp/<id>
directory for our session. - Use the
cat
endpoint to download the tarball to our local.
Initial attempts failed until we realised that the binaries installed on the remote are from busybox. Busybox binaries are meant to be minimal, which means they don’t include all flags that would be on a fully-functional binary. We used the following docs to help build the payloads: https://boxmatrix.info/wiki/Property:tar.
We used the following command to tar the flag directory:
We then used the cat
endpoint to download the resulting tarball, z
.
Because of the 6 char limit, we created the following files to be used in our wildcard exploit:
tar
vcf
z
Finally, we run the wildcard exploit, where the files generated before expand into the full command:
* /f*
A similar process was used to determine that flag.txt
exists in the /flag
directory. It involved piping the output of ls
to a file and downloading it.
Solve script
This is the script that returned the flag.
Flag
icc{6b1513fa-e3f7-4dc9-b110-66cac22ee98e}
References
- https://blog.karatos.in/a?ID=01650-1b895396-acd4-461c-8a7e-fe8f5e7eee0e
- https://boxmatrix.info/wiki/Property:tar
You shall not pass
Description
Connect to the device via USB at baud 115200. You’re now in a Python shell.
You can paste snippets using CTRL+E and CTRL+D.
Extract the flag from efuse by calling secure_read_efuse_block(<block>, <start_offset>, <length>)
Use get_flag(<bytes>)
to convert found data into a flag.
You can submit the flag by calling flags.submit_flag("CTF{xxxx}")
.
Run help() to repeat challenge info.
To show off our 1337 skills we have included part of the implementation here:
Solution
This was the first, and easiest, challenge on the hardware badge. Because of this, the solution is fairly straightforward.
To be honest, I found the correct sequence of bytes by just guessing. If you pass a length of 0 into secure_read_efuse_block
, it will return 32 bytes of data. This allows you to read the efuse.EFUSE_BLK2
region and bypass the first guard in the code.
Flag
CTF{50d1f7f8cb5de765cc0e910a908ba4822a085ef8491d1fee}
Insane in the Membrain
Description
Call solve(program="><[]+-,.")
to provide a BrainSuck program
that can add sequences of bytes that end in a null byte.
For example:
Input (hex): “010200”. Output (hex): “03”
Inputs and outputs are treated as byte values - not ASCII and not hex-encoded
Solution
This challenge uses the language “Brainfuck”, which is a language that is essentially just a Turing Machine.
Character | Meaning |
---|---|
> | Increment the data pointer (to point to the next cell to the right). |
< | Decrement the data pointer (to point to the next cell to the left). |
+ | Increment (increase by one) the byte at the data pointer. |
- | Decrement (decrease by one) the byte at the data pointer. |
. | Output the byte at the data pointer. |
, | Accept one byte of input, storing its value in the byte at the data pointer. |
[ | If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command. |
] | If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command. |
I used this online interpreter to help debug my code.
The code to solve this challenge is below:
Running solve(">,<,[[>+<-],]>.")
returns the flag.
Flag
CTF{771bce26ac7b238bbb6220cd795501d2f547a3ba1ca235f1}