找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 5559|回复: 7

终于找到了这两个地址,代码如下

 火.. [复制链接]

90

主题

473

回帖

2

精华

钻石会员

积分
3261
发表于 2010-8-30 09:57:49 | 显示全部楼层 |阅读模式
  1. #include <ntddk.h>
  2. #include "ntimage.h"
  3. #include "KernelVoid.h"
  4. VOID Unload(IN PDRIVER_OBJECT DriverObject)
  5. {
  6. }

  7. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
  8. {
  9. ULONG SSDT_NtOpenProcess_Addr;
  10. KdPrint(("驱动加载成功"));
  11. KvGetSSDTVoid("NtOpenProcess");
  12. DbgPrint("NtOpenProcess的原始地址1=%x/n.",KvGetSSDTVoid("NtOpenProcess"));

  13. _asm
  14. {
  15. push ebx
  16. push eax
  17. mov ebx,KeServiceDescriptorTable
  18. mov ebx,[ebx]
  19. mov eax,0x7a
  20. shl eax,2
  21. add ebx,eax
  22. mov ebx,[ebx]
  23. mov SSDT_NtOpenProcess_Addr,ebx
  24. pop eax
  25. pop ebx
  26. }
  27. KdPrint(("NtOpenProcess的当前地址=%x",SSDT_NtOpenProcess_Addr));

  28. DriverObject->DriverUnload = Unload;

  29. return STATUS_SUCCESS;
  30. }
复制代码

90

主题

473

回帖

2

精华

钻石会员

积分
3261
 楼主| 发表于 2010-8-30 10:00:25 | 显示全部楼层
本帖最后由 ok100fen 于 2010-8-30 13:59 编辑

