PEB TEB structural body

PEB TEB structure using
an OS executable file is loaded into memory, and load modules associated processed after treatment ...... import table and other necessary treatment to form a process. Stored in the OS kernel have an ID card information on this process, which is usually seen HANDLE, called the process handle. . .

After the OS has finished loading, FS segment register points to the current TEB structure, particularly TEB following structure:

KD> dt _teb 
NT _TEB!
+ 0x000 NtTib: _NT_TIB + 0x01C EnvironmentPointer: Ptr32 Void + 0x020 ClientId: _CLIENT_ID: the current process ID + 0x028 ActiveRpcHandle: Ptr32 Void + 0x02C ThreadLocalStoragePointer: Ptr32 Void + 0x030 PEB pointer Ptr32 _PEB current process: ProcessEnvironmentBlock + 0x034 LastErrorValue: Uint4B + 0x038 CountOfOwnedCriticalSections: Uint4B + 0x03C CsrClientThread: Ptr32 Void + 0x040 Win32ThreadInfo: Ptr32 Void + 0x044 User32Reserved : [26] Uint4B +0x0ac UserReserved : [5] Uint4B +0x0c0 WOW32Reserved : Ptr32 Void +0x0c4 CurrentLocale : Uint4B +0x0c8 FpSoftwareStatusRegister : Uint4B +0x0cc SystemReserved1 : [54] Ptr32 Void +0x1a4 ExceptionCode : Int4B +0x1a8 ActivationContextStack : _ACTIVATION_CONTEXT_STACK +0x1bc SpareBytes1 : [24] UChar +0x1d4 GdiTebBatch : _GDI_TEB_BATCH +0x6b4 RealClientId : _CLIENT_ID +0x6bc GdiCachedProcessHandle : Ptr32 Void +0x6c0 GdiClientPID : Uint4B +0x6c4 GdiClientTID : Uint4B +0x6c8 GdiThreadLocalInfo : Ptr32 Void +0x6cc Win32ClientInfo : [62] Uint4B +0x7c4 glDispatchTable : [233] Ptr32 Void +0xb68 glReserved1 : [29] Uint4B +0xbdc glReserved2 : Ptr32 Void +0xbe0 glSectionInfo : Ptr32 Void +0xbe4 glSection : Ptr32 Void +0xbe8 glTable : Ptr32 Void +0xbec glCurrentRC : Ptr32 Void +0xbf0 glContext : Ptr32 Void +0xbf4 LastStatusValue : Uint4B +0xbf8 StaticUnicodeString : _UNICODE_STRING +0xc00 StaticUnicodeBuffer : [261] Uint2B +0xe0c DeallocationStack : Ptr32 Void +0xe10 TlsSlots : [64] Ptr32 Void +0xf10 TlsLinks : _LIST_ENTRY +0xf18 Vdm : Ptr32 Void +0xf1c ReservedForNtRpc : Ptr32 Void +0xf20 DbgSsReserved : [2] Ptr32 Void +0xf28 HardErrorsAreDisabled : Uint4B +0xf2c Instrumentation : [16] Ptr32 Void +0xf6c WinSockData : Ptr32 Void +0xf70 GdiBatchCount : Uint4B +0xf74 InDbgPrint : UChar +0xf75 FreeStackOnTermination : UChar +0xf76 HasFiberData : UChar +0xf77 IdealProcessor : UChar +0xf78 Spare3 : Uint4B +0xf7c ReservedForPerf : Ptr32 Void +0xf80 ReservedForOle : Ptr32 Void +0xf84 WaitingOnLoaderLock : Uint4B +0xf88 Wx86Thread : _Wx86ThreadState +0xf94 TlsExpansionSlots : Ptr32 Ptr32 Void +0xf98 ImpersonationLocale : Uint4B +0xf9c IsImpersonating : Uint4B +0xfa0 NlsCache : Ptr32 Void +0xfa4 pShimData : Ptr32 Void +0xfa8 HeapVirtualAffinity : Uint4B +0xfac CurrentTransactionHandle : Ptr32 Void +0xfb0 ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME +0xfb4 SafeThunkCall : UChar +0xfb5 BooleanSpare : [3] UChar

 

You can see offset 0x30 in TEB is PEB structure pointer of this process, you can get the address of PEB through this pointer, so continue to read some more information about this process. The following statement can be used for reading the assembler PEB corresponding memory address pointer:

the __asm
{
MOV EAX, FS: [0x30]
MOV PEB, EAX
}

after PEB obtained address information corresponding to the read memory, press PEB structure resolution. . . Structure look down:

KD> dt _peb 
NT ! _PEB
 + 0x000 InheritedAddressSpace: uchar
 + 0x001 ReadImageFileExecOptions: uchar
 + 0x002 BeingDebugged: uchar debug flag
 + 0x003 SpareBool: uchar
 + 0x004 Mutant: Ptr32 Void
 + 0x008 ImageBaseAddress: Ptr32 Void image base
 + 0x00C Ldr: Ptr32 _PEB_LDR_DATA process load module list
 + 0x010 processParameters: Ptr32 _RTL_USER_PROCESS_PARAMETERS
 + 0x014 SubSystemData: Ptr32 Void
 + 0x018 ProcessHeap: Ptr32 Void
+0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION
+0x020 FastPebLockRoutine : Ptr32 Void
+0x024 FastPebUnlockRoutine : Ptr32 Void
+0x028 EnvironmentUpdateCount : Uint4B
+0x02c KernelCallbackTable : Ptr32 Void
+0x030 SystemReserved : [1] Uint4B
+0x034 AtlThunkSListPtr32 : Uint4B
+0x038 FreeList : Ptr32 _PEB_FREE_BLOCK
+0x03c TlsExpansionCounter : Uint4B
+0x040 TlsBitmap : Ptr32 Void
+0x044 TlsBitmapBits : [2] Uint4B
+0x04c ReadOnlySharedMemoryBase : Ptr32 Void
+0x050 ReadOnlySharedMemoryHeap : Ptr32 Void
+0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void
+0x058 AnsiCodePageData : Ptr32 Void
+0x05c OemCodePageData : Ptr32 Void
+0x060 UnicodeCaseTableData : Ptr32 Void
+0x064 NumberOfProcessors : Uint4B
+0x068 NtGlobalFlag : Uint4B
+0x070 CriticalSectionTimeout : _LARGE_INTEGER
+0x078 HeapSegmentReserve : Uint4B
+0x07c HeapSegmentCommit : Uint4B
+0x080 HeapDeCommitTotalFreeThreshold : Uint4B
+0x084 HeapDeCommitFreeBlockThreshold : Uint4B
+0x088 NumberOfHeaps : Uint4B
+0x08c MaximumNumberOfHeaps : Uint4B
+0x090 ProcessHeaps : Ptr32 Ptr32 Void
+0x094 GdiSharedHandleTable : Ptr32 Void
+0x098 ProcessStarterHelper : Ptr32 Void
+0x09c GdiDCAttributeList : Uint4B
+0x0a0 LoaderLock : Ptr32 Void
+0x0a4 OSMajorVersion : Uint4B
+0x0a8 OSMinorVersion : Uint4B
+0x0ac OSBuildNumber : Uint2B
+0x0ae OSCSDVersion : Uint2B
+0x0b0 OSPlatformId : Uint4B
+0x0b4 ImageSubsystem : Uint4B
+0x0b8 ImageSubsystemMajorVersion : Uint4B
+0x0bc ImageSubsystemMinorVersion : Uint4B
+0x0c0 ImageProcessAffinityMask : Uint4B
+0x0c4 GdiHandleBuffer : [34] Uint4B
+0x14c PostProcessInitRoutine : Ptr32 void 
+0x150 TlsExpansionBitmap : Ptr32 Void
+0x154 TlsExpansionBitmapBits : [32] Uint4B
+0x1d4 SessionId : Uint4B
+0x1d8 AppCompatFlags : _ULARGE_INTEGER
+0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER
+0x1e8 pShimData : Ptr32 Void
+0x1ec AppCompatInfo : Ptr32 Void
+0x1f0 CSDVersion : _UNICODE_STRING
+0x1f8 ActivationContextData : Ptr32 Void
+0x1fc ProcessAssemblyStorageMap : Ptr32 Void
+0x200 SystemDefaultActivationContextData : Ptr32 Void
+0x204 SystemAssemblyStorageMap : Ptr32 Void
+0x208 MinimumStackCommit : Uint4B

 

Example of this process needs to read image base, the following code, so easy ...

_asm
{
mov eax,fs:[30h];
mov ebx,[eax+08h];
mov ImageBaseAddres,ebx;
}
printf("ImageBaseAddress:0x%x\n",PEB);

Whether the need for basic debugging process is detected (commissioning in endless war AntiDebug the virus to anti-ah ...... ......)

_asm 
{ 
MOV EAX, FS: [30h]; 
MOV EBX, [EAX + 02h]; 
MOV the PEB, EBX; 
} 
the printf ( " current system debug: 0x% X \ n- " , the PEB);

 

Reproduced in: https: //blog.csdn.net/chriz_w/article/details/52096552

Guess you like

Origin www.cnblogs.com/gd-luojialin/p/11856289.html