Wie der Zugriff auf Benutzer-Modus-Speicher?

Ich versuche zu Lesen, die von PEB notepad.exe
Derzeit bin ich versuchen, auf den PEB durch die Registrierung einer ProcessCreation Rückruf und dann warten, bis notepad.exe erstellt. Sobald der Editor erstellt, ich benutze es die PID zu öffnen, der Prozess und finden die PEB mit ZwQuerryProcess(PROCESS_BASIC_INFORMATION).

Aber wenn ich versuche, Lesen Sie über INFORMATIONEN->PEB wird eine Ausnahme ausgelöst (ich nehme an, das ist, weil ich keinen Zugriff auf den Speicher)

Als ich das erste entdeckt habe, erinnerte ich jemanden erwähnen, der KeStackAttachProcess und es ist Gegenstück zu access Adressen in einem anderen Prozess-Kontext.

Das problem ist, dass ich nicht wissen, wie um zu überprüfen, ob Sie die context-change erfolgreich war oder nicht. Und einmal bin ich angeblich in einem anderen Kontext habe ich noch keinen Zugriff auf die peb. Weiß jemand wie ich Zugriff auf die PEB von notepad?

Hier ist der code, den ich verwende, um zu finden und Zugang der PEB:

Übernehmen hgtPid = die PID Editor

void ModuleDumperThread(){

NTSTATUS Status = STATUS_SUCCESS;
HANDLE hProcessHandle = NULL;
PLIST_ENTRY Next;
PLDR_DATA_TABLE_ENTRY LdrDataTableEntry;
CLIENT_ID clientID; 
ACCESS_MASK DesiredAccess = PROCESS_ALL_ACCESS;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hProcessId = hgtPid;
PROCESS_BASIC_INFORMATION BasicInfoReal;
ULONG SizeReturned;

PEPROCESS ep;
KAPC_STATE *ka_state = NULL;


InitializeObjectAttributes (&ObjectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);

   clientID.UniqueProcess = hProcessId;  
   clientID.UniqueThread = NULL; 

__try{


Status = ZwOpenProcess(&hProcessHandle, DesiredAccess, &ObjectAttributes, &clientID);

                if(Status != STATUS_SUCCESS){
                        DbgPrint("Failed to open process\n");
                        DbgPrint("NtStatus: 0x%x", Status);
                        return;
                }

            Status = gZwQueryprocess(hProcessHandle, ProcessBasicInformation, (PVOID)&BasicInfoReal, sizeof(PROCESS_BASIC_INFORMATION), &SizeReturned);

                    if(Status != STATUS_SUCCESS){
                                DbgPrint("gZwQueryprocess failed\n");
                                DbgPrint("Size returned: 0x%x\nNtStatus: 0x%x\n", SizeReturned, Status);
                                ZwClose(hProcessHandle);
                                return;
                    }

            ZwClose(hProcessHandle);        

        Status = PsLookupProcessByProcessId(hProcessId, &ep);

                    if(Status != STATUS_SUCCESS){
                                DbgPrint("PsLookupProcessByProcessId failed\n");
                                DbgPrint("NtStatus: 0x%x\n", Status);
                                return;
                    }

ka_state = ExAllocatePoolWithTag(NonPagedPool, sizeof(KAPC_STATE),'trak');

            KeStackAttachProcess(ep, ka_state);

__try{

                if(BasicInfoReal.PebBaseAddress->Ldr){

                           Next = BasicInfoReal.PebBaseAddress->Ldr->InLoadOrderModuleList.Blink;
                           LdrDataTableEntry = CONTAINING_RECORD( Next,
                                                                  LDR_DATA_TABLE_ENTRY,
                                                                  LoadOrder
                                                                );
                    DbgPrint("Module base address: 0x%x", LdrDataTableEntry->ModuleBaseAddress);
                } 
    }__except( EXCEPTION_EXECUTE_HANDLER ) {
        DbgPrint("Exception while trying to access the PEB\n");
       }

            KeUnstackDetachProcess(ka_state);
            ExFreePool(ka_state);


}__except( EXCEPTION_EXECUTE_HANDLER ) {
                DbgPrint("Exception in ModuleDumper\n");
        }

              if(ep){
                ObDereferenceObject(ep);        
              } 
return;
}

Hat jemand vor Ort alle Fehler/Mängel?

Vielen Dank im Voraus

EDIT:

