Showing posts with label english. Show all posts
Showing posts with label english. Show all posts

2016-07-11

How to "hello world" Legacy Kernel Driver

How to "hello world" Legacy Kernel Driver


Preinstalled

  1. Visual Studio 2013
  2. WDK 8.1
  3. Windows 2012 R2
  4. Debug View



Step

  1. start Visual Studio.
  2. Click on the FILE > NEW > Proejct. then Pop up a ‘new Project’ wizard.
  3. Choose the visual C++  > Windows driver > Empty WDM driver Project.
  4. You could see the two projects on the solution explorer, The one is your own name, and the ohter one is package project for your driver
  5. Select ‘Source files’ on the Solution Explorer that in the right side.
  6. Click Mouse right button and click ‘add’ > ‘new item’. then Pop up a ‘new file’ wizard.
  7. Choose the visual C++  > C++ file.
  8. Copy a following basis of source code, and paste it on the ‘ new c++ file’ that you have created.
helloworld.cpp
#include <ntddk.h>


VOID Unload(
_In_ struct _DRIVER_OBJECT *DriverObject
)
{
UNREFERENCED_PARAMETER(DriverObject);

DbgPrintEx(DPFLTR_DEFAULT_ID, 0xFFFFFFFF, "GoodBye Windows Kernel\n");

return;
}

NTSTATUS DriverEntry(
_In_ struct _DRIVER_OBJECT *DriverObject,
_In_ PUNICODE_STRING       RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER(RegistryPath);

DbgPrintEx(DPFLTR_DEFAULT_ID, 0xFFFFFFFF, "Hello Windows Kernel\n");

DriverObject->DriverUnload = Unload;


return status;
}

  1. Select a build platform and a architecture, then run ‘build’
  2. As a result you can see  the driver file that named end with .sys in ther subfolder of your project’s location.
  3. Remeber file’s full path or copy it to root folder.
  4. For the test, first , you register driver as a service simply.
Resigist a driver as a service.
sc create helloworlddriver binpath=D:\helloworld.sys type=kernel

  1. Run debugview app to see kernel messages from your driver by a ‘DbgPrintEx’.
    (Turn on the capture kernel function.)
  2. Start and stop your own driver.
Start a driver service.
sc start helloworlddriver

Stop a a driver service.
sc stop helloworlddriver


  1. Now, Confirm it worked well on the debugview.
    ng.PNG
  2. Finally, ungister the your driver.
Unresigist a driver
sc delete helloworlddriver




2016-06-30

How to Windows Kernel debugging between Virtual marchine with Network

How to Windows Kernel debugging between Virtual marchine with Network .


Test Setting

Debugger and Debugee have same settings.

  1. Windows 2012 R2
  2. Visual Studio 2013
  3. WDK 8.1
  4. 1 - NIC


Basically, Kernel debugging dodel is a diagram that is following <fig .1>.


<fig .1>

Therefore, It needs 2 PCs or 2 VMs for debugging, and it has to be connected by Network  each o other.
And, Network kernel debugging is suppored by WDK 8 and later..
However, Despite of Supprting formally, From the ‘msconfig’ GUI wizard , it does not choose ‘NET’ mode…
ㅜ.,ㅜ….


But, It became more simpler than using a serial port.
hoooray~.

Steps for the Debuggee



  1. Setting up the debug mode with a network address , then Run commands next..
bcdedit /debug on
bcdedit /dbgsettings net hostip:192.168.2.8 port :50000
※  A parameter hostip means address of ‘Debugger’ that is connected with ‘Debugee’.
※ A command returns Key and you should to note or rememeber that key.
※ And, you are going to see your debug settings with following command.
(bcdedit /dbgsettings)


  1. and Reboot


Steps for The Debugger

  1. Start  a Windbg.
  2. Click on the File > ‘Kernel Debug’
  3. Move on ‘NET’ tab of the popup window.
  4. Enter value of  port and Key you memo. ( ex . sdkjhs8sjhdksjd87sdjhksjdnnjhskd9sdks)
  5. Click ‘OK’
  6. It will printed “Waiting connect..” .

    If it still connecting…
  7. Reboot debuggee , and click on the Debug > break .

    After it is connected, you want to boot debugee continually.
  8. Click on the Debug > go.


How to start Windows Kernel debugging on Virtual marchine with Serial port

How to start Windows Kernel debugging on Virtual marchine with Serial port .

Test Setting
Debugger and Debugee have same settings.

  1. Windows 2012 R2
  2. Visual Studio 2013
  3. WDK 8.1
  4. 1 NIC
  5. 1 Serial port

Basically, Kernel debugging dodel is a diagram that is following <fig .1>.

<fig .1>


Therefore, It needs 2 PC for debugging.

Steps for the Debuggee

In other word, Debuggee is called “Target PC”.
  1. Power off  the VM (debuggee).
  2. VM Workstation > Setting> click ‘add…’ > click ‘Serial port’
  3. Choose ‘Named Pipe’ and Enter a pipe name with format. ( ex ‘\\.\pipe\debug’)
  4. Choose “this is … server “ for the near end.
  5. Choose “this is … Application” for the Far end.
  6. Dselect the “Yield on CPU Poll” on the check box
  7. Click ‘ok’ ( Remeber new added serial Port Number )
  8. Power on the VM.

    After booting
  9. Open ‘Device Manager’
  10. Expand the ports that is tree item.
  11. Confirm the new serial port  that you added is working nomally.
    (Recommend to use view menu ‘hidden device show’.
  12. Check the Properties if it is corrent value or not when you had added a new serial port.
  13. Setting up the debug mode with a serial port you made before a step.
bcdedit /debug on
bcdedit /dbgsettings serial debugport:2 baudrate:115200

※ And, you can see your debug settings with following command.
(bcdedit /dbgsettings)

  1. and Reboot.




Steps for The Debugger

  1. Start  a Windbg.
  2. Click on the File > ‘Kernel Debug’
  3. Move on ‘COM’ tab of the popup window.
  4. Enter value a pipe name on port. ( ex ‘\\.\pipe\debug’ - you entered before )
  5. Select the ‘pipe’ check box, then click ‘OK’
  6. It will printed “Waiting connect..” .

    If it still connecting…
  7. Reboot debuggee , and click on the Debug > break .

    After it is connected, you want to boot debugee continually.
  8. Click on the Debug > go.