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

Wrong implementation in rop.migrate() #879

Closed
bruce30262 opened this issue Feb 4, 2017 · 2 comments
Closed

Wrong implementation in rop.migrate() #879

bruce30262 opened this issue Feb 4, 2017 · 2 comments
Labels
Milestone

Comments

@bruce30262
Copy link
Contributor

here's how pwntools create the ROP chain for stack migration (using the leave ; ret gadget):

    elif pop_bp and leave and len(pop_bp.regs) == 1:
        self.raw(pop_bp)
        self.raw(next_base - 4) # <-- what about x64 binary ?
        self.raw(leave)

As you can see it set the bp register to next_base-4, then use the leave;ret gadget to migrate the stack to next_base. This work in x86 binaries, but not in x64 binaries ( would have to be self.raw(next_base-8) not self.raw(next_base - 4) )

@zachriggle
Copy link
Member

99% of the ROP functionality only works on amd64.

If you make this change locally (to next_base - context.bytes), does the pivot actually work?

@zachriggle zachriggle added the bug label Feb 4, 2017
@zachriggle zachriggle added this to the Someday milestone Feb 4, 2017
@bruce30262
Copy link
Contributor Author

I found this bug when I was doing a CTF challenge, which I need to do stack migration in a x64 binary.
If I use the original function (rop.migrate(buf)), it will migrate the stack to the wrong address, causing the exploit crash the program. I ended up writing my own function to make the exploit work, something like:

def migrate(buf):
    rop.raw(pop_rbp)
    rop.raw(buf-0x8)
    rop.raw(leave)

So yes I think if we change it to next_base - context.bytes if will migrate the stack to the right position ( at least for x86 & x64 binary )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants