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

FmtStr has some problems #1139

Closed
matrix1001 opened this issue Apr 18, 2018 · 2 comments
Closed

FmtStr has some problems #1139

matrix1001 opened this issue Apr 18, 2018 · 2 comments

Comments

@matrix1001
Copy link

numbwritten does not work

def fmt(s):
    print repr(s)
f = FmtStr(fmt, offset=0)
f.write(0xdeadbeef,0x12345678)
f.execute_writes()
#result: '\xef\xbe\xad\xde\xf0\xbe\xad\xde\xf1\xbe\xad\xde\xf2\xbe\xad\xde%104c%0$hhn%222c%1$hhn%222c%2$hhn%222c%3$hhn'

f = FmtStr(fmt, offset=0,numbwritten=20)
f.write(0xdeadbeef,0x12345678)
f.execute_writes()
#result: '\xef\xbe\xad\xde\xf0\xbe\xad\xde\xf1\xbe\xad\xde\xf2\xbe\xad\xde%104c%0$hhn%222c%1$hhn%222c%2$hhn%222c%3$hhn'

apparently the result should be different .

bad char problem

def fmt(s):
    print repr(s)
f = FmtStr(fmt, offset=0)
f.write(0x080420,0x12345678)
f.execute_writes()
#result: ' \x04\x08\x00!\x04\x08\x00"\x04\x08\x00#\x04\x08\x00%104c%0$hhn%222c%1$hhn%222c%2$hhn%222c%3$hhn'

some char like '\x00' will terminate the printf!!!
better solution is to put address in the tail of the payload!

@matrix1001
Copy link
Author

matrix1001 commented Apr 18, 2018

I just checked the code. Found this in FmtStr:

    def execute_writes(self):
        fmtstr = randoms(self.padlen)
        fmtstr += fmtstr_payload(self.offset, self.writes, numbwritten=self.padlen, write_size='byte')
        self.execute_fmt(fmtstr)
        self.writes = {}

it shoul be fmtstr += fmtstr_payload(self.offset, self.writes, numbwritten=self.padlen+self.numbwritten, write_size='byte')

@zachriggle
Copy link
Member

Yep, the code is pretty limited in its utility. I had some prototype code to auto-solve and exploit format string bugs in a pull request but it was never completed.

Feel free to contribute a fix!

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

No branches or pull requests

3 participants