别人的头文件,修改了一下名称,才可以
原来真要明白原理才行

  1. typedef struct ServiceDescriptorEntry{
  2. PVOID ServiceTableBase;
  3. PVOID ServiceCounterTableBase;
  4. ULONG NumberOfServices;
  5. PVOID ParamTableBase;
  6. } ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;

  7. typedef struct _SERVICE_DESCRIPTOR_TABLE{
  8. ServiceDescriptorTableEntry_t ntoskrnl; // ntoskrnl.exe (native api)
  9. ServiceDescriptorTableEntry_t win32k; // win32k.sys (gdi/user)
  10. ServiceDescriptorTableEntry_t Table3; // not used
  11. ServiceDescriptorTableEntry_t Table4; // not used
  12. }SERVICE_DESCRIPTOR_TABLE,*PSERVICE_DESCRIPTOR_TABLE;
  13. typedef enum _SYSTEM_INFORMATION_CLASS // Q S
  14. {
  15. SystemBasicInformation, // 00 Y N
  16. SystemProcessorInformation, // 01 Y N
  17. SystemPerformanceInformation, // 02 Y N
  18. SystemTimeOfDayInformation, // 03 Y N
  19. SystemNotImplemented1, // 04 Y N
  20. SystemProcessesAndThreadsInformation, // 05 Y N
  21. SystemCallCounts, // 06 Y N
  22. SystemConfigurationInformation, // 07 Y N
  23. SystemProcessorTimes, // 08 Y N
  24. SystemGlobalFlag, // 09 Y Y
  25. SystemNotImplemented2, // 10 Y N
  26. SystemModuleInformation, // 11 Y N
  27. SystemLockInformation, // 12 Y N
  28. SystemNotImplemented3, // 13 Y N
  29. SystemNotImplemented4, // 14 Y N
  30. SystemNotImplemented5, // 15 Y N
  31. SystemHandleInformation, // 16 Y N
  32. SystemObjectInformation, // 17 Y N
  33. SystemPagefileInformation, // 18 Y N
  34. SystemInstructionEmulationCounts, // 19 Y N
  35. SystemInvalidInfoClass1, // 20
  36. SystemCacheInformation, // 21 Y Y
  37. SystemPoolTagInformation, // 22 Y N
  38. SystemProcessorStatistics, // 23 Y N
  39. SystemDpcInformation, // 24 Y Y
  40. SystemNotImplemented6, // 25 Y N
  41. SystemLoadImage, // 26 N Y
  42. SystemUnloadImage, // 27 N Y
  43. SystemTimeAdjustment, // 28 Y Y
  44. SystemNotImplemented7, // 29 Y N
  45. SystemNotImplemented8, // 30 Y N
  46. SystemNotImplemented9, // 31 Y N
  47. SystemCrashDumpInformation, // 32 Y N
  48. SystemExceptionInformation, // 33 Y N
  49. SystemCrashDumpStateInformation, // 34 Y Y/N
  50. SystemKernelDebuggerInformation, // 35 Y N
  51. SystemContextSwitchInformation, // 36 Y N
  52. SystemRegistryQuotaInformation, // 37 Y Y
  53. SystemLoadAndCallImage, // 38 N Y
  54. SystemPrioritySeparation, // 39 N Y
  55. SystemNotImplemented10, // 40 Y N
  56. SystemNotImplemented11, // 41 Y N
  57. SystemInvalidInfoClass2, // 42
  58. SystemInvalidInfoClass3, // 43
  59. SystemTimeZoneInformation, // 44 Y N
  60. SystemLookasideInformation, // 45 Y N
  61. SystemSetTimeSlipEvent, // 46 N Y
  62. SystemCreateSession, // 47 N Y
  63. SystemDeleteSession, // 48 N Y
  64. SystemInvalidInfoClass4, // 49
  65. SystemRangeStartInformation, // 50 Y N
  66. SystemVerifierInformation, // 51 Y Y
  67. SystemAddVerifier, // 52 N Y
  68. SystemSessionProcessesInformation // 53 Y N
  69. } SYSTEM_INFORMATION_CLASS;
  70. typedef struct _SYSTEM_MODULE_INFORMATION {
  71. ULONG Reserved[2];
  72. PVOID Base; //The base address of the module.
  73. ULONG Size; //The size of the module.
  74. ULONG Flags;
  75. USHORT Index;
  76. USHORT Unknown;
  77. USHORT LoadCount;
  78. USHORT ModuleNameOffset;
  79. CHAR ImageName[256];//The filepath of the module.
  80. } SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;
  81. typedef struct _MODULE_LIST {
  82. ULONG NumberOfModules;
  83. SYSTEM_MODULE_INFORMATION SysModuleInfo[];
  84. } MODULE_LIST, *PMODULE_LIST;
  85. typedef struct _SECTION_IMAGE_INFORMATION {
  86. PVOID EntryPoint;
  87. ULONG StackZeroBits;
  88. ULONG StackReserved;
  89. ULONG StackCommit;
  90. ULONG ImageSubsystem;
  91. unsigned char SubsystemVersionLow;
  92. unsigned char SubsystemVersionHigh;
  93. ULONG Unknown1;
  94. ULONG ImageCharacteristics;
  95. ULONG ImageMachineType;
  96. ULONG Unknown2[3];
  97. } SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
  98. NTSYSAPI NTSTATUS ZwQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass,PVOID SystemInformation,ULONG SystemInformationLength,PULONG ReturnLength);
  99. extern PServiceDescriptorTableEntry_t KeServiceDescriptorTable;
  100. ULONG GetKernelBaseAddress(OUT PCHAR lpszModule)
  101. {
  102. NTSTATUS ntStatus;
  103. ULONG NeededSize, KernelAddr=0;
  104. PMODULE_LIST pModuleList;
  105. ZwQuerySystemInformation( SystemModuleInformation, &NeededSize, 0, &NeededSize);
  106. pModuleList = ExAllocatePool( NonPagedPool, NeededSize );
  107. ntStatus = ZwQuerySystemInformation( SystemModuleInformation, pModuleList, NeededSize, NULL );
  108. if ( NT_SUCCESS(ntStatus) )
  109. {
  110. KernelAddr = (ULONG)pModuleList->SysModuleInfo[0].Base;
  111. if (lpszModule)
  112. {
  113. strcpy( lpszModule, "\\SystemRoot\\System32\" );
  114. strcat( lpszModule, pModuleList->SysModuleInfo[0].ModuleNameOffset+ pModuleList->SysModuleInfo[0].ImageName );
  115. }
  116. }
  117. ExFreePool(pModuleList);
  118. return KernelAddr;
  119. }
  120. ULONG RVAToRaw(IN ULONG lpBase, IN ULONG VirtualAddress )
  121. {
  122. IMAGE_DOS_HEADER *pDosHeader;
  123. IMAGE_NT_HEADERS *pNtHeader;
  124. IMAGE_SECTION_HEADER *pSectionHeader;
  125. ULONG NumOfSections, i;
  126. pDosHeader = (IMAGE_DOS_HEADER*)lpBase;
  127. if ( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE )
  128. return 0;
  129. pNtHeader =(IMAGE_NT_HEADERS*)( (unsigned char*)lpBase + pDosHeader->e_lfanew );
  130. NumOfSections = pNtHeader->FileHeader.NumberOfSections;

  131. pSectionHeader = (IMAGE_SECTION_HEADER*)((ULONG)pNtHeader + sizeof(ULONG) + sizeof(IMAGE_FILE_HEADER)
  132. + pNtHeader->FileHeader.SizeOfOptionalHeader);
  133. VirtualAddress -= (ULONG)lpBase;
  134. for ( i=0; i<NumOfSections; i++ )
  135. {
  136. pSectionHeader = (IMAGE_SECTION_HEADER*)( (ULONG)pSectionHeader + sizeof(IMAGE_SECTION_HEADER) * i );
  137. if( VirtualAddress > pSectionHeader->VirtualAddress &&
  138. VirtualAddress < pSectionHeader->VirtualAddress + pSectionHeader->SizeOfRawData )
  139. {
  140. ULONG Offset = VirtualAddress - pSectionHeader->VirtualAddress + pSectionHeader->PointerToRawData;
  141. return Offset;
  142. }
  143. }
  144. return 0;
  145. }
  146. ULONG GetSSDTRealAddr(IN ULONG Index)
  147. {
  148. NTSTATUS ntStatus;
  149. ULONG KernelVirtualBase, KernelImageBase,RealServiceAddress=0;
  150. ULONG NumberOfServices, KiServiceTable, uSSDTRaw,KernelServiceTable;
  151. char szKernelPath[256];
  152. ANSI_STRING asFileName;
  153. UNICODE_STRING usFileName;
  154. OBJECT_ATTRIBUTES ObjAttr;
  155. IO_STATUS_BLOCK ioStatus;
  156. FILE_POSITION_INFORMATION FilePos;
  157. HANDLE hFile;
  158. KernelVirtualBase = GetKernelBaseAddress( szKernelPath );
  159. KernelImageBase = ((IMAGE_NT_HEADERS*)(KernelVirtualBase + ((IMAGE_DOS_HEADER*)KernelVirtualBase)->e_lfanew))->OptionalHeader.ImageBase;
  160. NumberOfServices = KeServiceDescriptorTable->NumberOfServices;
  161. KiServiceTable = (ULONG)KeServiceDescriptorTable->ServiceTableBase;
  162. if (Index>=NumberOfServices) return FALSE;
  163. uSSDTRaw = RVAToRaw( KernelVirtualBase, KiServiceTable+Index*4);
  164. if (uSSDTRaw)
  165. {
  166. RtlInitAnsiString( &asFileName, szKernelPath );
  167. ntStatus = RtlAnsiStringToUnicodeString( &usFileName, &asFileName, TRUE );
  168. if( NT_SUCCESS(ntStatus) )
  169. {
  170. InitializeObjectAttributes(&ObjAttr,&usFileName,OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,NULL,NULL);
  171. ntStatus = ZwOpenFile(&hFile,FILE_READ_DATA,&ObjAttr,&ioStatus,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,FILE_SYNCHRONOUS_IO_NONALERT );
  172. if ( NT_SUCCESS(ntStatus) && hFile )
  173. {
  174. FilePos.CurrentByteOffset.LowPart = uSSDTRaw;
  175. FilePos.CurrentByteOffset.HighPart = 0;
  176. ntStatus = ZwSetInformationFile( hFile,&ioStatus,&FilePos,sizeof(FILE_POSITION_INFORMATION),FilePositionInformation );
  177. if( NT_SUCCESS(ntStatus) )
  178. {
  179. ntStatus = ZwReadFile(hFile,NULL,NULL,NULL,&ioStatus,&KernelServiceTable,sizeof(ULONG),NULL,NULL );
  180. if( NT_SUCCESS(ntStatus) )
  181. {
  182. RealServiceAddress=KernelServiceTable - KernelImageBase + KernelVirtualBase;
  183. }
  184. }
  185. ZwClose(hFile);
  186. }
  187. }
  188. }
  189. RtlFreeUnicodeString( &usFileName );
  190. return RealServiceAddress;
  191. }

  192. ULONG GetExportFuncAddr(IN PCHAR lpFunctionName, IN PUNICODE_STRING pDllName)
  193. {
  194. HANDLE hThread, hSection, hFile, hMod;
  195. SECTION_IMAGE_INFORMATION sii;
  196. PIMAGE_DOS_HEADER pDosHeader;
  197. PIMAGE_OPTIONAL_HEADER pOptHeader;
  198. PIMAGE_EXPORT_DIRECTORY pExportTable;
  199. PULONG arrayOfFuncAddr,arrayOfFuncNames;
  200. PSHORT arrayOfFuncOrdinals;
  201. ULONG funcOrdinal,Base, i, FuncAddr;
  202. PCHAR FuncName;
  203. STRING ntFuncName, ntFuncNameSearch;
  204. PVOID BaseAddress = NULL;
  205. SIZE_T size = 0;
  206. OBJECT_ATTRIBUTES ObjAttr;
  207. IO_STATUS_BLOCK IoStatusBlock;
  208. InitializeObjectAttributes(&ObjAttr,pDllName,OBJ_CASE_INSENSITIVE,NULL, NULL);
  209. ZwOpenFile(&hFile,FILE_EXECUTE | SYNCHRONIZE,&ObjAttr,&IoStatusBlock,FILE_SHARE_READ,FILE_SYNCHRONOUS_IO_NONALERT);
  210. ObjAttr.ObjectName = 0;
  211. ZwCreateSection(&hSection,SECTION_ALL_ACCESS,&ObjAttr,0,PAGE_EXECUTE,0x1000000,hFile);
  212. ZwMapViewOfSection(hSection,NtCurrentProcess(),&BaseAddress,0,1000, 0,&size,(SECTION_INHERIT)1,MEM_TOP_DOWN, PAGE_READWRITE);
  213. ZwClose(hFile);
  214. hMod = BaseAddress;
  215. pDosHeader = (PIMAGE_DOS_HEADER)hMod;
  216. pOptHeader = (PIMAGE_OPTIONAL_HEADER)((PUCHAR)hMod + pDosHeader->e_lfanew + 24 );
  217. pExportTable =(PIMAGE_EXPORT_DIRECTORY)((PUCHAR)hMod + pOptHeader->DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT]. VirtualAddress);
  218. arrayOfFuncAddr = (PULONG)( (PUCHAR)hMod + pExportTable->AddressOfFunctions);
  219. arrayOfFuncNames = (PULONG)( (PUCHAR)hMod + pExportTable->AddressOfNames);
  220. arrayOfFuncOrdinals = (PSHORT)( (PUCHAR)hMod + pExportTable->AddressOfNameOrdinals);
  221. Base = pExportTable->Base;
  222. RtlInitString(&ntFuncNameSearch, lpFunctionName);
  223. for( i=0; i<pExportTable->NumberOfFunctions; i++ )
  224. {
  225. FuncName = (PCHAR)( (PUCHAR)hMod + arrayOfFuncNames[i]);
  226. RtlInitString( &ntFuncName, FuncName );
  227. funcOrdinal = arrayOfFuncOrdinals[i] + Base - 1;
  228. FuncAddr = (ULONG)( (PUCHAR)hMod + arrayOfFuncAddr[funcOrdinal]);
  229. if (RtlCompareString(&ntFuncName, &ntFuncNameSearch, TRUE) == 0)
  230. {
  231. ZwClose(hSection);
  232. return FuncAddr;
  233. }
  234. }
  235. ZwClose(hSection);
  236. return 0;
  237. }
  238. ULONG GetSysCallIndex( PCHAR FuncName )//获得索引号
  239. {
  240. UNICODE_STRING usDllName;
  241. ULONG FuncAddr;
  242. ULONG SysCallIndex;
  243. RtlInitUnicodeString( &usDllName, L"\\SystemRoot\\System32\\ntdll.dll" );
  244. FuncAddr = GetExportFuncAddr(FuncName, &usDllName);
  245. SysCallIndex = *( (PSHORT)(FuncAddr + 1) );
  246. return SysCallIndex;


  247. }
