[PROTIP] Get an Interactive Python Shell in Peach
by sirus on Sep.30, 2010, under Code, Fuzzing
Peach being the monolith that it is, breaks most python debugging tools. As such it makes debugging pit files extremely difficult. I came across the RC of the IPython interactive shell and found that it can actually handle breaking in the middle of cracking input in peach!
Download and install IPython 0.10.1.rc1.
Create a code-behind file for peach with this simple function:
import inspect,IPython
def db():
uframe = inspect.currentframe().f_back
return eval('IPython.Shell.IPShellEmbed([])()', dict(globals().items() + uframe.f_globals.items()),uframe.f_locals)
Now anywhere you have an evaluated field you can execute a db() call and break into a python shell with the full context so you have access to the cracker and the DataEmelent! A great feature of IPython is that is also has tab autocompletion and element inspection.
And here is some example usage:
<Import import="*" from="peach_debug"/>
...
<DataModel name="SampleModel">
<Number name="foo">
<!-- always break -->
<Relation type="when" when="db() or True" />
</Number>
<Blob name="bar">
<!-- always break but maintain a conditional so parsing continues -->
<Relation type="when" when="( db() and False) or int(self.find('foo').getInternalValue()) & 0x1 == 0x1" />
</Blob>
<Blob name="bas">
<!-- break only on specific conditional -->
<Relation type="when" when="( int(self.find('foo').getInternalValue()) == 0x03 and db()) or True" />
</Blob>
</DataModel>
Once you are in the IPython shell try the following:
self?
self??
self.getInternalValue()
self.parent?
self.find('foo')
self.find('foo').getInternalValue()
To break out of the shell and resume execution of peach press Ctrl+Z.
3 Comments for this entry
1 Trackback or Pingback for this entry
-
Tweets that mention [PROTIP] Get an Interactive Python Shell in Peach | haxsys.net -- Topsy.com
September 30th, 2010 on 2:08 PM[...] This post was mentioned on Twitter by Tom Ferris, Mikhail Davidov. Mikhail Davidov said: [BLAHG] Protip: Getting an interactive shell in Peach to debug your fuzzer http://bit.ly/dh6P0b [...]
September 30th, 2010 on 1:33 PM
Hi thanks for this a little good post. But I still don’t get the second part though!
October 3rd, 2010 on 6:00 AM
Hey thanks for yet another very interesting post. Where do you find your inspiration for all this
?
February 13th, 2011 on 6:51 PM
Do you have an detailed guide about how to use it? I’m not quite catch you.