gogo
Problem
Hmmm this is a weird file... enter_password. There is a instance of the service running at
mercury.picoctf.net:48728
.
Solution
We can decompile the program using Ghidra and check out the
main
functions. There is acheckPassword
function, which is shown below:The
checkPassword
function runs a loop that XORs two characters and compares the result to another variable. The loop in assembly is shown below:We can use GDB and set a breakpoint at
0x080d4b28
so we have access to the values that our input is XORed with and the values that the result of the XOR operation is compared with.We launch the program in gdb with
gdb ./enter_password
and create the breakpoint withb* 0x080d4b28
. We run the program withr
and enter 32a
s since the decompiled code shows that the loop runs0x20
times. You can generate a string of 32a
s for copy-pasting by runningpython -c "print('a'*32)"
. According to the disassembly, our input should be at$ecx
. If we runx /32 $ecx
, sure enough we see our input:The values that our input is XORed with are at
$esp+0x4
and the expected values are at$esp+0x24
:Now, we can XOR these two values to get the input because if
x ^ y = z
theny ^ z = x
, wherex
is the input ($ecx
),y
are the values that the input is XORed with ($esp+0x4
), andx
are the expected values ($esp+0x24
). We can use CyberChef to compute the XOR between3836313833366631336533643632376466613337356264623833383932313465
and4a53475d414503545d025a0a5357450d05005d555410010e4155574b45504601
to getreverseengineericanbarelyforward
as the output.Let's run the program normally with
./enter_password
and enterreverseengineericanbarelyforward
for the password:We need an unhashed key. The value that the input is XORed with at
$esp+0x4
converted from hex to ascii looks like a hash:861836f13e3d627dfa375bdb8389214e
. I noticed this while building the CyberChef recipe for decoding the password. If we paste this into CrackStation we find that it is the md5 hash forgoldfish
. If we enter the password and then type ingoldfish
for the unhashed key, the program will read theflag.txt
file.Connect to the web service with
nc mercury.picoctf.net 48728
, sendreverseengineericanbarelyforward
for the password andgoldfish
for the unhashed key to get the flag:
Flag
picoCTF{p1kap1ka_p1c0b187f1db}
Last updated