前段时间拜读了Sysnap 的
<简单inline hook ObReferenceObjectByHandle保护进程和屏蔽文件执行>
觉得这个函数很是方便 于是准备实现下
但是实现方法有所不同 , Sysnap的方法有些麻烦
我就干脆直接把ObReferenceObjectByHandle的最后7个字节给改了
然后在判断是不是我们要保护的进程,不是就把原状态返回
是就返回个 c0000008(STATUS_INVAILD_HANDLE)
但是没发防止进程被结束~~到底怎么回事咧?哪里出错了?
关键代码如下
int
AyObReferenceObjectByHandle(
IN HANDLE Handle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_TYPE ObjectType ,
IN KPROCESSOR_MODE AccessMode,
OUT PVOID *Object,
OUT POBJECT_HANDLE_INFORMATION HandleInformation
)
{
//NTSTATUS status = STATUS_SUCCESS ;
ULONG PID , i , count = 0 ;
unsigned char *ProName , ImaName[] = "INSTDRV.EXE" ;
if( ObjectType != *PsProcessType)
return 0 ;
ProName = (unsigned char *)(*Object)+GetPlantformDependentInfo(OFFSET_EPROCESS_IMAGENAME) ;
/*for( i = 0 ; i < 16 ; i++ , ProName++ )
{
if( *ProName == ImaName[i] )
count++ ;
if( *ProName == '\0' && ImaName[i] == '\0' )
break ;
}
*/
PID = (ULONG)((unsigned char *)(*Object)+GetPlantformDependentInfo(OFFSET_EPROCESS_PID)) ;
//DbgPrint("process PID %x\n" , PID) ;
if( strlen(ProName) == RtlCompareMemory( ProName , &ImaName[0] , strlen(ProName) ) )
{
DbgPrint("name:%s" , ProName) ;
DbgPrint("PID:%d" , PID) ;
DbgPrint("STATUS_INVALID_HANDLE :%x", STATUS_INVALID_HANDLE ) ;
return 1 ;
}
//DbgPrint("AyHook For ObReferenceObjectByHandle\n") ;
return 0 ;
}
__declspec(naked)
T_ObReferenceObjectByHandle( )
{
__asm
{
push eax
push [ebp+1ch]
push [ebp+18h]
push [ebp+14h]
push [ebp+10h]
push [ebp+0ch]
push [ebp+08h]
call AyObReferenceObjectByHandle ;应该是以ret 18h返回 调用完ebp指针跟原先不变
pop edx //弹出原先eax的值到edx
cmp eax , 1
jnz end
mov edx , 0xC0000008L
// mov [ebp+18h] , 0x0L
end :
mov eax , edx
pop edi
pop esi
pop ebx
_emit 0xc9 //leave
ret 18h
}
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课