复制代码

6

主题

196

回帖

0

精华

铜牌会员

菜鸟

积分
52
发表于 2010-8-30 13:21:39 | 显示全部楼层
回复 2# ok100fen
OK爷爷,您搞不清楚啊?
TA那个是sssdt.h,我这个是KernelVoid.h,我这个是修改过的,不是TA的.
是我为了方便加了个Kv******,原来是没有的.

6

主题

196

回帖

0

精华

铜牌会员

菜鸟

积分
52
发表于 2010-8-30 13:23:51 | 显示全部楼层
再说了,您这个0x7A是硬编码,这段代码仅仅能在XP上运行.

90

主题

473

回帖

2

精华

钻石会员

积分
3261
 楼主| 发表于 2010-8-30 14:55:36 | 显示全部楼层
用微软宏取得地址的代码

#include <ntddk.h>
VOID Unload(IN PDRIVER_OBJECT DriverObject)
{
}
#pragma pack(1)        //SSDT表的结构
typedef struct ServiceDescriptorEntry {
        unsigned int *ServiceTableBase;
        unsigned int *ServiceCounterTableBase; //Used only in checked build
        unsigned int NumberOfServices;
        unsigned char *ParamTableBase;
} ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;
#pragma pack()


__declspec(dllimport) ServiceDescriptorTableEntry_t KeServiceDescriptorTable;        //变量名是不能变的,因为是从外部导入

