Windows Kernel Debugging
Introduction
Kernel debugging isn’t that much different than user-mode debugging from my experience, it just requires more setup and you can’t (or shouldn’t) do it locally. Here’s a high-level overview of what you need to do:
- Create a Windows VM - preferably hosted on Hyper-V
- Install WinDBG on host computer and KDNET on VM
- Enable debug mode and test-signing
- Set-up KDNET
- Attach WinDBG to VM kernel
- Load & Run driver
- Optional: Apply a mask to see appropriate
DbgPrint()
messages
- Optional: Apply a mask to see appropriate
Getting WinDbg
Installing WinDBG will be the easiest part of this tutorial (if you are running Windows locally). Microsoft released an new and improved version of WinDBG (thankfully) that can be easily installed through the Microsoft Store.
All you need to do is:
- Open Microsoft Store
- In the search bar, enter “WinDbg”
- Press install
It should look like this when you’re done:
Installing KDNET
This is where things start becoming a little tricky (not too bad though).
Troubleshooting Tricks
If WinDBG is unable to connect to KDNET on your VM here are some things to try:
-
ENABLE ICMP (ping) traffic inbound on the firewall
- By default, Windows blocks ICMP (ping) packets. Not sure why, but it does.
- Verify you can ping the VM:
ping <VM IP>
- If you can’t, it’s probably one of two things:
- Your VM isn’t on the correct network - change the VM’s network adapter
- Ping is probably blocked by the VM’s firewall (see [1] )
- If you can’t, it’s probably one of two things:
Loading & Running the Driver
I will come back and flesh this out more, but basically you need to create a service and start the service from an Administrator command prompt. You will need to create a kernel service:
C:\> sc create [service name] binPath= C:\path\to\driver type= kernel
This should say something along the lines of “SUCCESS”
Then to start the driver, run:
C:\> sc start [service name]
If any errors occur when the service starts (mostly permissioning or FILE NOT FOUND), it will tell you. In other words - No output, is good output. If you’re concerned about whether the driver is currently loaded/running, run this command: sc query [service name]
.