Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: ghacke en 30 Septiembre 2008, 20:57 pm



Título: Usar API sin declarar [Problema] xD
Publicado por: ghacke en 30 Septiembre 2008, 20:57 pm
hola a todos !! estoy molestando en esta ocacion para pedir algo de ayuda O.O" !!

Hace unos dias, baje el codigo del troyano Shark, y me propuce hacer una versión privada para mi, una q escape a los antivirus =P, empece un proyecto nuevo y voy copiando partes del codigo de a poco, asta ahora, le faltan muchas funcionalidades, pero ya es un intento de troyano y solo lo detacta un AV  =P,

Bueno, por eso los molesto en esta ocacion =P, como deben imaginarse, el troyano usa la implementacion de API de Socket ( La desarrollada por Emiliano Scavuzzo) , solo por agregar estos modulos a un proyectoo limpio, ya lo detectan 3 AV como un troyano xD, me di ceunta q era por la declaracion de API q usa, por eso, busque una manera de usar las api sin declararlas, en internet, encotre este modulo q funciona, para llamar api sin declararlas antes, y me funciono a la perfeccion, pero el problema es cuando quiero llamar alguna API q se le debe pasar una Type como parametro X_x

aca les dejo el modulo ^^! ( espero q a alguien le sirva )
y q alguna alma caritativa me explique como puedo modificar este code, para poder llamar api y pasarle estructuras como parametros

Código
  1. Option Explicit
  2.  
  3. '***********************************************
  4. '* This module use excelent solution from
  5. '* http://www.vbdotcom.com/FreeCode.htm
  6. '* how to implement assembly calls directly
  7. '* into VB code.
  8. '***********************************************
  9. '
  10. ' ***********************************************************
  11. ' MODIFIED VERSION - BUFFER COMPATIBLE & LOT EASIER HANDLING:
  12. ' BY ROCKZ
  13. ' ***********************************************************
  14. '
  15.  
  16. Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  17. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  18. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  19. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
  20. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cBytes As Long)
  21.  
  22. Private mlngParameters() As Long    'list of parameters
  23. Private mlngAddress As Long         'address of function to call
  24. Private mbytCode() As Byte          'buffer for assembly code
  25. Private mlngCP As Long              'used to keep track of latest byte added to code
  26.  
  27. Private Type xbyte
  28.    arr() As Byte
  29. End Type
  30.  
  31.  
  32. Public Function CallAPIByName(libName As String, funcName As String, ParamArray FuncParams()) As Long
  33.    Dim arr() As Variant
  34.    arr() = FuncParams()
  35.  
  36.    CallAPIByName = CallRemote(libName, funcName, arr())
  37.  
  38.    Dim i As Long
  39.    For i = LBound(FuncParams()) To UBound(FuncParams())
  40.        FuncParams(i) = arr(i)
  41.    Next i
  42. End Function
  43.  
  44.  
  45. Public Function CallRemote(libName As String, funcName As String, FuncParams() As Variant) As Long
  46.    Dim lb As Long, i As Integer
  47.    ReDim mlngParameters(0)
  48.    ReDim mbytCode(0)
  49.    mlngAddress = 0
  50.  
  51.    Dim x() As xbyte
  52.    Dim wasString() As Boolean
  53.    Dim keineparams As Boolean
  54.    ' Prepare params
  55.    If UBound(FuncParams()) = -1 Then
  56.        keineparams = True
  57.        GoTo keineparams
  58.    End If
  59.    On Error GoTo 0
  60.  
  61.    ReDim wasString(UBound(FuncParams()))
  62.    For i = LBound(FuncParams()) To UBound(FuncParams())
  63.        wasString(i) = False
  64.        If varType(FuncParams(i)) = vbString Then
  65.            ReDim Preserve x(i)
  66.            x(i).arr = StrConv(FuncParams(i), vbFromUnicode) & Chr(0)
  67.            FuncParams(i) = VarPtr(x(i).arr(0))
  68.            wasString(i) = True
  69.        End If
  70.    Next i
  71.  
  72. keineparams:
  73.  
  74.    lb = LoadLibrary(ByVal libName)
  75.    If lb = 0 Then
  76.        MsgBox "DLL not found", vbCritical
  77.        Exit Function
  78.    End If
  79.    mlngAddress = GetProcAddress(lb, ByVal funcName)
  80.    If mlngAddress = 0 Then
  81.        MsgBox "Function entry not found", vbCritical
  82.        FreeLibrary lb
  83.        Exit Function
  84.    End If
  85.  
  86.    ReDim mlngParameters(UBound(FuncParams) + 1)
  87.    For i = 1 To UBound(mlngParameters)
  88.        mlngParameters(i) = CLng(FuncParams(i - 1))
  89.    Next i
  90.    CallRemote = CallWindowProc(PrepareCode, 0, 0, 0, 0)
  91.    FreeLibrary lb
  92.  
  93.    If keineparams Then Exit Function
  94.  
  95.    For i = LBound(FuncParams()) To UBound(FuncParams())
  96.        If wasString(i) Then ' kann ja sein das es buffershit war
  97.            FuncParams(i) = StrConv(x(i).arr(), vbUnicode)
  98.        End If
  99.    Next i
  100. End Function
  101.  
  102.  
  103. Private Function PrepareCode() As Long
  104.    Dim lngX As Long, codeStart As Long
  105.    ReDim mbytCode(18 + 32 + 6 * UBound(mlngParameters))
  106.    codeStart = GetAlignedCodeStart(VarPtr(mbytCode(0)))
  107.    mlngCP = codeStart - VarPtr(mbytCode(0))
  108.    For lngX = 0 To mlngCP - 1
  109.        mbytCode(lngX) = &HCC
  110.    Next
  111.    AddByteToCode &H58 'pop eax
  112.    AddByteToCode &H59 'pop ecx
  113.    AddByteToCode &H59 'pop ecx
  114.    AddByteToCode &H59 'pop ecx
  115.    AddByteToCode &H59 'pop ecx
  116.    AddByteToCode &H50 'push eax
  117.    For lngX = UBound(mlngParameters) To 1 Step -1
  118.        AddByteToCode &H68 'push wwxxyyzz
  119.        AddLongToCode mlngParameters(lngX)
  120.    Next
  121.    AddCallToCode mlngAddress
  122.    AddByteToCode &HC3
  123.    AddByteToCode &HCC
  124.    PrepareCode = codeStart
  125. End Function
  126.  
  127.  
  128. Private Sub AddCallToCode(lngAddress As Long)
  129.    AddByteToCode &HE8
  130.    AddLongToCode lngAddress - VarPtr(mbytCode(mlngCP)) - 4
  131. End Sub
  132.  
  133.  
  134. Private Sub AddLongToCode(lng As Long)
  135.    Dim intX As Integer
  136.    Dim byt(3) As Byte
  137.    CopyMemory byt(0), lng, 4
  138.    For intX = 0 To 3
  139.        AddByteToCode byt(intX)
  140.    Next
  141. End Sub
  142.  
  143.  
  144. Private Sub AddByteToCode(byt As Byte)
  145.    mbytCode(mlngCP) = byt
  146.    mlngCP = mlngCP + 1
  147. End Sub
  148.  
  149.  
  150. Private Function GetAlignedCodeStart(lngAddress As Long) As Long
  151.    GetAlignedCodeStart = lngAddress + (15 - (lngAddress - 1) Mod 16)
  152.    If (15 - (lngAddress - 1) Mod 16) = 0 Then GetAlignedCodeStart = GetAlignedCodeStart + 16
  153. End Function
  154.  


Título: Re: Usar API sin declarar [Problema] xD
Publicado por: cobein en 30 Septiembre 2008, 21:35 pm
Esas funciones empujan longs al stack antes de hacer el call, asi que tenes que usar varptr(myUDT) para que funcione