Build a simple sample. Code
is transferred to the buffer that is in the map does not file section, available for
. In this case, change the memory access is impossible, ie to put breaks in the memory will not work:
Code:
_imp__MessageBoxA proto :HANDLE, :PSTR, :PSTR, :ULONG
%NTERR macro
.if Eax
Int 3
.endif
endm
.data
$Message CHAR 16 DUP (?)
.code
include Gcbe.inc
%ALLOC macro vBase, vSize, vProtect, cSize, Reg32
mov vBase,NULL
mov vSize,cSize
invoke ZwAllocateVirtualMemory, NtCurrentProcess, addr vBase, 0, addr vSize, MEM_COMMIT, PAGE_READWRITE
mov Reg32,vBase
%NTERR
add vBase,cSize - X86_PAGE_SIZE
mov vSize,X86_PAGE_SIZE
invoke ZwProtectVirtualMemory, NtCurrentProcess, addr vBase, addr vSize, PAGE_NOACCESS, addr vProtect
%NTERR
endm
$Title CHAR "Ip's:",0
Ep proc
Local GpSize:ULONG
Local Snapshot:GP_SNAPSHOT
Local Protect:ULONG
Local CsBase:PVOID, CsSize:ULONG
Local BiBase:PVOID, BiSize:ULONG
Local ObjAttr:OBJECT_ATTRIBUTES
Local SectionSize:LARGE_INTEGER
Local SectionOffset:LARGE_INTEGER
Local ViewBase:PVOID, ViewSize:ULONG
Local SectionHandle:HANDLE
%ALLOC Snapshot.GpBase, GpSize, Protect, 200H * X86_PAGE_SIZE, Ebx
mov Snapshot.GpLimit,ebx
mov Snapshot.GpBase,ebx
lea ecx,Snapshot.GpLimit
push eax
push eax
push eax
push eax
push eax
push 4
push GCBE_PARSE_SEPARATE
push ecx
push dword ptr [_imp__MessageBoxA]
%GPCALL GP_PARSE
%NTERR
mov eax,Snapshot.GpLimit
xor edx,edx
sub eax,ebx
mov ecx,ENTRY_HEADER_SIZE
div ecx
invoke udw2str, Eax, addr $Message
%ALLOC CsBase, CsSize, Protect, 200H * X86_PAGE_SIZE, Esi
; %ALLOC BiBase, BiSize, Protect, 200H * X86_PAGE_SIZE, Edi
xor eax,eax
cld
mov ecx,sizeof(OBJECT_ATTRIBUTES)/4
lea edi,ObjAttr
mov dword ptr [SectionSize],100H * X86_PAGE_SIZE
mov dword ptr [SectionSize + 4],eax
rep stosd
mov ObjAttr.uLength,sizeof(OBJECT_ATTRIBUTES)
invoke ZwCreateSection, addr SectionHandle, SECTION_ALL_ACCESS, addr ObjAttr, addr SectionSize, PAGE_EXECUTE_READWRITE, SEC_COMMIT, NULL
%NTERR
mov ViewBase,eax
mov ViewSize,eax
mov dword ptr [SectionOffset],eax
mov dword ptr [SectionOffset + 4],eax
invoke ZwMapViewOfSection, SectionHandle, NtCurrentProcess, addr ViewBase, 0, 0, addr SectionOffset, addr ViewSize, ViewShare, NULL, PAGE_EXECUTE_READWRITE
%NTERR
push ViewBase ; push edi
push esi
push Snapshot.GpLimit
push Snapshot.GpBase
%GPCALL GP_BUILD_GRAPH
%NTERR
invoke ZwUnmapViewOfSection, NtCurrentProcess, ViewBase
%NTERR
invoke ZwMapViewOfSection, SectionHandle, NtCurrentProcess, addr ViewBase, 0, 0, addr SectionOffset, addr ViewSize, ViewShare, NULL, PAGE_EXECUTE_READ
%NTERR
push MB_OK
push offset $Title
push offset $Message
push eax
call ViewBase
ret
Ep endp
Possible to automatically generate a series of Gs-prefixes. This will make the debugger useless
The same manipulation can be done remap image.