Quantcast
Channel: 看雪安全论坛
Viewing all articles
Browse latest Browse all 9556

【求助】还没转正,写第一个驱动遇到问题

$
0
0
网上的一个例子, 环境 VS2010 WDK 7600.16385.1 求助,谢谢。

错误 1 error LNK2019: 无法解析的外部符号 __imp__MmGetSystemRoutineAddress,该符号在函数 "long __cdecl DriverEntry(struct _DRIVER_OBJECT *,struct _UNICODE_STRING *)" (?DriverEntry@@YAJPAU_DRIVER_OBJECT@@PAU_UNICODE_STRING@@@Z) 中被引用 D:\我的文件\2013\06\MyApp\MyApp\Test2.obj MyApp



代码:

#include <ntddk.h>
#include <windef.h>
#include <ntimage.h>


#pragma comment(lib, "Ntoskrnl.lib")

ULONG JmpAddress;//跳转到NtOpenProcess里的地址

typedef NTSTATUS (*NTOPENPROCESS)(PHANDLE ProcessHandle,
                ACCESS_MASK DesiredAccess,
                POBJECT_ATTRIBUTES ObjectAttributes,
                PCLIENT_ID ClientId);

NTOPENPROCESS MyNtOpenProcess;
//PVOID MyNtOpenProcess;
VOID Unload(IN PDRIVER_OBJECT DriverObject)
{

DbgPrint("release the hook!\n");
};

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{

        DbgPrint("add the hook!\n");


  ULONG  Address;
  UNICODE_STRING UniCodeFunctionName;
  RtlInitUnicodeString( &UniCodeFunctionName, (PCWSTR)"NtOpenProcess" );
  MyNtOpenProcess = (NTOPENPROCESS) MmGetSystemRoutineAddress( &UniCodeFunctionName );//得到SSDT地址,不过该地址有可能被钩去了
  // KdPrint(("取得原函数NtOpenProcess 的值为 %x",MyNtOpenProcess));
  JmpAddress = (ULONG)MyNtOpenProcess + 10; //跳转到NtOpenProcess函数头+10的地方,这样在其前面写的JMP都失效了
  __asm
  {
    //去掉内存保护
    cli
          mov  eax,cr0
    and  eax,not 10000h
    mov  cr0,eax
 
  pushad
   
    push    0C4h
    push      804db4h//在本机就是这个值
    //共十个字节
    jmp      [JmpAddress]    ;//HOOK SSDT
    popad
    //恢复内存保护
    mov  eax,cr0
    or    eax,10000h
    mov  cr0,eax

    sti
  }
 
DriverObject->DriverUnload=Unload;
return STATUS_SUCCESS;
}


Viewing all articles
Browse latest Browse all 9556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>