Ich habe ein paar Sachen verändert, und das ist, wo wird es wirklich Bizarr. Für den Willen des seins sicher, ich habe die 'ep' der KeStackAttachProcess (), um die von msdn bezeichnet PRKPROCESS geben, wenn ich Anrufe, KeStackAttachProcess() wird nun die Ausführung einfach verschwindet. Vor dem Aufruf ist alles in Ordnung, nach dem Aufruf, es gibt einfach nichts. Keine Fehler, keine Ausnahmen, keine BSOD ' s: Nichts. Was ist Los?!?

Änderungen:

    __asm{
        mov eax, ep
        mov eax, [eax]
        mov myPKPROCESS, eax  //just dereferencing my pointer (I don't have the structs)
    }

  DbgPrint("Test print\n");   //gets printed just fine

            KeStackAttachProcess(&myPKPROCESS, ka_state); 
DbgPrint("Test print\n");  //nothing happens

EDIT2:

Habe ich das problem gelöst. Ich weiß noch nicht, was falsch gelaufen ist in dem obigen code, aber dieser code scheint zu funktionieren:

void ModuleDumperThread(){

NTSTATUS Status = STATUS_SUCCESS;
HANDLE hProcessHandle = NULL;
PLIST_ENTRY Next;
PLDR_DATA_TABLE_ENTRY LdrDataTableEntry;
CLIENT_ID clientID; 
ACCESS_MASK DesiredAccess = PROCESS_ALL_ACCESS;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hProcessId = hgtPid;
PROCESS_BASIC_INFORMATION BasicInfoReal;
ULONG SizeReturned;
PEPROCESS ep = NULL;
unsigned int Index = 0;
InitializeObjectAttributes (&ObjectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);

   clientID.UniqueProcess = hProcessId;  
   clientID.UniqueThread = NULL; 


__try{

    Status = ZwOpenProcess(&hProcessHandle, DesiredAccess, &ObjectAttributes, &clientID);

                if(Status != STATUS_SUCCESS){
                        DbgPrint("Failed to open process\n");
                        DbgPrint("NtStatus: 0x%x", Status);
                        return;
                }

            Status = gZwQueryprocess(hProcessHandle, ProcessBasicInformation, (PVOID)&BasicInfoReal, sizeof(PROCESS_BASIC_INFORMATION), &SizeReturned);

                    if(Status != STATUS_SUCCESS){
                                DbgPrint("gZwQueryprocess failed\n"); 
                                DbgPrint("Size returned: 0x%x\nNtStatus: 0x%x\n", SizeReturned, Status);
                                ZwClose(hProcessHandle);
                                return;
                    }

    //DbgPrint("Basic info: 0x%x\n", BasicInfoReal);
    //DbgPrint("BasicInfoReal->PebBaseAddress: 0x%x\n", BasicInfoReal->PebBaseAddress);
    //DbgPrint("RealPeb: 0x%x\n", RealPeb);
    //DbgPrint("gZwReadVirtualMemory: 0x%x\n", gZwReadVirtualMemory);

                    Status = PsLookupProcessByProcessId(hProcessId, &ep);

                    if(Status != STATUS_SUCCESS){
                                DbgPrint("PsLookupProcessByProcessId failed\n");
                                DbgPrint("NtStatus: 0x%x\n", Status);
                                ZwClose(hProcessHandle);
                                return;
                    }
Timeout((INT64)0x1FFFFFF);

KeAttachProcess(ep);
__try{
   DbgPrint("ImageBaseAddress of notepad.exe: 0x%x\n", BasicInfoReal.PebBaseAddress->ImageBaseAddress);

    Next = BasicInfoReal.PebBaseAddress->Ldr->InLoadOrderModuleList.Blink;
    LdrDataTableEntry = CONTAINING_RECORD( Next, LDR_DATA_TABLE_ENTRY, LoadOrder);


    for(Index = 0; Index != 17; Index++){
       DbgPrint("%d: ImageBase of %wZ in Notepad.exe: 0x%x\n", Index, &(LdrDataTableEntry->ModuleName), LdrDataTableEntry->ModuleBaseAddress);
       Next = Next->Blink;
       LdrDataTableEntry = CONTAINING_RECORD(Next, LDR_DATA_TABLE_ENTRY, LoadOrder);
    }


   }__except( EXCEPTION_EXECUTE_HANDLER ) {
                DbgPrint("Exception while accessing the LDR\n");
        }

KeDetachProcess();

    }__except( EXCEPTION_EXECUTE_HANDLER ) {
                DbgPrint("Exception in ModuleDumper\n");
        }
        ObDereferenceObject((PVOID)ep);
        ZwClose(hProcessHandle);    


return;
}
InformationsquelleAutor Unknown | 2011-06-11
Schreibe einen Kommentar