elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 16 17 18 19 20
141  Seguridad Informática / Análisis y Diseño de Malware / Re: [AYUDA] formato PE obtener dirección fisica de secciones y mas cosas en: 5 Septiembre 2011, 18:33 pm
http://www.sendspace.com/file/eiwwul

Ahí les dejo un código en C con todas las estructuras hechas a mano y la lectura de cada campo ;).

Un saludo.
The Swash
142  Seguridad Informática / Análisis y Diseño de Malware / Re: [AYUDA] formato PE obtener dirección fisica de secciones y mas cosas en: 4 Septiembre 2011, 04:01 am
  • Usas una estructura ISH y el tamaño que tiene por defecto es: 0x28 bytes como vas guardar más de una sección ahí?, no tienes un array.
  • Te recomiendo trabajar con archivo proyectado en memoria y para las estructuras punteros.
  • + (sizeof(ish)*(ifh.NumberOfSections-1)) + suma; + suma está sobrando ya lo haces con la multiplicación.

Un saludo ;)
143  Seguridad Informática / Análisis y Diseño de Malware / Re: Indetectando AVIRA en: 17 Julio 2011, 14:31 pm
Revisar las rutinas de las detecciones con OllyDBG sería lo más prudente antes de hacer cambios, y con respecto a la tecera firma puedes quitarla moviendo RtlMoveMemory a otro sector, y quizá para eso necesites leer algunos documentos sobre el Formato PE.

