elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 08:31  


Tema destacado: [AIO elhacker.NET] Compilación herramientas análisis y desinfección malware

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)  (Leído 1,626 veces)
Karcrack


Desconectado Desconectado

Mensajes: 2.192


Se siente observado ¬¬'


Ver Perfil
[VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« en: 23 Abril 2011, 15:34 »

Código
'---------------------------------------------------------------------------------------
' Module    : mAPIPatchByID
' Author    : Karcrack
' Now       : 23/04/2011 14:13
' Purpose   : Patch API functions by ID
' History   : 23/04/2011 First cut .........................................................
'---------------------------------------------------------------------------------------

Option Explicit
 
'KERNEL32
Private Declare Function NtWriteVirtualMemory Lib "NTDLL" (ByVal hProcess As Long, ByRef lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
 
Public Sub PatchAPIAddr(ByVal lID As Long, ByVal lAddr As Long)
   Dim hInstance       As Long
   Dim lExtTablePtr    As Long
 
   hInstance = App.hInstance
   lExtTablePtr = GetDWORD(GetDWORD((hInstance + GetDWORD(hInstance + GetDWORD(hInstance + &H3C) + &H28)) + &H1) + &H30) + &H234
   If GetDWORD(lExtTablePtr + &H4) >= lID Then
       Call PutDWORD(GetDWORD(GetDWORD(GetDWORD(lExtTablePtr) + (8 * lID) + 4) + &H19), lAddr)
   End If
End Sub
 
Private Sub PutDWORD(ByVal lAddr As Long, ByVal lDWORD As Long)
   Call NtWriteVirtualMemory(-1, ByVal lAddr, lDWORD, 4, ByVal 0&)
End Sub
 
Private Function GetDWORD(ByVal lAddr As Long) As Long
   Call NtWriteVirtualMemory(-1, GetDWORD, ByVal lAddr, 4, ByVal 0&)
End Function

Para que sirve? Para cargar APIs dinamicamente :D

Un ejemplo:
Código
Option Explicit
 
'USER32
Private Declare Function MessageBox Lib "nadaesloqueparece" Alias "Karcrack" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
'KERNEL32
Private Declare Function GetProcAddress Lib "KERNEL32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function LoadLibrary Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
 
Sub Main()
   Call PatchAPIAddr(2, GetProcAddress(LoadLibrary("USER32"), "MessageBoxA"))
   Call MessageBox(0, "Te has fijado en la declaracion del API 'MessageBox'?", "Hola :)", 0)
End Sub
 
Otro un poco mas enrevesado:
Código
Option Explicit
 
'USER32
Private Declare Function fnc1& Lib "whatever" (ByVal a&, ByVal b&, ByVal c&, ByVal d&)
Private Declare Function fnc2& Lib "whatever" (ByVal a&, ByVal b&)
'KERNEL32
Private Declare Function GetProcAddress Lib "KERNEL32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function LoadLibrary Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
 
Private Const u32$ = "ZXJW87"
Private Const msgbx$ = "RjxxfljGt}\"
Private Const ktmr$ = "PnqqYnrjw"
Private Const stmr$ = "XjyYnrjw"
Private x&
Private bo&
 
Sub Main()
   Dim p&
 
   p = GetProcAddress(LoadLibrary(d(u32)), d(stmr))
   Call PatchAPIAddr(3, p)
   x = fnc1(0, 0, 2 * 1000, AddressOf tproc)
   p = GetProcAddress(LoadLibrary(d(u32)), d(msgbx))
   Call PatchAPIAddr(3, p)
   p = GetProcAddress(LoadLibrary(d(u32)), d(ktmr))
   Call PatchAPIAddr(2, p)
   bo = 1
   While bo
       DoEvents
   Wend
End Sub
 
Private Function d$(s$)
   Dim i&
   d = s
   For i = 1 To Len(d)
       Mid$(d, i, 1) = Chr$(Asc(Mid$(d, i, 1)) - 5)
   Next i
End Function
 
Private Function tproc&(ByVal a&, ByVal b&, ByVal c&, ByVal d&)
   If fnc1(0, StrPtr("Seguimos?"), StrPtr(":)"), vbYesNo) = vbNo Then
       bo = 0
       Call fnc2(0, x)
   End If
End Function

Los ejemplos han de ir en un modulo aparte puesto después del modulo 'mAPIPatchByID' para que los IDs se correspondiesen... en caso contrario hay que calcular los IDs usando por ejemplo el OllyDbg :P

Cualquier duda preguntad!


En línea

Abronsius

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #1 en: 24 Abril 2011, 16:04 »

Excellent !!!! bye bye CallAPI


En línea
CAR3S?


Desconectado Desconectado

Mensajes: 331


Level xXx


Ver Perfil
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #2 en: 24 Abril 2011, 16:35 »

Diria que esta bueno.... pero no entendi para que sirve  >:D
En línea
Swellow

Desconectado Desconectado

Mensajes: 36


Ver Perfil
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #3 en: 24 Abril 2011, 19:22 »

ÔMG! You are the best Karcrack. It seems pretty hard to use, can you give some more explanations please?
En línea
raul338
Moderador
***
Desconectado Desconectado

Mensajes: 2.372


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #4 en: 25 Abril 2011, 01:00 »

Los ejemplos han de ir en un modulo aparte puesto después del modulo 'mAPIPatchByID' para que los IDs se correspondiesen... en caso contrario hay que calcular los IDs usando por ejemplo el OllyDbg :P

Interesantisimo, pero ... no entiendo como sacar los ids :P
En línea

LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 693


Seguime


Ver Perfil WWW
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #5 en: 25 Abril 2011, 02:09 »

Hola, me da error 53 no se ha encontrado el archivo nadaesloqueparece, estoy en windows 7 32 bits
el id seria el ordinal del MessageBoxA ? , no testie si es el 2 quizas ese sea el problema.

Saludos.
En línea

Abronsius

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #6 en: 25 Abril 2011, 02:42 »

Hola, me da error 53 no se ha encontrado el archivo nadaesloqueparece, estoy en windows 7 32 bits
el id seria el ordinal del MessageBoxA ? , no testie si es el 2 quizas ese sea el problema.

Saludos.

Compile, Open OllyDbg, Watch Api Order, set proper ID in source, recompile :)
En línea
Karcrack


Desconectado Desconectado

Mensajes: 2.192


Se siente observado ¬¬'


Ver Perfil
Re: [VB6][SNIPPET] mAPIPatchByID - Carga APIs dinamicamente (Late binding)
« Respuesta #7 en: 26 Abril 2011, 16:27 »

@LeandroA: No se usan los ordinales de las funciones, estos varian en cada version de W$, se utiliza el orden en el que estan declaradas las funciones en las estructuras del VB6 :D

You are right @Abronsius :)

