WCHAR pModuleName[216]={0};
VOID LoadImageNotifyRoutine
(
__in_opt PUNICODE_STRING FullImageName,
__in HANDLE ProcessId,
__in PIMAGE_INFO ImageInfo
)
{
PVOID pDrvEntry;
PEPROCESS ProcessObj=NULL;
char* pname;
PSIZE_T pdata[2]={0};
NTSTATUS st=STATUS_UNSUCCESSFUL;
char szFullImageName[260]={0};
int i=0;
if(FullImageName!=NULL && MmIsAddressValid(FullImageName))
{
if(ProcessId!=0){
st = PsLookupProcessByProcessId(ProcessId, &ProcessObj);
if (PsGetProcessImageFileName!=NULL)
{
pname = PsGetProcessImageFileName(ProcessObj);
if (pname==NULL)
goto fun_ret;
pname= _strlwr(pname);
if (strstr(browser,pname)!=NULL){
if(FullImageName->Length<=216){
wcsncpy(pModuleName,FullImageName->Buffer,FullImageName->Length);
for( i = 0; i < FullImageName->Length; i++)
pModuleName[i] = tolower(pModuleName[i]);
if (wcsstr(pModuleName,L"\\dll.dll")!=NULL){
DbgPrint("进程:%s PID:%d 模块:%ws",pname,ProcessId,pModuleName);
pDrvEntry=GetDriverEntryByImageBase(ImageInfo->ImageBase);//得到dll入口
pdata[0]=ProcessObj;
pdata[1]=pDrvEntry;
DenyLoadDll(pdata);
}
}
}
}
}
}
fun_ret:
return;
}
void DenyLoadDll(PSIZE_T data)
{
PEPROCESS dld_ep=(PEPROCESS)(data[0]);
PVOID DriverEntry=(PVOID)(data[1]);
UCHAR fuck64[]="\xB8\x00\x00\x00\x00\xC3";
UCHAR fuck32[]="\xB8\x00\x00\x00\x00\xC2\x08\x00";
PVOID BaseAddress=DriverEntry;
ULONG OldProtect;
SIZE_T RegionSize;
NTSTATUS st;
KAPC_STATE ks={0};
if((ULONG64)DriverEntry<(ULONG64)0x7FFFFFFF)
{
RegionSize=sizeof(fuck32);
}
else
{
RegionSize=sizeof(fuck64);
}
KeStackAttachProcess(dld_ep,&ks);
st=NtProtectVirtualMemory((HANDLE)-1,&BaseAddress,&RegionSize,PAGE_EXECUTE_READWRITE,&OldProtect);
DbgPrint("st:%x",st);//NtProtectVirturalMemorry调用后返回值c0000005
if(NT_SUCCESS(st))
{
__try
{
DbgPrint("成功!\n");
if((ULONG64)DriverEntry<(ULONG64)0x7FFFFFFF)
{
memcpy(DriverEntry,fuck32,sizeof(fuck32));
}
else
{
memcpy(DriverEntry,fuck64,sizeof(fuck64));
}
}
__except(1)
{
;
}
}
KeUnstackDetachProcess(&ks);
PsTerminateSystemThread(STATUS_SUCCESS);
}
求大家帮忙能不能看出哪里出问题!主要是想拦截进程第三方dll的加载
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!