Un saludo.
144  Seguridad Informática / Análisis y Diseño de Malware / [MASM][UserMode]Hook OpenProcess en: 11 Julio 2011, 23:55 pm
Código
  1. .386
  2. .model flat, stdcall
  3. option casemap:none
  4.  
  5. include C:\masm32\include\windows.inc
  6. include C:\masm32\include\kernel32.inc
  7. includelib C:\masm32\lib\kernel32.lib
  8.  
  9. .data
  10. ProcessId        dd 0
  11. ProcessProtect   dd 0
  12. hProcess         dd 0
  13. APIAddress       dd 0
  14. SnapshotHandle   dd 0
  15. DistanceFunc     dd 0
  16. fAddress         dd 0
  17. Bytesw           dd 0
  18. _JMP             db 5 dup(?)
  19. Diference        dd 0
  20. Buff             db 0
  21. _PROCESSENTRY32  PROCESSENTRY32 <?>
  22. Process          db "taskmgr.exe",0   ;Process to Hook
  23. API              db "OpenProcess",0
  24. lLibrary         db "kernel32.dll",0
  25. Protect          db "notepad.exe",0   ;Process to Protect
  26.  
  27. .code
  28. start:
  29. mov dword ptr[_PROCESSENTRY32.dwSize], 0128h
  30.  
  31. _Begin:
  32. invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
  33. mov dword ptr[SnapshotHandle],eax
  34.  
  35. _Cmp:
  36.    invoke Process32Next,dword ptr[SnapshotHandle], addr _PROCESSENTRY32
  37.    mov edi, eax
  38.    invoke lstrcmp,addr Process, addr _PROCESSENTRY32.szExeFile
  39.    or eax, eax
  40.    jz _GetPID2
  41.    invoke lstrcmp,addr Protect, addr _PROCESSENTRY32.szExeFile
  42.    or eax, eax
  43.    jz _GetPID
  44.  
  45. _Continue:    
  46.    or edi, edi
  47.    jz _Exit
  48.    jnz _Cmp
  49.  
  50. _Proc:    
  51.    invoke GetModuleHandle, addr lLibrary
  52.    invoke GetProcAddress, eax, addr API
  53.    mov dword ptr[APIAddress], eax
  54.  
  55.    mov eax, offset _EndHook
  56.    mov ebx, offset _Hook
  57.    sub eax, ebx
  58.    mov dword ptr[DistanceFunc], eax
  59.  
  60.    invoke OpenProcess,PROCESS_ALL_ACCESS,FALSE,dword ptr [ProcessId]
  61.    mov dword ptr [hProcess], eax
  62.    invoke ReadProcessMemory,dword ptr[hProcess], dword ptr [APIAddress], addr Buff, 1, addr Bytesw
  63.    cmp byte ptr [Buff], 0E9h
  64.    jz _Exit
  65.    invoke VirtualAllocEx,dword ptr [hProcess],NULL,dword ptr[DistanceFunc],MEM_RESERVE or             MEM_COMMIT,PAGE_EXECUTE_READWRITE
  66.    mov dword ptr [fAddress], eax
  67.    mov ecx, offset _Hook
  68.    invoke VirtualProtect,ecx,10,PAGE_EXECUTE_READWRITE,addr Bytesw
  69.    mov ebx, dword ptr[APIAddress]
  70.    add ebx, 5
  71.    mov dword ptr[_Hook + 1], ebx
  72.    mov ebx, dword ptr[ProcessProtect]
  73.    mov dword ptr[_Hook + 6], ebx
  74.    mov ecx, offset _Hook
  75.    invoke WriteProcessMemory,dword ptr[hProcess], dword ptr [fAddress], ecx, dword ptr [DistanceFunc], addr Bytesw
  76.    invoke VirtualProtectEx,dword ptr[hProcess],dword ptr [APIAddress], 5, PAGE_EXECUTE_READWRITE, addr Bytesw
  77.    mov byte ptr [_JMP], 0E9h
  78.    mov edx, dword ptr [fAddress]
  79.    add dword ptr [APIAddress],5
  80.    sub edx, dword ptr [APIAddress]
  81.    mov dword ptr [_JMP +1], edx
  82.    sub dword ptr [APIAddress], 5
  83.    invoke WriteProcessMemory,dword ptr [hProcess], dword ptr[APIAddress], addr _JMP, 5, addr Bytesw
  84.    invoke CloseHandle, dword ptr [hProcess]
  85.  
  86. _Exit:
  87.    invoke ExitProcess,0
  88.  
  89. _Hook:
  90.    mov eax, 00000000h ; API Address
  91.    mov ecx, 00000000h ; PID
  92.  
  93.    push ebp           ; Stack frame
  94.    mov ebp, esp
  95.  
  96.    pushad
  97.    cmp ecx, dword ptr [ebp + 10h]
  98.    jz _Hooked                     ; If is equal jump to Hooked
  99.    popad                          ; Restaure registers
  100.    jmp eax                        ; Jump to API + 5
  101.  
  102. _Hooked:
  103.    popad
  104.    mov esp, ebp
  105.    pop ebp
  106.    mov eax, 0
  107.    retn 0Ch
  108. _EndHook:    
  109.  
  110. _GetPID:
  111.    mov eax, dword ptr [_PROCESSENTRY32.th32ProcessID]
  112.    mov dword ptr[ProcessProtect],eax
  113.    jmp _Found
  114.  
  115. _GetPID2:
  116.    mov eax, dword ptr [_PROCESSENTRY32.th32ProcessID]
  117.    mov dword ptr[ProcessId],eax
  118.    jmp _Cmp2
  119.  
  120. _Found:
  121.    cmp [ProcessId],0
  122.    jz _Cmp
  123.    jmp _Cmp2
  124.  
  125. _Cmp2:
  126.    cmp dword ptr[ProcessProtect],0
  127.    jnz _Proc
  128.    jmp _Cmp
  129.  
  130. end start

Información:
Este es el pequeño ejemplo de enganchar(Hookear) a la función Kernel32.OpenProcess la cual permite abrir un proceso por muchos motivos (Cerrarlo, obtener información, modificar, etc).

¿Que hace exactamente?
Sencillamente enganchamos esa función y así podemos verificar si quieren abrir el proceso que nosotros designemos a proteger.

Ustedes pueden hacerle su respectiva adaptación a condiciones etc, pero me enfoque en un ejemplo y en aprender.

Mis mayores agradecimientos a Lelouch (Como me soportaste xD) y a [Zero].
Dedicado a todos mis mentores :P (Sobra mencionarlos)
Saludos.

145  Seguridad Informática / Análisis y Diseño de Malware / [Documento]Formato PE bajo Windows - Español en: 30 Junio 2011, 19:15 pm

Información:
Este documento trata de explicar la mayor parte de la estructura de los archivos ejecutables de Windows, esta basado en la información oficial de microsoft y su ventaja es que esta en lengua española bien graficado y explicado.

Descarga - Lectura online:
http://www.box.net/shared/4156t5rfv8tr5v4bgo19
146  Seguridad Informática / Análisis y Diseño de Malware / [Tutorial]Relocaciones en ejecutables en: 5 Junio 2011, 01:36 am
Que tal amigos, les traigo un pequeño tutorial que me quedo algo corto porque no me pude extender más en el tema pero traté de explicarlo lo mejor posible.
Espero les guste.

Link:
Código:
http://www.box.net/shared/v9pcb3bzzv
147  Seguridad Informática / Análisis y Diseño de Malware / Re: Ejecución de Archivos desde Memoria [Base Relocation] en: 3 Junio 2011, 00:58 am
A mi parecer la dependencia exacta de que todas las direcciónes físicas sean realocadas da un porcentaje muy alto de fallar al cargar un ejecutable en otro espacio de memoria diferente a su ImageBase, tenía que prácticar Relocations así que decidí intentarlo en Delphi y vaya trabajo me ha dado. Gracias [Zero]
Código
  1. IMAGE_IMPORT_DESCRIPTOR = packed record
  2.    OriginalFirstThunk: DWORD;
  3.    TimeDateStamp: DWORD;
  4.    ForwarderChain: DWORD;
  5.    Name: DWORD;
  6.    FirstThunk: DWORD;
  7. end;
  8.  
  9. IMAGE_RELOCATIONS = packed record
  10.    PageRVA: DWORD;
  11.    Size:    DWORD;
  12. end;
  13.  
  14. type
  15. TArrayOfByte = array of byte;
  16. TArrayOfISH = array of TIMAGESECTIONHEADER;
  17. PIMAGEIMPORTDESCRIPTOR = ^IMAGE_IMPORT_DESCRIPTOR;
  18. PIMAGERELOCATIONS = ^IMAGE_RELOCATIONS;
  19.  
  20. function RVATOOFFSET(RVA:DWORD): DWORD;
  21. var
  22. i,n: integer;
  23. begin
  24.     for i:= 0 to IFH.NumberOfSections-1 do
  25.     begin
  26.          n:= (ish[i].VirtualAddress + ish[i].SizeOfRawData)-RVA ;
  27.          if n > 0 then
  28.          begin
  29.               Result:=(RVA - ish[i].VirtualAddress) + ish[i].PointerToRawData;
  30.               break;
  31.          end;
  32.     end;
  33.     if RVA < ish[0].VirtualAddress then Result:= RVA;
  34. end;
  35.  
  36.  
  37. procedure Execute();
  38. var
  39. IDH:         PIMAGEDOSHEADER;
  40. IOH:         PIMAGEOPTIONALHEADER;
  41. IDD:         Array[0..15] of PIMAGEDATADIRECTORY;
  42. IID:         PIMAGEIMPORTDESCRIPTOR;
  43. IR:          PIMAGERELOCATIONS;
  44. aBuffer:     TArrayOfByte;
  45. FileLen:     DWORD;
  46. hFile:       THANDLE;
  47. BytesRead:   DWORD;
  48. Signature:   PDWORD;
  49. i:           DWORD;
  50. Acumulador:  DWORD;
  51. BaseAddress: Pointer;
  52. lFunction:   PDWORD;
  53. TempAddress: DWORD;
  54. EP:          DWORD;
  55. aBlock:      DWORD;
  56. rBlock:      PWORD;
  57. dType:       DWORD;
  58. Offset:      PDWORD;
  59. Delta:       DWORD;
  60. rOffset:     DWORD;
  61. Ordinal:     DWORD;
  62. GPA:         function(hModule: Cardinal; Ordinal: Cardinal): Pointer; stdcall;
  63. begin
  64.     hFile:= CreateFileA('C:\Archivos de programa\Opera\opera.exe',GENERIC_READ, FILE_SHARE_READ,nil, OPEN_EXISTING,0,0);
  65.     If hFile <> INVALID_HANDLE_VALUE then
  66.     begin
  67.          FileLen:= GetFileSize(hFile,nil);
  68.          SetLength(aBuffer,FileLen);
  69.          ReadFile(hFile,aBuffer[0],FileLen,BytesRead,nil);
  70.     end;
  71.     GPA:= GetProcAddress(GetModuleHandle('kernel32'),'GetProcAddress');
  72.     CloseHandle(hFile);
  73.     IDH:= Pointer(aBuffer);
  74.     if IDH.e_magic = IMAGE_DOS_SIGNATURE then
  75.     begin
  76.          Signature := @aBuffer[IDH._lfanew];
  77.          if Signature^ = IMAGE_NT_SIGNATURE then
  78.          begin
  79.               IFH:= @aBuffer[IDH._lfanew + 4];
  80.               IOH:= @aBuffer[IDH._lfanew + 24];
  81.               Acumulador:= 0;
  82.               for i:=0 to 15 do
  83.               begin
  84.                    IDD[i]:= @aBuffer[IDH._lfanew + 120 + Acumulador];
  85.                    Acumulador:= Acumulador+8;
  86.               end;
  87.               SetLength(ISH, IFH.NumberOfSections-1);
  88.               Acumulador := 0;
  89.               for i:=0 to IFH.NumberOfSections-1 do
  90.               begin
  91.                    CopyMemory(@ISH[i], @aBuffer[IDH._lfanew + 248 + Acumulador], 40);
  92.                    Acumulador:= Acumulador + 40;
  93.               end;
  94.               BaseAddress:= VirtualAlloc(nil, IOH.SizeOfImage, MEM_RESERVE or MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  95.               CopyMemory(BaseAddress, @aBuffer[0], IOH.SizeOfHeaders);
  96.               for i:=0 to IFH.NumberOfSections-1 do
  97.               begin
  98.                    CopyMemory(Pointer(DWORD(BaseAddress)+ISH[i].VirtualAddress), @aBuffer[ISH[i].PointerToRawData], ISH[i].SizeOfRawData);
  99.               end;
  100.                              Delta:= DWORD(BaseAddress) - IOH.ImageBase;
  101.               rOffset:= RVATOOFFSET(IDD[5].VirtualAddress);
  102.               IR:= @aBuffer[rOffset];
  103.               While(IR.PageRVA <> 0) do
  104.               begin
  105.                    aBlock:= (IR.Size - 8)div 2;
  106.                    rBlock:= Pointer(DWORD(IR) + 8);
  107.                    While(aBlock > 0) do
  108.                    begin
  109.                         dType:= (rBlock^ and $F000) div $1000;
  110.                         Offset:= Pointer(DWORD(rBlock^ and $FFF) + IR.PageRVA + DWORD(BaseAddress));
  111.                         if dType = 3 then
  112.                         begin
  113.                              Offset^:= Offset^ + Delta;
  114.                         end;
  115.                         rBlock:= Pointer(DWORD(rBlock)+ 2);
  116.                         aBlock:= aBlock - 1;
  117.                    end;
  118.                    IR:= Pointer(DWORD(IR)+ IR.Size);
  119.               end;
  120.               IID:= @aBuffer[RVATOOFFSET(IDD[1].VirtualAddress)];
  121.               While(IID.Name <> 0) do
  122.               begin
  123.                    lFunction:= Pointer(DWORD(BaseAddress) + IID.FirstThunk);
  124.                    While(lFunction^ <> 0) do
  125.                    begin
  126.                         if lFunction^ > $80000000 then
  127.                         begin
  128.                              Ordinal:= lFunction^-$80000000;
  129.                              TempAddress:= DWORD(GPA(LoadLibraryA(@aBuffer[RVATOOFFSET(IID.Name)]),Ordinal));
  130.                         end else
  131.                         begin
  132.                              TempAddress:= DWORD(GetProcAddress(LoadLibraryA(@aBuffer[RVATOOFFSET(IID.Name)]),@aBuffer[RVATOOFFSET(lFunction^+2)]));
  133.                         end;
  134.                         lFunction^:= TempAddress;
  135.                         lFunction:= Pointer(DWORD(lFunction)+4);
  136.                    end;
  137.                    IID:= Pointer(DWORD(IID)+20);
  138.               end;
  139.               EP:= IOH.AddressOfEntryPoint + DWORD(BaseAddress);
  140.               asm
  141.               mov eax, EP
  142.               jmp eax;
  143.               end;
  144.          end;
  145.     end;
  146. end;

PD: Algunos errores corregidos, añadido soporte para importación por ordinales.
148  Seguridad Informática / Análisis y Diseño de Malware / [Tutorial-SC]Cargando funciones importadas a mano! en: 22 Mayo 2011, 22:54 pm
Hola amigos, después de exactamente una semana vengo con otro documento que le tenía ganas y lo que más satisfacción me dio fue el código en ensamblador en el cual tardé 2 días pero bueno.
Espero les guste y hasta la próxima.

The Swash

Link:
Código:
http://www.box.net/shared/0alan9bock

Un saludo y agradecimientos especiales a [Zero]  ;)
149  Seguridad Informática / Análisis y Diseño de Malware / Ejemplo de infección mediante TLS Callbacks en: 16 Mayo 2011, 02:16 am
Que tal amigos, he leído un poco acerca del tema y haciendo pruebas logré instalar una rutina en el TLS Callbacks y quise compartirlo, espero sus críticas opiniones y recomendaciones.
Espero me disculpen si hay errores técnicos, Un saludo.