//取函数在SSDT中的位置
#define SYSTEMSERVICE(_function)  KeServiceDescriptorTable.ServiceTableBase[ *(PULONG)((PUCHAR)_function+1)]
//取函数的索引
#define SYSCALL_INDEX(_Function) *(PULONG)((PUCHAR)_Function+1)
NTSYSAPI NTSTATUS NTAPI ZwOpenProcess(OUT PHANDLE ProcessHandle,IN ACCESS_MASK DesiredAccess,IN POBJECT_ATTRIBUTES ObjectAttributes,IN PCLIENT_ID ClientId OPTIONAL);

typedef NTSTATUS (*ZWOPENPROCESS)(OUT PHANDLE ProcessHandle,IN ACCESS_MASK DesiredAccess,IN POBJECT_ATTRIBUTES ObjectAttributes,IN PCLIENT_ID ClientId OPTIONAL);



NTSTATUS  DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
       
      

           SYSTEMSERVICE(ZwOpenProcess);

      
       KdPrint(("NtOpenProcess的地址=%x",SYSTEMSERVICE(ZwOpenProcess)));



        DriverObject->DriverUnload = Unload;

        return STATUS_SUCCESS;
}

90

主题

473

回帖

2

精华

钻石会员

积分
3261
 楼主| 发表于 2010-8-30 17:36:19 | 显示全部楼层
#include <ntddk.h>
#include "ntimage.h"
#include "KernelVoid.h"


VOID Unload(IN PDRIVER_OBJECT DriverObject)
{
}

NTSTATUS  DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
       

                     ULONG XXXX;
                     XXXX=KvGetKernelVoid(L"NtOpenProcess");


                     KdPrint(("内核函数地址=%x",XXXX));



                    DriverObject->DriverUnload = Unload;

        return STATUS_SUCCESS;
}
头像被屏蔽

27

主题

136

回帖

2

精华

铂金会员

积分
2257
发表于 2010-8-30 18:23:42 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

275

主题

3017

回帖

1

精华

管理员

嗷嗷叫的老马

积分
17064

论坛牛人贡献奖关注奖最佳版主进步奖人气王疯狂作品奖精英奖赞助论坛勋章乐于助人勋章

QQ
发表于 2010-8-31 16:00:35 | 显示全部楼层
我......是路过的.....
我就是嗷嗷叫的老马了......

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表