REinject's Blog

No matter how good our kung fu is, it can't beat guns


ret2csu

ret2csu is a technique that leverages code gadgets found in glibc’s __libc_csu_init function for ROP (Return-Oriented Programming) attacks. It’s commonly used to bypass certain restrictions, such as disabled syscalls, RELRO, or when longer gadget chains are needed.

In practice, it typically refers to using the register initialization and restoration instruction sequences at the beginning and end of functions. These instruction sequences serve the following purposes:

  1. Set registers
  2. Call arbitrary functions
  3. Pass arguments
  4. Adjust the stack

For shorter gadgets, you can use pwntools for quick searching. For example, to find a ‘pop rdi\nret’ gadget:

from pwn import *

context.arch = 'amd64'

elf = ELF("./canary")

print(hex(next(elf.search(asm('pop rdi\nret'), executable=True))))

Related challenges: