De1CTF 2019 Mine Sweeping Writeup
This is my writeup for the Mine Sweeping
challenge. This challenge was part of De1CTF 2019.
The files for this challenge might be still available on ctftime so you can also give it a try if you want.
For this challenge we had access to an archive containing a game made in Unity and its dependencies (DLLs and assets). At a first glance, the game looked like the classic minesweeper (That was probably expected with that title). Also, I couldn’t find any stated goal or objective that would lead me to the flag so I assumed that I probably have to finish/win the game in order to get the flag.
Because the game was created using Unity my first thought was to decompile it using dnSpy. As reverse isn’t my thing (yet…) I couldn’t get any code by doing this.
Also, some quick static analysis performed on the game files did not reveal anything useful.
My next approach was trying to see if I find any useful information by playing the game for a bit. It is the minesweeper game that I’m already familiar with but it looks like there are quite a lot of mines. Sadly, I was never good at minesweeper.
After a few attempts at playing the game I noticed that the layout of the game board is always the same. This meant that I could memorize where the mines are by playing multiple times and than do a perfect run using the memorized location.
Or I could write a script for that …
The only tool that I knew about with for writing a script that interacts with desktop apps was AutoIt.
I used the helper tool that comes with AutoIt to get the coordinates for the top-left cell from the game board and also to estimate what is the distance between two cells.
The script that I created can be seen below.
autosweep_explore.au3 (click to expand)
This should click on each cell, check if the yellow ‘Game over’ message appeared and mark the result with a 0 (mine) or 1 (safe) in a csv file.
This part worked really well so I created a second autoit script that would play the game using the data from the csv file. That script can be seen below.
autosweep_play.au3 (click to expand)
After running the second script, I quickly realized that I made some mistakes on the first one and as a result I got most of the cells that were covered by the yellow ‘Game over’ message wrong (almost all of them were marked as empty even if they were not). This was probably the result of a timing error; I suspect that the program was not resetting the game after the ‘Game over’ message appeared by clicking on a regular cell that was not covered by that message.
However, when I took at the csv file in a text editor I noticed something.
It looks similar to a QR code (look at the corners). And qr codes are quite resilient so even if a part of them was damaged they can still be read.
Maybe that’s where the flag was hidden so I wrote a very quick python script to convert the 1s and 0s to a PNG file that I could scan more easily.
draw_qr.py (click to expand)
The result was a QR code that was a bit damaged in the center, as expected. It was only 29x29 pixels so I had to magnify it a bit to make it easily readable. This can be easily done using an image viewer like nomacs (open-source) or an image editor.
The QR code that was obtained by me can be seen below.
Reading the QR code got me the following URL http://qr02.cn/FeJ7dU
.
After accessing the URL using a browser I was redirected to another page that contained the flag.