Comment on Pyrasite - Inject code into a running Python processComments−onedognight14yTL;DR The code is mostly this with a nice wrapper. gdb_cmds = [ 'PyGILState_Ensure()', # Allow payloads to import modules alongside them 'PyRun_SimpleString("import sys; sys.path.insert(0, \\"%s\\");")' % os.path.dirname(self.filename), 'PyRun_SimpleString("execfile(\\"%s\\")")' % self.filename, 'PyGILState_Release($1)', ] self._run('gdb -p %d -batch %s' % (self.pid, ' '.join(["-eval-command='call %s'" % cmd for cmd in gdb_cmds])))
Comments
TL;DR The code is mostly this with a nice wrapper.