#ifndef CETC ALLERT! DO NOT PUT THIS FILE IN THE STANDARD CE DISTRIBUTION #endif #include "ntifs.h" #include "extraimports.h" #include "memscan.h" #include "tdiwrapper.h" #include #include "rootkit.h" VOID CETC_CORE(IN PVOID StartContext) { KLOCK_QUEUE_HANDLE lqh; PEPROCESS ActivePEPROCESS=NULL; InitServer(); if (FileObjectConnection!=NULL) { StopListener=FALSE; while (!StopListener) { AddressListEntries=0; DbgPrint("Start listening\n"); if (Listen()) { ULONG DataSent=0; BOOLEAN PasswordCorrect=FALSE; int i; unsigned char command; char a; char *buffer; char defaultpass[9]="defaultpw"; DbgPrint("Listen=success\n"); connected=TRUE; DbgPrint("Waiting for password\n"); while ((!PasswordCorrect) && (connected)) { if (Receive(&command,1)) { if (command==CS_PASSWORD) //only one possible so use a if { if (Receive(&a,1)) //length { if (a!=0) { buffer=ExAllocatePoolWithTag(NonPagedPool,(ULONG)a,0); DbgPrint("received passsize=%d\n",a); //allocate a buffer big enough to receive the password if (Receive(buffer,a)) { if (a<=9) { for (i=0; i0) Send(TempBuffer,pos); ExFreePool(TempBuffer); Send(EndList,1); } __except(1) { DbgPrint("Error in processlist\n"); } break; } case CS_OPENPROCESS: { unsigned char openedprocess=SC_OPENPROCESSSUCCESS; DbgPrint("Open Process\n"); if (Receive(&ActivePEPROCESS,4)) DbgPrint("ActivePEPROCESS=%p\n",ActivePEPROCESS); else DbgPrint("OpenProcess failed"); Send(&openedprocess,1); break; } case CS_CancelScan: { CurrentScan.scanning=FALSE; addressfile=0; valuefile=0; } case CS_FirstScan: { //start,stop:dword;vartype:byte;Scantype:byte;scanvaluelength:byte;scanvalue:array of bytes;scanoptions:byte DWORD start; DWORD stop; BYTE VarType; BYTE Scantype; BYTE ScanvalueSize; char *scanvalue; BYTE ScanOptions; Receive(&start,4); Receive(&stop,4); Receive(&VarType,1); Receive(&Scantype,1); Receive(&ScanvalueSize,1); scanvalue=ExAllocatePoolWithTag(NonPagedPool,ScanvalueSize,0); if (scanvalue!=NULL) { __try { Receive(scanvalue,ScanvalueSize); Receive(&ScanOptions,1); //all parameters received, start the scan.... DbgPrint("start=%x stop=%x vartype=%d scantype=%d scanvaluesize=%d scanoptions=%d\n",start,stop,VarType,Scantype,ScanvalueSize); FirstScan(ActivePEPROCESS,start,stop,VarType,Scantype,ScanvalueSize,scanvalue,ScanOptions); } __finally { ExFreePool(scanvalue); } } break; } case CS_ReadProcessMemory: { //ReadProcessMemory(address:dword; length: word); BOOLEAN ok=FALSE; ULONG address; WORD size; WORD bytesread=0; char* outputbuffer; DbgPrint("ReadProcessMemory\n"); Receive(&address,4); Receive(&size,2); DbgPrint("address=%x size=%d\n",address,size); //output SC_ReadProcessMemoryResult(successboolean: byte; actualread: word; bytesread: array of byte) //allocate memory to hold the data outputbuffer=ExAllocatePoolWithTag(NonPagedPool,(ULONG)size+4,0); if (outputbuffer!=NULL) { DbgPrint("Allocated memory\n"); DbgPrint("ActivePEPROCESS=%p\n",ActivePEPROCESS); ok=ReadProcessMemory(0,ActivePEPROCESS,(PVOID)address,size,(PVOID)&outputbuffer[4]); if (ok) DbgPrint("ReadProcessMemory successful\n"); else DbgPrint("ReadProcessMemory failed\n"); bytesread=ok ? (WORD)size : 0; outputbuffer[0]=SC_ReadProcessMemoryResult; outputbuffer[1]=ok ? 1:0; *(PWORD)(&outputbuffer[2])=bytesread; Send(outputbuffer,bytesread+4); ExFreePool(outputbuffer); } break; } case CS_WriteProcessMemory: { //WriteProcessMemory(address:dword; length: word; bytes: array of byte); BOOLEAN ok=FALSE; ULONG address; WORD size; WORD bytesread=0; char* inputbuffer; DbgPrint("WriteProcessMemory\n"); Receive(&address,4); Receive(&size,2); DbgPrint("address=%x size=%d\n",address,size); inputbuffer=ExAllocatePoolWithTag(NonPagedPool, (size<=4) ? 4 : (ULONG)size,0); if (inputbuffer!=NULL) { Receive(inputbuffer,size); ok=WriteProcessMemory(0,ActivePEPROCESS,(PVOID)address,size,inputbuffer); if (ok) DbgPrint("WriteProcessMemory successful\n"); else DbgPrint("WriteProcessMemory failed\n"); inputbuffer[0]=SC_WriteProcessMemoryResult; inputbuffer[1]=ok ? 1:0; *(PWORD)(&inputbuffer[2])=ok ? (WORD)size: 0; Send(inputbuffer,4); ExFreePool(inputbuffer); } break; } case CS_ClearRecordList: { AddressListEntries=0; break; } case CS_UpdateList: //update list(start:word stop:word) //request a updated list { WORD start,stop; WORD i,j; DWORD buffersize=1,pos; char *buffer; ADDRESSENTRY *templist; DbgPrint("UpdateList\n"); Receive(&start,2); Receive(&stop,2); DbgPrint("start=%d\nstop=%d\n",start,stop); //read the addresses and send the data to the client start=start>AddressListEntries-1 ? 0:start; stop=stop>AddressListEntries-1 ? AddressListEntries:stop; DbgPrint("After adjusting:\nstart=%d\nstop=%d\n",start,stop); templist=ExAllocatePoolWithTag(NonPagedPool, (start-stop+1)*sizeof(ADDRESSENTRY),0); if (templist!=NULL) { j=0; for (i=start;i