PD: Quiero agradecer a trompetin17evony y apokliptiko por sus recomendaciones.

Link:
Código:
http://www.box.net/shared/h0ra1953cn
150  Seguridad Informática / Análisis y Diseño de Malware / [MASM32] KernelBase Address + GetProcAddress en: 9 Mayo 2011, 02:23 am
Código
  1. .386
  2. .model flat, stdcall
  3. option casemap:none
  4. assume fs:nothing
  5.  
  6. .data
  7. GPA db "GetProcAddress",0
  8. Cont dd 0
  9.  
  10. .code
  11. start:
  12. mov eax, fs:[030h]    ; Get pointer of the PEB
  13. mov eax, [eax + 0ch]  ; Get pointer of PPEB_LDR_DATA
  14. mov eax, [eax + 0ch]  ; Get pointer of InLoadOrderModuleList
  15. mov eax, [eax]        ; Get InLoadOrderModuleList of next library "ntdll"
  16. mov eax, [eax]        ; Get InLoadOrderModuleList of next library "kernel32"
  17. mov eax, [eax + 018h] ; Get BaseAddress of "kernel32"
  18.  
  19. mov ecx, dword ptr[eax + 03ch]   ; Set PE Offset
  20. add ecx, 078h                    ; Set in DirectoryTable[0]
  21. mov edx, dword ptr [eax + ecx]   ; Get Export Table RVA
  22. add edx, eax                     ; Add KernelBase Address
  23. xor ebx, ebx                     ; Clean EBX
  24. add edx, 020h                    ; Set in addressofnames RVA
  25. mov ebx, dword ptr [edx]         ; Get RVA AddressOfNames Table
  26. add ebx, eax                     ; Add KernelBase Address
  27.  
  28. COMP:                   ; Rutine of compare strings with "GetProcAddress", incrementing Cont
  29. add ebx, 4
  30. inc [Cont]
  31. mov esi, dword ptr [ebx]
  32. add esi, eax
  33. lea edi, [GPA]
  34. mov ecx, 0Eh
  35. repe cmpsb
  36. jnz COMP
  37.  
  38. ;GetAddress
  39. xor ebx, ebx            ; Clean EBX
  40. add edx, 04h            ; Set on Table Ordinal RVA
  41. mov ebx, dword ptr[edx] ; Get first RVA of Ordinal
  42. add ebx, eax            ; Add KernelBase Address
  43. mov edi, eax            ; Save KernelBase Address in EDI
  44. xor eax, eax            ; Clean EAX
  45. mov al, 02h             ; Base of WORD
  46. mov esi, edx            ; Save Address of RVA Ordinal Table
  47. mul word ptr[Cont]      ; Mul Cont for get WORD
  48. mov [Cont], eax         ; Get new value in Cont
  49. xor eax, eax            ; Clean EAX
  50. add ebx, [Cont]         ; Add Cont to Address of Ordinal Table
  51. mov ax,word ptr[ebx]    ; Get Ordinal of GetProcAddress
  52. sub esi, 08h            ; Set in AddressOfFunctions
  53. mov ecx, [esi]          ; Get First pointer to Functions RVA
  54. add ecx, edi            ; Add KernelBase Address
  55. xor ebx, ebx            ; Clean EBX
  56. mov ebx, eax            ; Mov Ordinal to EBX for MUL
  57. mov eax, 04h            ; Base of DWORD
  58. mul ebx                 ; Calcule spaces to Get address bassed in (Address of First Function + Ordinal GetProcAddress
  59. add ecx, eax            ; Add spaces for Set Address in RVA of GetProcAddress
  60. mov ecx, [ecx]          ; Get RVA of GetProcAddress
  61. add ecx, edi            ; Add KernelBase Address
  62. end start

Agradecimientos a Shaddy, [Zero], Lelo, Thor, Psymera & todos los que me han ayudado.
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 16 17 18 19 20
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines