path=%2Fhome%2Fspwnce%2Fwww%2Fdocs%2Fexamples%2Fhello.spy
in the query stringpath=/flag1
, and browse itThe server will be returning an encrypted flag, , every time a player connects to the server. This is the public key used:
Note that the ciphertext is computed by a flawed ElGamal such that :
The goal is to obtain the flag, .
An important observation is that is not taken modulo , therefore it is a multiple of . If we get many ciphertexts , , … by connecting to the server for multiple times, eventually we have
We can use the Euclidean algorithm to compute the GCD of two numbers, given below:
To compute GCD of multiple numbers (), we can apply GCD pairwise:
After getting the number , we can convert it into a string. From chall.py
, the flag string is converted to a number by m = int.from_bytes(flag, 'big')
. You may want to look at how an reverse operation can be done using int.to_bytes
in Python.
🏁 I am not getting the flag! That means the m
you got is incorrect. It is likely that the GCD you obtained is a small multiple of the actual - go get more 's and compute GCDs further!
can_leave
is not 0 (but by reading the code, can_leave
is always 0?)scanf("%s", buf)
does not limit the length of user input, vulnerable to Buffer overflow attack
.printf(buf)
looks odd. Usually, printing out a string in c should be printf("%s", buf)
.Format string attack
.Format string attack
can potentially achieve arbitrary memory read
and arbitrary memory write
.Checksec
in gef, find out what protection methods are enabledget_shell
function is randomized.Buffer overflow attack
does not work unless we need the value of canary.Format string attack
to leak one PIE address (an address that is under the effect of PIE), then calculate the address of the get_shell
function. (The offset between the leaked address and the get_shell
function is fixed)Format string attack
to leak the canary value.Format string attack
to overwrite the value of can_leave
so that we can leave the loop and return from the main function (to trigger the Buffer overflow attack
).Buffer overflow attack
to overwrite the return address to the get_shell
function.get_shell
function to get the shell and cat the flag.So you can use many ways to do this, but maybe you want to look in the traffic first to get a feel of what it does.
To do so, we can setup a proxy in between to stiff all the traffic, and possibly modify the content.
What it means is that you setup an intermediate server (aka proxy) in between the game server,
so the game client interacts with the proxy, and the proxy interacts with the game server. By this way, the proxy view and modify the data sent by both sides.
You can use whatever tools to do it, for HTTP request, you can use mitmproxy
, but in here, a TCP proxy is better (with mitmproxy
may be annoying to setup).
One of the possible tools will be tcpproxy.
It will be something like this:
Then you can connect your chess client to the local proxy instead:
And you should see the traffic in between shown via the proxy.
After seeing the traffic, you should be able to see what the client send to the server, and vise versa.
You can also modify the data sent via some other module from tcpproxy, such as
You can see their source code on github to learn more about how it works.
If you try more, you will note not every modification works. What is the condition that make the replacement works? (Maybe related to the first few weird bytes?)
By this point you should be able to cheat by modifying the packets. Good luck!
Download sdcard.zip
, extract it and found sdcard.dd
. Put it into any digital forensic tool.
In the following writeup, I have used Autopsy for demostration. You will be able to find file named f0000000.png
under $CarvedFiles
.
In alternative, you may see that Autopsy can search files by entension. A file name _lag.png
can be found.
Both f0000000.png
and _lag.png
are the same picture but with different names. I have extracted f0000000.png
to continue my investigation.
If you are not using Autopsy, the image name may varies depending on the tool you used.
We found that the image can be opened but nothing show up.
And the EXIF seems does not match with the content size.
We may continue the investigation flow in either ways:
The file extension in PNG, so we decided to investigate the file as an corrupted image. You may read some inforatmion on PNG chuncks.
PNG © corkami, CC BY-NC-SA 2.0
We decided to put f0000000.png
into PNG file chunk inspector for investigation. Multiple IHDR chunk was found.
We know that a legal PNG image should contain only 1 IHDR chunck, we can open a Hex Editor to edit the image f0000000.png
.
I used HexEd.it for editing. You may wish to use HxD for the modification.
From the information from PNG file chunk inspector, we know that there are 2 option of IHDR chunck to remove:
The first check IHDR check (Byte 8 - 32) shows the image has 1 pixel. This is more spcious and we decided to remove it first. Note that an IHDR chunk should be exactly 25 bytes.
Once you have the first IHDR chunk removed, save the image and open it. You will be able to open the image now.
I have the partial image included in my writeup so that you should try the guide yourself.