pslookupthreadbythreadid 這個函數地址是那裡的,作用是什麼,恢復原理呢?
驅動原代嗎,是參照了墮落天才和Damax的文章 ,後改的
裏面有幾處錯誤,
求大師幫忙修改下
#include<ntddk.h>
typedef struct _SERVICE_DESCRIPTOR_TABLE
{
PVOID ServiceTableBase;
PULONG ServiceCounterTableBase;
ULONG NumberOfService;
ULONG ParamTableBase;
}SERVICE_DESCRIPTOR_TABLE,*PSERVICE_DESCRIPTOR_TABLE; //由于KeServiceDescriptorTable只有一项,这里就简单点了
extern PSERVICE_DESCRIPTOR_TABLE KeServiceDescriptorTable;//KeServiceDescriptorTable为导出函数
/////////////////////////////////////
VOID Hook();
VOID Unhook();
VOID OnUnload(IN PDRIVER_OBJECT DriverObject);
//////////////////////////////////////
ULONG JmpAddress;//跳转到NtOpenProcess里的地址
ULONG JmpAddress0;
ULONG JmpAddress1;
ULONG JmpAddress2;
ULONG JmpAddress3;
ULONG OldServiceAddress;//原来NtOpenProcess的服务地址
ULONG OldServiceAddress0;
ULONG OldServiceAddress1;
ULONG OldServiceAddress2;
ULONG OldServiceAddress3;
//////////////////////////////////////
__declspec(naked) NTSTATUS __stdcall MyNtOpenProcess(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PCLIENT_ID ClientId)
{
DbgPrint("NtOpenProcess() called");
__asm{
push 0C4h
push 804db4c0h
mov eax,8053cbb0h
call eax
jmp [JmpAddress]
}
}
///////////////////////////////////////////////////////////////
//0: kd> u 805d576a
//nt!PsLookupThreadByThreadId+0x161c:
//805d576a b94d80e83e mov ecx,3EE8804Dh
//805d576f 74f6 je nt!PsLookupThreadByThreadId+0x1619 (805d5767)
//805d5771 ff33 push dword ptr [ebx]
//805d5773 f6 ???
//805d5774 8975e4 mov dword ptr [ebp-1Ch],esi
//805d5777 64a124010000 mov eax,dword ptr fs:[00000124h]
//805d577d 8b7d08 mov edi,dword ptr [ebp+8]
//805d5780 3bf8 cmp edi,eax
__declspec(naked) NTSTATUS __stdcall PsLookupThreadByThreadId(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PCLIENT_ID ClientId)
{
__asm{
mov ecx,3EE8804Dh
je 805d5767h
push dword ptr [ebx]
jmp [JmpAddress0]
}
}
///////////////////////////////////////////////////////////////
__declspec(naked) NTSTATUS __stdcall MyNtReadVirtualMemory(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PCLIENT_ID ClientId)
{
__asm{
push 1Ch
push 804daee8h
mov eax,8053cbb0h
call eax
jmp [JmpAddress1]
}
}
///////////////////////////////////////////////////////////////
__declspec(naked) NTSTATUS __stdcall MyNtWriteVirtualMemory(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PCLIENT_ID ClientId)
{
__asm{
push 1Ch
push 804daf08h
mov eax,8053cbb0h
call eax
jmp [JmpAddress2]
}
}
///////////////////////////////////////////////////
//0: kd> u 0x805B537E
//nt!NtWriteVirtualMemory+0x6:
//805b537e 80e82c sub al,2Ch
//805b5381 78f8 js nt!NtWriteVirtualMemory+0x3 (805b537b)
//805b5383 ff64a124 jmp dword ptr [ecx+24h]
//805b5387 0100 add dword ptr [eax],eax
//805b5389 008bf88a8740 add byte ptr [ebx+40878AF8h],cl
//805b538f 0100 add dword ptr [eax],eax
//805b5391 008845e08b75 add byte ptr [eax+758BE045h],cl
//805b5397 1484 adc al,84h
__declspec(naked) NTSTATUS __stdcall MyNtWriteVirtualMemory_0x6(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PCLIENT_ID ClientId)
{
__asm{
sub al,2Ch
js 805b537bh
jmp dword ptr [ecx+24h] //這裡也出錯了
jmp [JmpAddress3]
}
}
///////////////////////////////////////////////////
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
DriverObject->DriverUnload = OnUnload;
DbgPrint("Unhooker load");
Hook();
return STATUS_SUCCESS;
}
/////////////////////////////////////////////////////
VOID OnUnload(IN PDRIVER_OBJECT DriverObject)
{
DbgPrint("Unhooker unload!");
Unhook();
}
/////////////////////////////////////////////////////
VOID Hook()
{
ULONG Address,Address0,Address1,Address2,Address3;
Address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x7A * 4;//0x7A为NtOpenProcess服务ID
Address0 = (ULONG)0x805D576A;
Address1 = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0xBA * 4;
Address2 = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0x115 * 4;
Address3 = (ULONG)KeServiceDescriptorTable->ServiceTableBase + 0xBA * 4;
OldServiceAddress = *(ULONG*)Address;//保存原来NtOpenProcess的地址
OldServiceAddress0 = *(ULONG*)Address0;
OldServiceAddress1 = *(ULONG*)Address1;//保存原来NtOpenProcess的地址
OldServiceAddress2 = *(ULONG*)Address2;//保存原来NtOpenProcess的地址
OldServiceAddress3 = *(ULONG*)Address3+0x6;//保存原来NtOpenProcess的地址
JmpAddress=(ULONG)NtOpenProcess+15; //跳转到NtOpenProcess函数头+15的地方,这样在其前面写的JMP都失效了
JmpAddress0=OldServiceAddress0+9;
JmpAddress1=OldServiceAddress1+12; //跳转到NtReadVirtualMemory函数头+12的地方,这样在其前面写的JMP都失效了
JmpAddress2=OldServiceAddress2+12; //跳转到NtWriteVirtualMemory函数头+12的地方,这样在其前面写的JMP都失效了
JmpAddress3=OldServiceAddress3+9;
__asm{//去掉内存保护
cli
mov eax,cr0
and eax,not 10000h
mov cr0,eax
}
*((ULONG*)Address)=(ULONG)MyNtOpenProcess;//HOOK SSDT
*((ULONG*)Address0)=(ULONG)PsLookupThreadByThreadId;
*((ULONG*)Address1)=(ULONG)MyNtReadVirtualMemory;//HOOK SSDT
*((ULONG*)Address2)=(ULONG)MyNtWriteVirtualMemory;
*((ULONG*)Address3)=(ULONG)MyNtWriteVirtualMemory_0x6;
__asm{//恢复内存保护
mov eax,cr0
or eax,10000h
mov cr0,eax
sti
}
}
//////////////////////////////////////////////////////
VOID Unhook()
{
ULONG Address,Address0,Address1,Address2,Address3;
Address=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0x7A * 4;//查找SSDT
Address0=(ULONG)0x805D576A;
Address1=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0xBA * 4;
Address2=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0x115 * 4;
Address3=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0xBA * 4;
__asm{
cli
mov eax,cr0
and eax,not 10000h
mov cr0,eax
}
*((ULONG*)Address) = (ULONG)OldServiceAddress;//还原SSDT
*((ULONG*)Address0) = (ULONG)OldServiceAddress0;
*((ULONG*)Address1) = (ULONG)OldServiceAddress1;
*((ULONG*)Address2) = (ULONG)OldServiceAddress2;
__asm{
mov eax,cr0
or eax,10000h
mov cr0,eax
sti
}
DbgPrint("Unhook");
}
[招生]系统0day安全班,企业级设备固件漏洞挖掘,Linux平台漏洞挖掘!