First of all lets download the binary, chmod +x flag, and check its architecture type and run it.
$ file flag
flag: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, no section header
$ ./flag
I will malloc() and strcpy the flag there. take it.
So as we can see the binary itself doesn’t do much, accepts no input, just ouput exactly what will it be doing.
Lets hop into GDB and see how is it working, you can use Ghidra/IDA as well but lets just stick to GDB as of now, you’ll see in a while why!?!
gef➤ disas main
No symbol table is loaded. Use the "file" command.
gef➤ file flag
Reading symbols from flag...
(No debugging symbols found in flag)
gef➤ info functions
All defined functions:
gef➤ info variables
All defined variables:
There is nothing in the file, this is very odd! No main function, no _entry function, no variables. STRANGE
The only possible explanation of this behavior is, that this binary has been packed with some packer to strip out all the information. We can check which packer has been used using a tool called DetectItEasy
As we can see in the disassembly, at 0x0000000000401184, some value is being moved into the $rdx register and is marked with a comment of flag as well. Lets put a breakpoint at *main+39 so that we can inspect $rdx register and get the value of the flag.
gef➤ b *main+39
Breakpoint 1 at 0x40118b
...
gef➤ x/s $rdx
0x496628: "UPX...? sounds like a delivery service :)" # FLAG
We got our flag. However, we used few tools like GDB and DetectItEasy to understand the binary better, these could have been easily avoided and simple strings could have been used to solve this challenge.
$ strings flag | grep UPX
UPX!
$Info: This file is packed with the UPX executable packer http://upx.sf.net $
$Id: UPX 3.08 Copyright (C) 1996-2011 the UPX Team. All Rights Reserved. $
UPX!
UPX!
... Unpack the binary ...
$ string flag-unpacked-upx | grep UPX
UPX...? sounds like a delivery service :)
So, there were multiple ways to solve this binary, however, for the strings method you’d have to go through the strings output manually and search for interesting strings to understand that it has been packed using UPX and then again go through the strings output of the unpacked binary to get the value of the flag.