Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ret2csu with PIE binaries #2158

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions pwnlib/rop/rop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,23 +1544,18 @@ def ret2csu(self, edi=Padding('edi'), rsi=Padding('rsi'),
# Prioritise non-PIE binaries so we can use _fini
exes = (elf for elf in self.elfs if not elf.library and elf.bits == 64)

nonpie = csu = None
csu = None
for elf in exes:
if not elf.pie:
if '__libc_csu_init' in elf.symbols:
break
nonpie = elf
elif '__libc_csu_init' in elf.symbols:
if '__libc_csu_init' in elf.symbols:
csu = elf
if not elf.pie:
break

if csu:
elf = csu
else:
log.error('No non-library binaries in [elfs]')

if elf.pie:
if nonpie:
elf = nonpie
elif csu:
elf = csu

from .ret2csu import ret2csu
ret2csu(self, elf, edi, rsi, rdx, rbx, rbp, r12, r13, r14, r15, call)

Expand Down
Loading