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

Adding support for FileStructure exploitation #1218

Merged
merged 4 commits into from
Dec 9, 2019

Conversation

vigneshsrao
Copy link
Contributor

This is in reference to #1217.

The functioning of this class is similar to srop.py. One has to create an object of this class and then assign member variables, similar to the C fashion. The python class basically emulate's the C FILE structure and makes it easier to write payloads for exploiting the FILE structure. It also includes methods to generate payloads for some standard cases like arbitrary read and write. Only amd64 and i386 architectures are supported currently.

The python file itself contains a full documentation. Please refer here for a detailed overview of the features.

@zachriggle
Copy link
Member

Overall this looks good, and most of the heavy lifting is done! Cool stuff!

I've added some comments about convention (self.arch vs context.arch, general code style (e.g. number of spaces), tests (needs more and better tests), and documentation (no functions or methods have docs).

If you can clean this up a bit, we can get this merged!

var['unknown2']=48
return var

def packit(s,l=8):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation and tests

var[i]=null
return var

def update_var(l):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation and tests

'_wide_data'
]

def get_defaults(null):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is wrong here. I'd recommend looking at collections.defaultdict to avoid the need for this.

>>> fileStr.flags = 0xfbad1807
>>> fileStr._IO_buf_base = 0xcafebabe
>>> fileStr._IO_buf_end = 0xfacef00d
>>> payload = str(fileStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should show what the payload looks like, so that there are actual tests.


>>> context.clear(arch='amd64')
>>> fileStr = FileStructure(0xdeadbeef)
>>> payload = fileStr.read(addr=0xcafebabe, size=100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show the payload

self['fileno'] = 1
return self.struntil('fileno')

def read(self,addr=0,size=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs and doctests

break
return structure[:len(structure)-1]

def write(self,addr=0,size=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs and doctests

def set_vars(self,item,value):
self[item]=value

def struntil(self,v):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs and doctests

structure=''
for val in self.vars_:
if isinstance(self[val],str):
if self.arch=='i386':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use self.arch, use context.arch

return structure[:len(structure)-1]

def write(self,addr=0,size=0):
self['flags'] &=~8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're inheriting from dict in order to set these fields.

Just use regular fields, i.e. self.flags, self._IO_write_base, etc.

This way these fields can be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we remove the inheritance from dict altogether? Or should we just add documentation for the various fields?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any places we leverage the dict inheritance other than to set self['field'] = value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While setting the default data we update the dict. Also, the str and struntil functions involve checking the type of the value of each key, while iterating through the list of fields. I am not quite sure how we can iterate through the list of fields while checking the type of the value they hold if all the fields are set as independent class attributes.

@zachriggle
Copy link
Member

zachriggle commented Nov 1, 2018 via email

@vigneshsrao
Copy link
Contributor Author

Neat! Did not think of this before. I'll make the necessary changes as soon as possible. Thanks a lot!

@vigneshsrao
Copy link
Contributor Author

Completed the necessary changes.

@orenht
Copy link

orenht commented Apr 25, 2019

Hi, are there any plans on getting this merged? :)

@vigneshsrao
Copy link
Contributor Author

@zachriggle Are there any more changes to be made to the code?
If not can this be merged?

@Arusekk Arusekk merged commit 59c7810 into Gallopsled:dev Dec 9, 2019
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

Successfully merging this pull request may close these issues.

4 participants