Cisco-Talos / pyrebox

Python scriptable Reverse Engineering Sandbox, a Virtual Machine instrumentation and inspection framework based on QEMU
https://talosintelligence.com/pyrebox
GNU General Public License v2.0
1.65k stars 248 forks source link

How to debug the scripts? #92

Closed vancaho closed 5 years ago

vancaho commented 5 years ago

Hi, I want to write a script for pyrebox. Because the function is a little complex, so I want to debug it when special activity happens in the guest machine. Is there a way to break the execution of the script and then retrive some values of the variables? Thanks very much.

xabiugarte commented 5 years ago

Hi @vancaho , you can try by adding the following two lines at the point where you want to stop your script:

import pdb
pdb.set_trace()

That will open a python debugger.

Another option, if what you need is to run pyrebox commands, is to add the following two lines:

from ipython_shell import start_shell
start_shell()

This second alternative will spawn an ipython shell in an environment where you can read guest memory and registers, execute pyrebox commands, or to use any of the python API functions exported by pyrebox.

Hope this helps,

Xabier.

vancaho commented 5 years ago

Can I use a IDE e.g. PyCharm to debug it?

xabiugarte commented 5 years ago

I never did it, but did you try this? https://blog.jetbrains.com/pycharm/2015/02/feature-spotlight-python-debugger-and-attach-to-process/

vancaho commented 5 years ago

After some work on Pycharm, I can debug the scripts with pycharm. From the [Run] menu, choose the [Edit configuration], then click "+" button and choose 'python remote debug'. From the dialog box, we can see instructions for remote debugging. Follow the instructions in the dialog, then we can debug the scripts. We can refer the following url https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html

xabiugarte commented 5 years ago

Hi,

I'm glad you found the solution!