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

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable  (Leído 3,212 veces)
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
[SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
« en: 7 Abril 2009, 19:01 pm »

Codigo relativo a este post:
Citar



Código
  1. '---------------------------------------------------------------------------------------
  2. ' Modulo    : mPatchExe
  3. ' Autor     : Karcrack
  4. ' Fecha-Hora: 07/04/2009  18:43
  5. ' Finalidad : Deshabilita cualquier ejecutable
  6. '---------------------------------------------------------------------------------------
  7.  
  8. Option Explicit
  9.  
  10. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal L As Long)
  11.  
  12. Private Enum ImageSignatureTypes
  13.    IMAGE_DOS_SIGNATURE = &H5A4D     ''\\ MZ
  14.    IMAGE_OS2_SIGNATURE = &H454E     ''\\ NE
  15.    IMAGE_OS2_SIGNATURE_LE = &H454C  ''\\ LE
  16.    IMAGE_VXD_SIGNATURE = &H454C     ''\\ LE
  17.    IMAGE_NT_SIGNATURE = &H4550      ''\\ PE\0\0
  18. End Enum
  19.  
  20. Private Type IMAGE_DOS_HEADER
  21.    e_magic As Integer        ' Magic number
  22.    e_cblp As Integer         ' Bytes on last page of file
  23.    e_cp As Integer           ' Pages in file
  24.    e_crlc As Integer         ' Relocations
  25.    e_cparhdr As Integer      ' Size of header in paragraphs
  26.    e_minalloc As Integer     ' Minimum extra paragraphs needed
  27.    e_maxalloc As Integer     ' Maximum extra paragraphs needed
  28.    e_ss As Integer           ' Initial (relative) SS value
  29.    e_sp As Integer           ' Initial SP value
  30.    e_csum As Integer         ' Checksum
  31.    e_ip As Integer           ' Initial IP value
  32.    e_cs As Integer           ' Initial (relative) CS value
  33.    e_lfarlc As Integer       ' File address of relocation table
  34.    e_ovno As Integer         ' Overlay number
  35.    e_res(0 To 3) As Integer  ' Reserved words
  36.    e_oemid As Integer        ' OEM identifier (for e_oeminfo)
  37.    e_oeminfo As Integer      ' OEM information; e_oemid specific
  38.    e_res2(0 To 9) As Integer ' Reserved words
  39.    e_lfanew As Long          ' File address of new exe header
  40. End Type
  41.  
  42. ' MSDOS File header
  43. Private Type IMAGE_FILE_HEADER
  44.    Machine As Integer
  45.    NumberOfSections As Integer
  46.    TimeDateStamp As Long
  47.    PointerToSymbolTable As Long
  48.    NumberOfSymbols As Long
  49.    SizeOfOptionalHeader As Integer
  50.    characteristics As Integer
  51. End Type
  52.  
  53. ' Directory format.
  54. Private Type IMAGE_DATA_DIRECTORY
  55.    VirtualAddress As Long
  56.    Size As Long
  57. End Type
  58.  
  59. ' Optional header format.
  60. Const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16
  61.  
  62. Private Type IMAGE_OPTIONAL_HEADER
  63.    ' Standard fields.
  64.    Magic As Integer
  65.    MajorLinkerVersion As Byte
  66.    MinorLinkerVersion As Byte
  67.    SizeOfCode As Long
  68.    SizeOfInitializedData As Long
  69.    SizeOfUnitializedData As Long
  70.    AddressOfEntryPoint As Long
  71.    BaseOfCode As Long
  72.    BaseOfData As Long
  73.    ' NT additional fields.
  74.    ImageBase As Long
  75.    SectionAlignment As Long
  76.    FileAlignment As Long
  77.    MajorOperatingSystemVersion As Integer
  78.    MinorOperatingSystemVersion As Integer
  79.    MajorImageVersion As Integer
  80.    MinorImageVersion As Integer
  81.    MajorSubsystemVersion As Integer
  82.    MinorSubsystemVersion As Integer
  83.    W32VersionValue As Long
  84.    SizeOfImage As Long
  85.    SizeOfHeaders As Long
  86.    CheckSum As Long
  87.    SubSystem As Integer
  88.    DllCharacteristics As Integer
  89.    SizeOfStackReserve As Long
  90.    SizeOfStackCommit As Long
  91.    SizeOfHeapReserve As Long
  92.    SizeOfHeapCommit As Long
  93.    LoaderFlags As Long
  94.    NumberOfRvaAndSizes As Long
  95.    DataDirectory(0 To IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1) As IMAGE_DATA_DIRECTORY
  96. End Type
  97.  
  98. Private Type IMAGE_NT_HEADERS
  99.    Signature As Long
  100.    FileHeader As IMAGE_FILE_HEADER
  101.    OptionalHeader As IMAGE_OPTIONAL_HEADER
  102. End Type
  103.  
  104. ' Section header
  105. Const IMAGE_SIZEOF_SHORT_NAME = 8
  106.  
  107. Private Type IMAGE_SECTION_HEADER
  108.   SecName As String * IMAGE_SIZEOF_SHORT_NAME
  109.   VirtualSize As Long
  110.   VirtualAddress  As Long
  111.   SizeOfRawData As Long
  112.   PointerToRawData As Long
  113.   PointerToRelocations As Long
  114.   PointerToLinenumbers As Long
  115.   NumberOfRelocations As Integer
  116.   NumberOfLinenumbers As Integer
  117.   characteristics  As Long
  118. End Type
  119.  
  120. '---------------------------------------------------------------------------------------
  121. ' Procedimiento : PatchExe
  122. ' Autor         : Karcrack
  123. ' Fecha         : 07/04/2009
  124. ' Parametro(s)  : sPath -> La ruta del fichero
  125. ' Return        : True si todo fue bien
  126. '---------------------------------------------------------------------------------------
  127.  
  128. Public Function PatchExe(ByVal sPath As String) As Boolean
  129.    On Error GoTo Fallo
  130.    Dim IDH             As IMAGE_DOS_HEADER
  131.    Dim INH             As IMAGE_NT_HEADERS
  132.    Dim ISH()           As IMAGE_SECTION_HEADER
  133.  
  134.    Dim bvCode()        As Byte
  135.    Dim PE              As Long
  136.    Dim i               As Long
  137.    Dim Section         As Long
  138.  
  139.    bvCode = ReadFile(sPath)                                                        'Leemos el fichero
  140.  
  141.    Call CopyMemory(IDH, bvCode(0), Len(IDH))                                       'Leemos la info del PE
  142.    Call CopyMemory(INH, bvCode(IDH.e_lfanew), Len(INH))                            'Leemos la info del PE
  143.  
  144.    For i = 0 To INH.FileHeader.NumberOfSections - 1
  145.        ReDim Preserve ISH(0 To i)
  146.        Call CopyMemory(ISH(i), bvCode(IDH.e_lfanew + Len(INH) + Len(ISH(i)) * i), Len(ISH(i)))
  147.        If (INH.OptionalHeader.AddressOfEntryPoint => ISH(i).VirtualAddress) And (INH.OptionalHeader.AddressOfEntryPoint =< ISH(i).VirtualAddress + ISH(i).VirtualSize) Then
  148.            Section = i
  149.            Exit For
  150.        End If
  151.    Next i
  152.  
  153.    bvCode(INH.OptionalHeader.AddressOfEntryPoint - ISH(i).VirtualAddress + ISH(i).PointerToRawData) = &HC3 'Parcheamos el fichero (C3=RET)
  154.  
  155.    Call SaveFile(bvCode, sPath)
  156.  
  157.    PatchExe = True                                                                 'Todo funciono
  158.    Exit Function                                                                   'Salimos
  159. Fallo:
  160.    PatchExe = False                                                                'Algo ha ido mal :S
  161. End Function
  162.  
  163.  
  164. '---------------------------------------------------------------------------------------
  165. ' Procedimiento : ReadFile
  166. ' Autor         : Karcrack
  167. ' Fecha         : 07/04/2009
  168. ' Parametro(s)  : sPath -> La ruta del fichero
  169. ' Return        : Devuelve un Byte array con los bytes del fichero
  170. '---------------------------------------------------------------------------------------
  171.  
  172. Private Function ReadFile(ByVal sPath As String) As Byte()
  173.    Dim bvTmp()         As Byte
  174.  
  175.    Open sPath For Binary As #1
  176.        ReDim bvTmp(0 To LOF(1) - 1)
  177.        Get #1, , bvTmp
  178.    Close #1
  179.  
  180.    ReadFile = bvTmp
  181. End Function
  182.  
  183.  
  184. '---------------------------------------------------------------------------------------
  185. ' Procedimiento : SaveFile
  186. ' Autor         : Karcrack
  187. ' Fecha         : 07/04/2009
  188. ' Parametro(s)  : bvData() -> Array de datos
  189. '                 sPath    -> Ruta de guardado
  190. '---------------------------------------------------------------------------------------
  191.  
  192. Private Sub SaveFile(ByRef bvData() As Byte, ByVal sPath As String)
  193.    Open sPath For Binary As #1
  194.        Put #1, , bvData
  195.    Close #1
  196. End Sub
  197.  


« Última modificación: 7 Abril 2009, 19:58 pm por Karcrack » En línea

el_c0c0


Desconectado Desconectado

Mensajes: 307


Ver Perfil
Re: [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
« Respuesta #1 en: 8 Abril 2009, 03:27 am »

muy interesante, esta seria la forma logica, aunque reemplazando 2 o 3 kb del principio ya lo cagas.
saludos


En línea

'-     coco
"Te voy a romper el orto"- Las hemorroides
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
« Respuesta #2 en: 8 Abril 2009, 10:38 am »

muy interesante, esta seria la forma logica, aunque reemplazando 2 o 3 kb del principio ya lo cagas.
saludos
Si, solo con reemplazar el primer byte (M) ya no funciona... pero muestra una fea pantalla negra y se pierde el icono...
En línea

Dessa


Desconectado Desconectado

Mensajes: 624



Ver Perfil
Re: [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
« Respuesta #3 en: 8 Abril 2009, 11:57 am »


Está bueno el code, se mantiene todo tal cual, icono y propiededes del ejecutable, me sirve para seguridad.

Saludos
« Última modificación: 9 Abril 2009, 00:00 am por Dessa » En línea

Adrian Desanti
YST


Desconectado Desconectado

Mensajes: 965


I'm you


Ver Perfil WWW
Re: [SOURCE][RET Exe Corruption] Corrompe cualquier Ejecutable
« Respuesta #4 en: 8 Abril 2009, 14:57 pm »

Tambien modificando el SizeOfImage a un valor malo te da que no es una aplicación valida , aunque muy util el metodo para desabilitar programas como el regedit ;) .
En línea



Yo le enseñe a Kayser a usar objetos en ASM
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
¿Generar ejecutable para que funcione en cualquier PC?
Programación Visual Basic
theluigy13etv 8 22,140 Último mensaje 21 Marzo 2012, 04:24 am
por theluigy13etv
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines