DWORD = LONG
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: Karcrack en 21 Febrero 2011, 16:43 PMhttp://advancevb.com.ar/?p=521
Option Explicit
Private Declare Function CreateThread Lib "KERNEL32" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByRef lpParameter As Any, ByVal dwCreationFlags As Long, ByRef lpThreadId As Long) As Long
Private Declare Sub ExitThread Lib "KERNEL32" (ByVal dwExitCode As Long)
Private Declare Function TlsGetValue Lib "KERNEL32" (ByVal dwTlsIndex As Long) As Long
Private Declare Function TlsSetValue Lib "KERNEL32" (ByVal dwTlsIndex As Long, ByRef lpTlsValue As Any) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
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 Declare Function FreeLibrary Lib "KERNEL32" (ByVal hLibModule As Long) As Long
Private MemAddress As Long
Private TlsAddress As Long
Private TlsIndex As Long
Public Function CreateNewThread(ByVal hThreadProc As Long, Optional ByVal Param As Long = 0) As Long
If (MemAddress + TlsIndex) = 0 Then
Call InitTlsIndex: Call CopyMemory(TlsIndex, ByVal TlsAddress, Len(TlsIndex)) 'Retrieve TlsIndx from TlsAddress
MemAddress = TlsGetValue(TlsIndex)
End If
CreateNewThread = CreateThread(0, 0, hThreadProc, ByVal Param, 0, 0)
End Function
Public Sub InitThread()
Call TlsSetValue(TlsIndex, ByVal MemAddress) 'VB will use this address to store DLL error information and etcs.
End Sub
Private Sub InitTlsIndex()
'Tls Index's address of our thread.
Dim bB(40) As Byte, St As String
Dim hProc As Long, hLib As Long, i As Integer, j As Integer
hLib = LoadLibrary("MSVBVM60")
hProc = GetProcAddress(hLib, "__vbaSetSystemError")
Call CopyMemory(bB(0), ByVal (hProc), 40)
While bB(i) <> &HC3 'RETN
If bB(i) = &HFF And bB(i + 1) = &H35 Then
For j = i + 2 To i + 5
St = Hex(bB(j)) & St
Next
TlsAddress = Val("&H" & St): Exit Sub
End If
i = i + 1
Wend
Call FreeLibrary(hProc)
End Sub
Public Sub TerminateThread(ByVal dwExitCode As Long)
Call ExitThread(dwExitCode)
End Sub
Cita de: Karcrack en 26 Enero 2011, 16:52 PM
Ese tipo de modificaciones serian sobre el fichero compilado y en este proyecto me intereso en el codigo
Por cierto, estuve haciendo un poco de research y lanzo una buenisima idea para aquel que tenga tiempo ... Desde el header de un fichero compilado de VB6 se puede acceder a las cadenas de las APIs importadas, se cifran, se modifica tambien el header para que haga al Loader de VB6 ejecutar una pequeña shellcode que descifrará las cadenas de las APIs... para que quede mas claro:
- Abrimos el fichero compilado
- Leemos la cabecera del VB6 y recorremos las cadenas de las APIs cifrando cada una
- Inyectamos una shellcode en uno de los muchos huecos que quedan en el ejecutable
- Modificamos la cabecera del VB6 para que haga ejecutar al Loader nuestra shellcode primero
- La shellcode se encargará de descifrar las cadenas y saltar al EntryPoint original que había en el header del VB6
De esta forma las APIs serian descifradas en Runtime y en Scantime nuestras APIs serian irreconocibles
Cita de: Karcrack en 28 Noviembre 2010, 21:50 PM
Al final lo conseguiste
A ver si con lo que te dije se puede extener a cualquier estructura
Option Explicit
Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As Long) As Long
Private Type SA1D_STRUCT
Struct(23) As Byte
bData() As Byte
Length As Long
End Type
Private SA1D() As SA1D_STRUCT
Public Sub ByteToStruct(ByVal StructPtr As Long, ByRef bArray() As Byte)
Dim Count As Long
Dim i As Long
Do
ReDim Preserve SA1D(i): Call CopyMemory(SA1D(i).Length, bArray(Count), 4)
ReDim SA1D(i).bData(SA1D(i).Length)
Call CopyMemory(SA1D(i).bData(0), bArray(Count + 4), SA1D(i).Length)
Count = Count + 4 + SA1D(i).Length: i = i + 1
Loop Until (UBound(bArray) + 1 = Count)
For i = 0 To UBound(SA1D)
Call CopyMemory(SA1D(i).Struct(12), VarPtr(SA1D(i).bData(0)), 4) 'DataPtr
Call CopyMemory(SA1D(i).Struct(16), SA1D(i).Length, 4) 'LBound
Call CopyMemory(SA1D(i).Struct(0), 1, 2) 'Dims
Call CopyMemory(SA1D(i).Struct(4), 1, 4) 'ElementSize
Call CopyMemory(ByVal StructPtr + (i * 4), VarPtr(SA1D(i).Struct(0)), 4) 'SA1D Struct
Next i
End Sub
Public Sub StructToByte(ByVal StructPtr As Long, ByRef bReturn() As Byte, ParamArray VarType() As Variant)
Dim SafeArrayPtr As Long
Dim ArrayLength As Long
Dim ArrayPtr As Long
Dim i As Long
ReDim bReturn(0)
For i = 0 To UBound(VarType)
Select Case VarType(i)
Case vbByte:
'SafeArray1D Struct
Call CopyMemory(SafeArrayPtr, ByVal StructPtr + (i * 4), 4)
Call CopyMemory(ArrayPtr, ByVal SafeArrayPtr + 12, 4) 'DataPtr
Call CopyMemory(ArrayLength, ByVal SafeArrayPtr + 16, 4) 'LBound
'Data Size + Data
ReDim Preserve bReturn(UBound(bReturn) + 4 + ArrayLength)
Call CopyMemory(ByVal VarPtr(bReturn(UBound(bReturn) - 4 - ArrayLength)), ArrayLength, 4)
Call CopyMemory(ByVal VarPtr(bReturn(UBound(bReturn) - ArrayLength)), ByVal ArrayPtr, ArrayLength)
End Select
Next i
ReDim Preserve bReturn(UBound(bReturn) - 1)
End Sub
Private Type dd
ss() As Byte
jj() As Byte
tt() As Byte
End Type
Sub Main()
Dim told As dd
Dim tnew As dd
Dim bB() As Byte
told.ss = StrConv("hola", vbFromUnicode)
told.jj = StrConv("jeje", vbFromUnicode)
told.tt = StrConv("wakawaka", vbFromUnicode)
Call StructToByte(VarPtr(told), bB, vbByte, vbByte, vbByte)
Call ByteToStruct(VarPtr(tnew), bB)
MsgBox StrConv(tnew.jj, vbUnicode)
MsgBox StrConv(tnew.ss, vbUnicode)
MsgBox StrConv(tnew.tt, vbUnicode)
End Sub