Welcome2Pwn!
~# cat Question
What better way to learn pwn than to go on a trip to the beach? (Because there are shells!)
welcome.c
The challenge provided a file that contained a buffer overflow vulnerability. The goal is to exploit this vulnerability to execute the shellz
function, which copies the stuff
array into the code
buffer and then executes the contents of code
as shellcode.
The program defines a global
stuff
array and a globalcode
pointer.The
shellz
function copies the contents ofstuff
into the memory pointed to bycode
and then executes it as shellcode.In the
main
function, the program sets up abuf
buffer and maps thecode
buffer as executable memory usingmmap
.The program reads input into the
stuff
array andbuf
buffer usingfgets
.
Exploiting
The goal is to overflow the buf
buffer in such a way that we overwrite the return address of the main
function with the address of the shellz
function. This will cause the program to return to shellz
instead of returning to main
, effectively executing our shellcode.
Crafting the Payload:
We need to send a payload that overflows the
buf
buffer and overwrites the return address with the address ofshellz
.
Finding the Offset:
We use cyclic input to find the offset at which the return address is overwritten.
Crafting the Final Payload:
We craft a payload that includes padding to reach the return address and the address of
shellz
.
Analysis of the script
The script starts a process for the challenge binary and uses the
ELF
class from thepwn
library to get information about the binary.It crafts a shellcode using assembly instructions for a
execve("/bin/sh", NULL, NULL)
syscall.It sends the shellcode to the program to populate the
stuff
array.It calculates the padding required to reach the return address and crafts a payload with the padding and the address of
shellz
.Finally, it sends the payload to the program, triggering the overflow and executing the shellcode.
Flag: LNC24{C0MPU73R_G0_brRrRRrRRRRRRrrRrRRRrRrRrRRrRRrRRRRRrRrR}
Last updated