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

rop.syscall attribute fails to find syscall gadget #1326

Closed
nbulischeck opened this issue Jul 24, 2019 · 3 comments
Closed

rop.syscall attribute fails to find syscall gadget #1326

nbulischeck opened this issue Jul 24, 2019 · 3 comments
Labels
help-wanted rop Return Oriented Programming manipulation routines

Comments

@nbulischeck
Copy link

This line fails to find valid syscall gadgets. I'm not 100% sure if that for loop is a valid solution.

if self.gadgets[each]['insns'] == [mapping[attr]]:

>>> binary = ELF.from_assembly('syscall; ret')
>>> rop = ROP(binary)
>>> rop.syscall # No result
>>> [rop.gadgets[gadget] for gadget in rop.gadgets if 'syscall' in rop.gadgets[gadget]['insns']]
[Gadget(0x10000000, [u'syscall', u'ret'], [], 0x4)] # Syscall gadget
@Arusekk Arusekk added the rop Return Oriented Programming manipulation routines label Jan 22, 2020
@saullocarvalho
Copy link
Contributor

How can I help to fix this issue?
While reproducing the steps provided by @nbulischeck , I got the following:

>>> elf = ELF.from_assembly('syscall; ret')
>>> rop = ROP(elf)
>>> rop.syscall
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hunter/app/pwntools/pwnlib/rop/rop.py", line 1398, in __getattr__
    if self.gadgets[each]['insns'] == [mapping[attr]]:
  File "/home/hunter/app/pwntools/pwnlib/rop/gadgets.py", line 57, in __getitem__
    if isinstance(key, six.integer_types):
NameError: name 'six' is not defined
>>> rop.gadgets.items()
dict_items([(268435458, Gadget(0x10000002, ['ret'], [], 0x4)), (268435456, Gadget(0x10000000, ['syscall'], [], 0x0))])

pwnlib/rop/gadgets.py is missing import six. This is easy to fix.

Regarding the original issue, should the syscall gadget have only the syscall instruction or should insns also include ret?

@saullocarvalho
Copy link
Contributor

ROPgadget is returning the syscall gadget and the gadget does not follow the instructions until it reaches a ret. That seems odd to me.

@Arusekk
Copy link
Member

Arusekk commented Oct 31, 2020

Fixed in #1678 and #1682.

@Arusekk Arusekk closed this as completed Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted rop Return Oriented Programming manipulation routines
Projects
None yet
Development

No branches or pull requests

4 participants