The subject tells us that this is a buffer overflow challenge. The goal of a buffer overflow is to fill the stack to overwrite a part of the memory that is not supposed to be written. This can lead to a remote code exploitation.
Let's check the file information to see what king of file we are facing to.
We see that the file is a elf64, we will reverse it to understand what the program is doing when running. Some rule have to be known before getting into elf64:
Displaying the strings give us some interesting information such as "/bin/sh" which is located at the address 0x2008. This can be useful if we need to pass /bin/sh in a argument of a function like system().
From the functions, we got the main function address, and other function that can potentially tell us that the vulnerability is located there. (vuln function should be interesting to check).
Looking at the function calls, we have a printf, then a flush, then a gets, vuln, and finally a puts.
In the vuln function, it will symply open a shell, the "/bin/sh" is passed as argument in the function system().
We set two breakpoint at [main+18] and at the instruction ret to calculate the memory space taken by the stack frame.
After reaching the first breakpoint, we can print the stack by printing the register $rsp. In this case $rsp = 0x7fffffffe240.
After the leave instruction, the $rsp = 0x7fffffffe278. So we can calculate the offset before writing outside of the stack frame.
It works ! Time to execute it on the remote machine through netcat.