He hecho una version que lee los primeros cuatro bytes del nombre de la funcion... mas sencilla de usar, no hay que revisar el orden:
Código
Private Sub PatchAPIAddr(ByVal lHash As Long, ByVal lAddr As Long)
   Dim lExtTablePtr    As Long
   Dim lPtr            As Long
   Dim i               As Long
   lExtTablePtr = GetDWORD(GetDWORD((App.hInstance + GetDWORD(App.hInstance + GetDWORD(App.hInstance + &H3C) + &H28)) + &H1) + &H30) + &H234
 
   For i = 0 To GetDWORD(lExtTablePtr + &H4)
       lPtr = GetDWORD(GetDWORD(lExtTablePtr) + (8 * i) + 4)
       If GetDWORD(GetDWORD(lPtr + 4)) = lHash Then
           Call PutDWORD(GetDWORD(lPtr + &H19), lAddr)
           Exit For
       End If
   Next i
End Sub

Ejemplo:
Código:
Private Declare Function MessageBoxA Lib "" Alias "01" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

sub Main()
  PatchAPIAddr(&H3130,pPunteroDeMessageBoxA)
  MessageBoxA(0, "HOOLA", ":D",0)
end

Saludos :D
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
incrementar un array (php) dinamicamente
Desarrollo Web
ayabass 3 1,296 Último mensaje 19 Enero 2005, 02:21
por -Riven-Ward-
respawning too late
GNU/Linux
kakalott 0 248 Último mensaje 7 Enero 2006, 08:13
por kakalott
Introduccion a APIs y como evitar el uso de MSWINSCK.OCX con APIs
Programación Visual Basic
Achernar 5 1,238 Último mensaje 5 Julio 2007, 23:43
por Achernar
Polimorfismo y Objetos creados dinámicamente C++ « 1 2 »
Programación C/C++
D4RIO 21 8,307 Último mensaje 10 Enero 2008, 21:02
por darkraider
Problema con JComboBox creada Dinamicamente
Java
Fran88 3 2,162 Último mensaje 31 Agosto 2009, 09:59
por Fran88
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines