Showing posts with label debuger. Show all posts
Showing posts with label debuger. Show all posts

Sunday, March 11, 2007

Ring 0 Debuger

Add to Del.icio.us

One of the first useful things you will want to do when in the bowels of ring 0 is attack the thing from a debugger point of view. In my case I like using Windows Debugger [windbg] (hey its free, fully functional and does remote debugging really well), and found it neccessary to find a way to have it work with VMWare.
The trick to get it to work in VMWare is to get the host OS to believe it is able to connect to a serial port. Through VMWare, to accomplish this, you need to create a named pipe. The following steps will guide you to configuring VMWare

  1. Open the virtual machine
  2. Click "Edit virtual machine settings"
  3. On the hardware tab click "Add"
  4. Select a "Serial Port"
  5. Select "Output to named pipe"
  6. Set the name to "\\.pipe\com_1".
  7. Select "This endi is the server"
  8. Select "The other end is a application" and click next
  9. Activate the option "Yeld CPU on pool" This is an important step as the Kernel in the target virtual machine uses the port in polled mode, not interrupt mode.
  10. Check if everything is OK. It should look like this
  11. Start the virtual machine
  12. Once you have configured your VMWare session, you need to power it on. You will be able to confirm that the new virtual serial port is added by clicking on the Devices->serial0 menu item. You should note it is saying "Connecting". This means its now ready for a remote connection.

    Once the actual virtual machine is configured, you need to configure the target operating system installed in the virtual machine to support remote debugging. This is accomplished by editing the boot.ini found in the root of the C:\ drive. To do this, you need to add a

    /debugport=some_com_port /baudrate=some_baud_rate
    to the end of an [operating systems] line. I would not recommend doing it to the one that is there. It would be better to copy the line and paste it with the ammendments, and then use the OS's menu selection to determine which mode you would like to boot into. This is what my boot.ini looks like for XP Pro as the operating system in the virtual machine:


    [boot loader]
    timeout=30
    default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows" /fastdetect /debug /debugport=COM1 /baudrate=115200
    multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /fastdetect


    You will notice that the second option sets the debugport to com1, and sets the baudrate to 115200. I am told you can tweak this out to get even more speed out.


  13. If you set up your boot.ini fine, save it and reboot. You should be prompted with something that looks like this:
  14. At this point you have completed setting up the VMWare side of things. Now you need to set up the host to connect to it. This is actually rather easy. You just need to tell windbg at the command like to connect to the pipe, like this:

    windbg -k com:port=\\.\pipe\com_1,pipe
    If you are using WinDbg 6.x or newer, a better alternative is to use:
    windbg -b -k com:pipe,port=\\.\pipe\com_1,resets=0
  15. Enjoy