Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Karcrack en 31 Octubre 2011, 13:19 pm



Título: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 31 Octubre 2011, 13:19 pm
Hace mucho tiempo que no toqueteaba a mi querido VB6 :P Así que aquí estoy con otra primicia chicoooos!!! :laugh: :laugh:

Este modulito que os presento permite trabajar con la memoria sin el uso de ningún API!!!!

Eso sí! Tenéis que desactivar la comprobación de límites de matrices :P Os pongo una foto:
(http://i44.tinypic.com/nbouww.png)
Además solo funciona compilado, como muchos otros hacks el IDE no permite tocar demasiado :-\ :xD

Y como todos estáis deseando aquí viene el sencillo pero eficaz código :)
Código
  1. '---------------------------------------------------------------------------------------
  2. ' Module    : mMemory
  3. ' Author    : Karcrack
  4. ' Date      : 20/09/2011
  5. ' Purpose   : Work with memory withouth using any API
  6. ' History   : 20/09/2011 First cut .....................................................
  7. '---------------------------------------------------------------------------------------
  8.  
  9. Option Explicit
  10.  
  11. Private bvHack(0)               As Byte
  12. Private lHackDelta              As Long
  13. Private bInitialized            As Boolean
  14.  
  15. Public Function Initialize() As Boolean
  16.    On Error GoTo Error_Handle
  17.  
  18.    bvHack(-1) = bvHack(-1) 'Error check
  19.    lHackDelta = VarPtr(bvHack(0))
  20.  
  21.    Initialize = True
  22.    bInitialized = Initialize
  23.    Exit Function
  24. Error_Handle:
  25.    If Err.Number = 9 Then Debug.Print "Remember to tick 'Remove array boundary check' and compile before using"
  26.    End
  27. End Function
  28.  
  29. Public Function GetByte(ByVal lPtr As Long) As Byte
  30.    If bInitialized Then GetByte = bvHack(lPtr - lHackDelta)
  31. End Function
  32.  
  33. Public Function GetWord(ByVal lPtr As Long) As Integer
  34.    If bInitialized Then GetWord = MakeWord(GetByte(lPtr + &H0), GetByte(lPtr + &H1))
  35. End Function
  36.  
  37. Public Function GetDWord(ByVal lPtr As Long) As Long
  38.    If bInitialized Then GetDWord = MakeDWord(GetWord(lPtr + &H0), GetWord(lPtr + &H2))
  39. End Function
  40.  
  41. Public Sub PutByte(ByVal lPtr As Long, ByVal bByte As Byte)
  42.    If bInitialized Then bvHack(lPtr - lHackDelta) = bByte
  43. End Sub
  44.  
  45. Public Sub PutWord(ByVal lPtr As Long, ByVal iWord As Integer)
  46.    If bInitialized Then Call PutByte(lPtr + &H0, iWord And &HFF): Call PutByte(lPtr + &H1, (iWord And &HFF00&) \ &H100)
  47. End Sub
  48.  
  49. Public Sub PutDWord(ByVal lPtr As Long, ByVal lDWord As Long)
  50.    If bInitialized Then Call PutWord(lPtr + &H0, IIf(lDWord And &H8000&, lDWord Or &HFFFF0000, lDWord And &HFFFF&)): Call PutWord(lPtr + &H2, (lDWord And &HFFFF0000) \ &H10000)
  51. End Sub
  52.  
  53. Private Function MakeWord(ByVal loByte As Byte, ByVal hiByte As Byte) As Integer '[http://www.xbeat.net/vbspeed/c_MakeWord.htm#MakeWord02]
  54.    If hiByte And &H80 Then
  55.        MakeWord = ((hiByte * &H100&) Or loByte) Or &HFFFF0000
  56.    Else
  57.        MakeWord = (hiByte * &H100) Or loByte
  58.    End If
  59. End Function
  60.  
  61. Private Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long '[http://www.xbeat.net/vbspeed/c_MakeDWord.htm#MakeDWord05]
  62.    MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
  63. End Function

Si saco un poco de tiempo libre hago una clase chuli piruli con este mismo sistema :)

Happy codin' ::)


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 31 Octubre 2011, 13:23 pm
Ejemplo de uso:
Código
  1. Private Sub Form_Load()
  2.    Dim x       As Long
  3.    Dim y       As Long
  4.  
  5.    Call mMemory.Initialize
  6.  
  7.    x = &H1337
  8.    y = 0
  9.    MsgBox x & vbCrLf & y
  10.    y = mMemory.GetDWord(VarPtr(x))
  11.    MsgBox x & vbCrLf & y
  12. End Sub
  13.  
;)


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: x64core en 31 Octubre 2011, 17:27 pm
 ;-) ;-) ;-) ;-)
Grande Karcrack!  ;D
lo estudiare, me imagino que es mas rapido que las apis,rtlmovememory?


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 31 Octubre 2011, 17:35 pm
Sipi ;D Básicamente son movs en ASM... el compilador se encarga del asunto ;)


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: x64core en 31 Octubre 2011, 18:54 pm
Karcrack estudie tu code ;D
y pues tengo unas dudas lo segui con el dbg en el ide me las arregle como pude :P
y veo que los haces como en el "aire de la memoria" podria colgarse la app si en el array en las posiciones (-xxxxxx) se encuentre ya ocupada ? :P


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: CAR3S? en 31 Octubre 2011, 19:28 pm
Bueno ya, me saco la duda...

¿que podria hacer con esto? :B


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 31 Octubre 2011, 19:33 pm
@Raul100: Todas las posiciones ya existen, el array solo ocupa 1 byte... el resto de indices se salen del array, es por eso que hay que indicarle al compilador que no queremos que compruebe si el indice es mayor que el tamaño del array... De esta forma podemos movernos a cualquier posición de memoria utilizando como referencia la posicion del unico byte que hemos reservado en memoria. :)

@nukje:De todo. :xD Básicamente es para eliminar el uso de funciones para el acceso de memoria.. así se pueden crear RunPEs y Invokes indetectables aún más fácilmente :D


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Slek Hacker en 31 Octubre 2011, 19:39 pm
Dioooss Karcrack!!! Eres el amoo!! +100000
Muchas Graciaas!!
 ;-)

Edit: el PutDWord me da error >,<


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 1 Noviembre 2011, 03:50 am
¿Podrías ponerme un ejemplo en el que te dé error? Las funciones put las hice un poco rápido y no testee, pero debe ir correctamente :P Comprueba que no estas intentando escribir en una zona no Writeable de la memoria.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 1 Noviembre 2011, 06:57 am
Se me habia ocurrido algo casi igual hace rato cuando vi esa opcion... pero nunca para algo tan asi como lo que te rifaste... esto esta bueno!¡.

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Slek Hacker en 1 Noviembre 2011, 09:05 am
Código
  1. Public Sub PutDWord(ByVal lPtr As Long, ByVal lDWord As Long)
  2.    If bInitialized Then Call PutWord(lPtr + &H0, IIf(lDWord And &H8000&, lDWord Or &HFFFF0000, lDWord And &HFFFF&)): Call PutWord(lPtr + &H2, (lDWord And &HFFFF0000) \ &H10000)
  3. End Sub

Arreglado :D

Saludos!


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 1 Noviembre 2011, 12:23 pm
Puse el low donde iba el hi y viceversa jaja gracias Slek :) Lo corrijo :-*


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 1 Noviembre 2011, 17:13 pm
Thanks so much for this, I've tried to use it on your PatchAPI function but I can't get it working :( Could you give us a sample please?


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 1 Noviembre 2011, 18:59 pm
You won't be able to write there because the memory section isn't writeable... you must use VirtualProtect() first...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: scapula en 2 Noviembre 2011, 20:42 pm
hello i have a problem with this function

Código:
Private Sub WriteString(ByVal lPtr As Long, ByVal sStr As String)
    Dim bvStr()         As Byte
    bvStr = StrConv(sStr, vbFromUnicode)
    Call WriteProcessMemory(-1, ByVal lPtr, bvStr(0), UBound(bvStr) + 1, ByVal 0&)
End Sub


i have use PutByte but i have an error Overflow you can help me please.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 3 Noviembre 2011, 00:14 am
@scapula:
Código:
Remember to tick 'Remove array boundary check' and compile before using
Also you must remember that with this method you cannot write in memory regions wich aren't writeable...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 3 Noviembre 2011, 00:52 am
.
Agregue mas funciones gracias a las funciones que propuso el compañero Karcrack... como reservar memoria.

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5. Dim sStr1   As String
  6. Dim sStr2   As String
  7. Dim lpStr   As Long
  8.  
  9.  
  10.    sStr1 = "BlackZeroX"
  11.    sStr2 = "InfrAngeluX-Soft"
  12.    MsgBox sStr1 & vbCrLf & sStr2
  13.    lpStr = mMemory.cloneString(VarPtr(sStr2), sStr1)       '  <--------------------- clone sStr1.
  14.    MsgBox sStr1 & vbCrLf & sStr2
  15.    Call mMemory.swapVarPtr(VarPtr(lpStr), VarPtr(sStr2))   '   //  restauramos.
  16.    MsgBox sStr1 & vbCrLf & sStr2
  17.    Call mMemory.releaseMemStr(lpStr)                       '   //  liberamos  la copia de sStr1 (release sStr1 clone)
  18.  
  19.    '   //  Other example.
  20. Dim sStr3   As String
  21. Dim lpSafe  As Long
  22.    lpSafe = mMemory.allocMem((LenB(sStr1) + 4 + 2))
  23.    lpStr = (mMemory.getMemData(lpSafe) + 4)
  24.    Call mMemory.writeMemory((lpStr - 4), (StrPtr(sStr1) - 4), (LenB(sStr1) + 4 + 2))
  25.    Call mMemory.swapVarPtr(VarPtr(sStr3), VarPtr(lpStr))
  26.    MsgBox "ejemplo 2: " & sStr3
  27.    Call mMemory.swapVarPtr(VarPtr(sStr3), VarPtr(lpStr))
  28.    mMemory.releaseMem (lpSafe) ' // liberamos la memoria reservada con allocMem()
  29.    MsgBox "ejemplo 2 Finish: " & sStr3
  30. End Sub
  31.  
  32.  

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5. Dim sStr1   As String
  6. Dim sStr2   As String
  7. Dim lpStr   As Long
  8. Dim i       As Long
  9. Dim a       As Byte
  10.  
  11.    Call mMemory.Initialize
  12.  
  13.    sStr1 = "BlackZeroX"
  14.    sStr2 = "InfrAngeluX-Soft"
  15.    MsgBox sStr2 & vbCrLf & sStr1
  16.    MsgBox mMemory.writeMemory(StrPtr(sStr2) + 8, StrPtr(sStr1) + 10, 10)
  17.    MsgBox sStr2 & vbCrLf & sStr1
  18. End Sub
  19.  
  20.  

Código
  1.  
  2. '---------------------------------------------------------------------------------------
  3. ' Module    : mMemory
  4. ' Author    : Karcrack
  5. ' Date      : 20/09/2011
  6. ' Purpose   : Work with memory withouth using any API
  7. ' History   : 20/09/2011 First cut .....................................................
  8. '---------------------------------------------------------------------------------------
  9.  
  10. Option Explicit
  11.  
  12. Public Declare Function VarPtrArr Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long
  13.  
  14. Private bvHack(0)               As Byte
  15. Private lHackDelta              As Long
  16. Private bInitialized            As Boolean
  17.  
  18. Public Function Initialize() As Boolean
  19.    On Error GoTo Error_Handle
  20.  
  21.    bvHack(-1) = bvHack(-1) 'Error check
  22.    lHackDelta = VarPtr(bvHack(0))
  23.  
  24.    Initialize = True
  25.    bInitialized = Initialize
  26.    Exit Function
  27. Error_Handle:
  28.    If Err.Number = 9 Then Debug.Print "Remember to tick 'Remove array boundary check' and compile before using"
  29. '    End
  30. End Function
  31.  
  32. Public Function GetByte(ByVal lptr As Long) As Byte
  33.    If bInitialized Then GetByte = bvHack(lptr - lHackDelta)
  34. End Function
  35.  
  36. Public Function GetWord(ByVal lptr As Long) As Integer
  37.    If bInitialized Then GetWord = MakeWord(GetByte(lptr + &H0), GetByte(lptr + &H1))
  38. End Function
  39.  
  40. Public Function GetDWord(ByVal lptr As Long) As Long
  41.    If bInitialized Then GetDWord = MakeDWord(GetWord(lptr + &H0), GetWord(lptr + &H2))
  42. End Function
  43.  
  44. Public Sub PutByte(ByVal lptr As Long, ByVal bByte As Byte)
  45.    If bInitialized Then bvHack(lptr - lHackDelta) = bByte
  46. End Sub
  47.  
  48. Public Sub PutWord(ByVal lptr As Long, ByVal iWord As Integer)
  49.    If bInitialized Then Call PutByte(lptr + &H0, iWord And &HFF): Call PutByte(lptr + &H1, (iWord And &HFF00&) \ &H100)
  50. End Sub
  51.  
  52. Public Sub PutDWord(ByVal lptr As Long, ByVal lDWord As Long)
  53.    If bInitialized Then Call PutWord(lptr + &H0, IIf(lDWord And &H8000&, lDWord Or &HFFFF0000, lDWord And &HFFFF&)): Call PutWord(lptr + &H2, (lDWord And &HFFFF0000) \ &H10000)
  54. End Sub
  55.  
  56. Public Function MakeWord(ByVal loByte As Byte, ByVal hiByte As Byte) As Integer '[http://www.xbeat.net/vbspeed/c_MakeWord.htm#MakeWord02]
  57.    If hiByte And &H80 Then
  58.        MakeWord = ((hiByte * &H100&) Or loByte) Or &HFFFF0000
  59.    Else
  60.        MakeWord = (hiByte * &H100) Or loByte
  61.    End If
  62. End Function
  63.  
  64. Public Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long '[http://www.xbeat.net/vbspeed/c_MakeDWord.htm#MakeDWord05]
  65.    MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
  66. End Function
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. '/////////////////////
  74. Public Function allocMem(ByVal lSize As Long) As Long
  75. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  76. '   //  Retorna la Dirrecion de un SafeArray.
  77. Dim pBuff()     As Byte
  78.    If (lSize <= &H0) Then Exit Function
  79.    ReDim pBuff(0 To (lSize - 1))
  80.    allocMem = GetDWord(VarPtrArr(pBuff))
  81.    PutDWord VarPtrArr(pBuff), 0
  82. End Function
  83.  
  84. Public Function reallocMem(ByVal lptr As Long, ByVal lSize As Long) As Long
  85. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  86. '   //  Retorna la Dirrecion de un SafeArray que se retorno en allocMem()/reallocMem().
  87. Dim pBuff()     As Byte
  88.    PutDWord VarPtrArr(pBuff), lptr
  89.    If not (lSize = &H0) Then
  90.        ReDim Preserve pBuff(0 To (lSize - 1))
  91.    Else
  92.        Erase pBuff
  93.    End If
  94.    reallocMem = GetDWord(VarPtrArr(pBuff))
  95.    PutDWord VarPtrArr(pBuff), 0
  96. End Function
  97.  
  98. Public Function getMemData(ByVal lptr As Long) As Long
  99. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  100. '   //  lPtr debe ser el valor (Address) que retorno en allocMem()/reallocMem().
  101. '   //  Esta funcion retorna la Dirrecion de memoria EDITABLE de lPtr (Dirrecion de un SafeArray).
  102. '   //  Referencias.
  103. '   //  http://msdn.microsoft.com/en-us/library/aa908603.aspx
  104.    If (lptr = &H0) Then Exit Function
  105.    getMemData = GetDWord(lptr + &HC)    '   //  obtenemos pvData
  106. End Function
  107.  
  108. Public Sub releaseMem(ByVal lptr As Long)
  109. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  110. '   //  lPtr debe ser la Dirrecion que retorno en allocMem()/reallocMem().
  111. Dim pBuff()     As Byte
  112.    PutDWord VarPtrArr(pBuff), lptr
  113. End Sub
  114.  
  115. Public Sub releaseMemStr(ByVal lptr As Long)
  116. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  117. '   //  lPtr debe ser la Dirrecion que retorno en cloneString().
  118. Dim sStr        As String
  119.    PutDWord VarPtr(sStr), lptr
  120. End Sub
  121.  
  122. Public Sub swapVarPtr(ByVal lpVar1 As Long, ByVal lpVar2 As Long)
  123. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  124. Dim lAux    As Long
  125.    lAux = GetDWord(lpVar1)
  126.    Call PutDWord(lpVar1, GetDWord(lpVar2))
  127.    Call PutDWord(lpVar2, lAux)
  128. End Sub
  129.  
  130. Public Function cloneString(ByVal lpStrDst As Long, ByVal sStrSrc As String) As Long
  131. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  132. '   //  lPtr -> Puntero a una variable destino (Preferiblemente String).
  133. '   //  sStr -> Cadena Clonada ( gracias a Byval ).
  134. Dim lpStrSrc        As Long
  135.    If Not (lpStrDst = &H0) And (mMemory.Initialize = True) Then
  136.        Call mMemory.swapVarPtr(lpStrDst, VarPtr(sStrSrc))
  137.        Call mMemory.swapVarPtr(VarPtr(cloneString), VarPtr(sStrSrc))
  138.    End If
  139. End Function
  140.  
  141. Public Function writeMemory(ByVal lpDataDst As Long, ByVal lpDataSrc As Long, ByVal lLn As Long) As Long
  142. '   //  By BlackZeroX (Thanks to Karcrack to GetDWord() function and PutDWord() function ).
  143. Dim i       As Long
  144.    If (lpDataSrc = &H0) Or (lpDataDst = &H0) Or (lLn = &H0) Then Exit Function
  145.    i = (lLn Mod 4)
  146.    If ((i And &H2) = &H2) Then
  147.        Call PutWord(lpDataDst, GetWord(lpDataSrc))
  148.        lpDataDst = (lpDataDst + 2)
  149.        lpDataSrc = (lpDataSrc + 2)
  150.        writeMemory = (writeMemory + 2)
  151.        lLn = (lLn - 2)
  152.    End If
  153.    If ((i And &H1) = &H1) Then
  154.        Call PutByte(lpDataDst, GetByte(lpDataSrc))
  155.        lpDataDst = (lpDataDst + 1)
  156.        lpDataSrc = (lpDataSrc + 1)
  157.        writeMemory = (writeMemory + 1)
  158.        lLn = (lLn - 1)
  159.    End If
  160.    For i = 0 To (lLn - 1) Step 4
  161.        Call PutDWord(lpDataDst + i, GetDWord(lpDataSrc + i))
  162.    Next
  163.    writeMemory = (writeMemory + lLn)
  164. End Function
  165.  
  166.  

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Dessa en 3 Noviembre 2011, 01:08 am
Como me cuesta manejar la p**a memoria !!!

Gracias por el aporte, Karcrack Or BlackZeroX = "Genios"

Saludos



Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 3 Noviembre 2011, 02:57 am
Buena contribución BlackZeroX :)
Gracias ;)


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: scapula en 3 Noviembre 2011, 03:29 am
Thanks Karcrack but i have checked "Remove array boundary check".

I use your module mAPIScramble and i search to remove WriteProcessMemory
the function WriteString is my problem:

Código
  1. '---------------------------------------------------------------------------------------
  2. ' Module    : mAPIScramble
  3. ' Author    : Karcrack
  4. ' Now       : 20/10/2010 22:52
  5. ' Purpose   : Obfuscate API Declaration in VB6
  6. ' History   : 20/10/2010 First cut .........................................................
  7. '---------------------------------------------------------------------------------------
  8.  
  9.  
  10.  
  11. 'KERNEL32
  12. Private Declare Function WriteProcessMemory Lib "KERNEL32" (ByVal hProcess As Long, ByRef lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
  13.  
  14. 'API SCRAMBLED
  15. Private Declare Function MessageBox Lib "VTFS43" Alias "NfttbhfCpyB" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
  16.  
  17.  
  18.  
  19. Public Function UnScrambleAPI(ByVal sLibName As String, ByVal sFuncName As String) As Boolean
  20.    Dim pBaseAddress    As Long
  21.    Dim pVB5            As Long
  22.    Dim pProjectInfo    As Long
  23.    Dim pExtTable       As Long
  24.    Dim pLibraryName    As Long
  25.    Dim pFunctionName   As Long
  26.    Dim iExtCount       As Long
  27.    Dim iIndex          As Long
  28.  
  29.    'Do NOT run it on the IDE
  30.    If App.LogMode = 0 Then Debug.Assert (0 = 1): Exit Function
  31.  
  32.    pBaseAddress = App.hInstance
  33.    pVB5 = ReadDWORD(pBaseAddress + ReadDWORD(pBaseAddress + ReadDWORD(pBaseAddress + &H3C) + &H28) + 1)
  34.    pProjectInfo = ReadDWORD(pVB5 + &H30)
  35.    pExtTable = ReadDWORD(pProjectInfo + &H234)
  36.    iExtCount = ReadDWORD(pProjectInfo + &H238)
  37.  
  38.    For iIndex = 0 To iExtCount - 1
  39.        If ReadDWORD(pExtTable) <> 6 Then
  40.            pLibraryName = ReadDWORD(ReadDWORD(pExtTable + &H4) + &H0)
  41.            pFunctionName = ReadDWORD(ReadDWORD(pExtTable + &H4) + &H4)
  42.  
  43.            If (pLibraryName <> 0) And (pFunctionName <> 0) Then
  44.                If ReadString(pLibraryName) = sLibName Then
  45.                    If ReadString(pFunctionName) = sFuncName Then
  46.                        Call WriteString(pLibraryName, Decrypt(sLibName))
  47.                        Call WriteString(pFunctionName, Decrypt(sFuncName))
  48.                        UnScrambleAPI = True
  49.                    End If
  50.                End If
  51.            End If
  52.        End If
  53.        pExtTable = pExtTable + 8
  54.    Next iIndex
  55. End Function
  56.  
  57. Private Function ReadDWORD(ByVal lptr As Long) As Long
  58.    ReadDWORD = mMemory.GetDWord(VarPtr(ByVal lptr&))
  59. End Function
  60.  
  61. Private Sub WriteDWORD(ByVal lptr As Long, ByVal lLng As Long)
  62.    Call mMemory.PutDWord(VarPtr(ByVal lptr&), VarPtr(lLng))
  63. End Sub
  64.  
  65. Private Function ReadString(ByVal lptr As Long) As String
  66.    Dim i               As Long
  67.    Dim b               As Byte
  68.  
  69.    Do
  70.        b = mMemory.GetByte(VarPtr(ByVal lptr& + i))
  71.        If b = 0 Then Exit Do
  72.        ReadString = ReadString & Chr$(b)
  73.        i = i + 1
  74.    Loop
  75.  
  76. End Function
  77.  
  78. Private Sub WriteString(ByVal lptr As Long, ByVal sStr As String)
  79.    Dim bvStr()         As Byte
  80.    bvStr = StrConv(sStr, vbFromUnicode)
  81.    Call WriteProcessMemory(-1, ByVal lptr, bvStr(0), UBound(bvStr) + 1, ByVal 0&) ' FUCKING API =(
  82. End Sub
  83.  
  84. Private Function Decrypt(ByVal sData As String) As String
  85.    Dim i               As Long
  86.  
  87.    For i = 1 To Len(sData)
  88.        Decrypt = Decrypt & Chr$(Asc(Mid$(sData, i, 1)) - 1)
  89.    Next i
  90. End Function
  91.  
  92. Public Function Encrypt(ByVal sData As String) As String
  93.    Dim i               As Long
  94.  
  95.    For i = 1 To Len(sData)
  96.        Encrypt = Encrypt & Chr$(Asc(Mid$(sData, i, 1)) + 1)
  97.    Next i
  98. End Function
  99.  
  100.  
  101. Sub Main()
  102. Const LIBNAME       As String = "VTFS43"
  103. Const FUNCNAME      As String = "NfttbhfCpyB"
  104.  
  105. Call mMemory.Initialize
  106.  
  107. If UnScrambleAPI(LIBNAME, FUNCNAME) = True Then
  108. Call MessageBox(0, ":)", ":)", 0)
  109. End If
  110. End Sub
  111.  
  112.  


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 3 Noviembre 2011, 08:38 am
.
Solo falta DESBLOQUEAR la memoria en writeMemory()...

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Function MessageBox Lib "VTFS43" Alias "NfttbhfCpyB" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
  5. Private Declare Function IsBadWritePtr Lib "kernel32" (ByVal lp As Long, ByVal ucb As Long) As Long
  6.  
  7. Public Function unScrambleAPI(ByVal sLibName As String, ByVal sFuncName As String) As Boolean
  8. Dim pBaseAddress    As Long
  9. Dim pVB5            As Long
  10. Dim pProjectInfo    As Long
  11. Dim pExtTable       As Long
  12. Dim pLibraryName    As Long
  13. Dim pFunctionName   As Long
  14. Dim iExtCount       As Long
  15. Dim iIndex          As Long
  16.  
  17. Dim bLibNameOri()   As Byte
  18. Dim bFuncNameOri()  As Byte
  19.  
  20.    'Do NOT run it on the IDE
  21.    If App.LogMode = 0 Then Debug.Assert (0 = 1): Exit Function
  22.  
  23.    pBaseAddress = App.hInstance
  24.    pVB5 = getDWord(pBaseAddress + getDWord(pBaseAddress + getDWord(pBaseAddress + &H3C) + &H28) + 1)
  25.    pProjectInfo = getDWord(pVB5 + &H30)
  26.    pExtTable = getDWord(pProjectInfo + &H234)
  27.    iExtCount = getDWord(pProjectInfo + &H238)
  28.  
  29.    bLibNameOri = StrConv(decrypt(sLibName), vbFromUnicode)
  30.    bFuncNameOri = StrConv(decrypt(sFuncName), vbFromUnicode)
  31.  
  32.    For iIndex = 0 To iExtCount - 1
  33.        If getDWord(pExtTable) <> 6 Then
  34.            pLibraryName = getDWord(getDWord(pExtTable + &H4) + &H0)
  35.            pFunctionName = getDWord(getDWord(pExtTable + &H4) + &H4)
  36.  
  37.            If (pLibraryName <> 0) And (pFunctionName <> 0) Then
  38.                If readString(pLibraryName) = sLibName Then
  39.                    If readString(pFunctionName) = sFuncName Then
  40.                        If Not (IsBadWritePtr(pLibraryName, (UBound(bLibNameOri) + 1)) = &H0) Then
  41.                            MsgBox "require Unlock BlockMemory"
  42.                        Else
  43.                            Call writeByte(pLibraryName, bLibNameOri)
  44.                        End If
  45.                        If Not (IsBadWritePtr(pFunctionName, (UBound(bFuncNameOri) + 1)) = &H0) Then
  46.                            MsgBox "require Unlock BlockMemory"
  47.                        Else
  48.                            Call writeByte(pFunctionName, bFuncNameOri)
  49.                        End If
  50.                        unScrambleAPI = True
  51.                    End If
  52.                End If
  53.            End If
  54.        End If
  55.        pExtTable = pExtTable + 8
  56.    Next iIndex
  57. End Function
  58.  
  59. Private Function readString(ByVal lptr As Long) As String
  60. Dim i               As Long
  61. Dim b               As Byte
  62.    Do
  63.        b = getByte(lptr + i)
  64.        If b = 0 Then Exit Do
  65.        readString = readString & Chr$(b)
  66.        i = i + 1
  67.    Loop
  68. End Function
  69.  
  70. Public Function itsArrayIni(ByVal lptr As Long) As Boolean
  71.    itsArrayIni = Not (getDWord(lptr) = &H0)
  72. End Function
  73.  
  74. Private Function writeByte(ByVal lptr As Long, ByRef bData() As Byte) As Long
  75.    If (Not itsArrayIni(VarPtrArr(bData))) Then Exit Function
  76.    writeByte = writeMemory(lptr, VarPtr(bData(0)), (UBound(bData) + 1))
  77. End Function
  78.  
  79. Private Function decrypt(ByRef sStr As String) As String
  80. Dim i               As Long
  81.    decrypt = Space(Len(sStr))
  82.    For i = 1 To Len(sStr)
  83.        Mid$(decrypt, i, 1) = Chr$(Asc(Mid$(sStr, i, 1)) - 1)
  84.    Next i
  85. End Function
  86.  
  87. Public Sub encrypt(ByRef sData As String)
  88. Dim i               As Long
  89.    For i = 1 To Len(sData)
  90.        Mid$(sData, i, 1) = Chr$(Asc(Mid$(sData, i, 1)) + 1)
  91.    Next i
  92. End Sub
  93.  
  94. Sub Main()
  95. Const LIBNAME       As String = "VTFS43"
  96. Const FUNCNAME      As String = "NfttbhfCpyB"
  97.  
  98.    If mMemory.initialize Then
  99.        If unScrambleAPI(LIBNAME, FUNCNAME) = True Then
  100.            Call MessageBox(0, ":)", ":)", 0)
  101.        End If
  102.    Else
  103.        MsgBox "Error"
  104.    End If
  105. End Sub
  106.  
  107.  

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: x64core en 3 Noviembre 2011, 09:02 am
 :laugh: :laugh:
hablemos en chino pues  >:D :xD
...

sino fuera por el nombre de la API no supiera que fuera :xD
Código:
Private Declare Function MessageBox Lib "VTFS43" Alias "NfttbhfCpyB" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

Grandes ustedes dos  ;D


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 3 Noviembre 2011, 09:29 am

hablemos en chino pues  >:D :xD


Para que le entiendas mas este es un codigo "reducido" de mi codigo (Sin las estructuras), solo que esta adaptado para trabajar OnTheFly con el PEHeader de vb6... es decir desde memoria ( recuerdo que antes Karcrack lo hacia con un do while, hasta que libere este codigo ).

ExtractApisEXEVB6 (Se puede Ampliar) (http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=5:extractinfoapi-vb6-pe&catid=2:catprocmanager&Itemid=3)

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: scapula en 3 Noviembre 2011, 14:10 pm
BlackZeroX thanks for you help  :D


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: TVFürer en 3 Noviembre 2011, 18:22 pm
Wowwww buenisimo muchachos felicitaciones a los 2 son  unos genios.
 Ahora una pregunta me dirian como lo utilizo por ejemplo con el Krunpe?

 Muchas gracias.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Slek Hacker en 4 Noviembre 2011, 12:03 pm
Solo falta DESBLOQUEAR la memoria en writeMemory()...

Con Desbloquear la memoria te refieres a usar allocMem?

Saludos!


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 4 Noviembre 2011, 20:46 pm
You won't be able to write there because the memory section isn't writeable... you must use VirtualProtect() first...

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: runman en 4 Noviembre 2011, 21:14 pm
can you show us how it works plz :¬¬
i can not get it to work with VirtualProtect()


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 6 Noviembre 2011, 02:34 am
Thanks a lot man for your example but how to "Unlock BlockMemory" ?

I'm getting that message...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Slek Hacker en 6 Noviembre 2011, 17:08 pm
No sé qué estoy haciendo mal. Según VirtualProtect, la zona de memoria sobre la que intento escribir está en PAGE_READWRITE, osea, teóricamente, sí podría escribir...

Código
  1. Private Sub WriteString(ByVal lPtr As Long, ByVal sStr As String)
  2.    Dim bvStr()         As Byte
  3.  
  4.    bvStr = StrConv(sStr, vbFromUnicode)
  5.  
  6.    Call WriteMemory(lPtr, VarPtr(bvStr(0)), UBound(bvStr) + 1)
  7. End Sub

Código
  1. Call VirtualProtect(ByVal pLibraryName, Len(sLibName), PAGE_READWRITE, lngOldProtect)
  2. Msgbox lngOldProtect
  3. Call WriteString(pLibraryName, Decrypt(sLibName))

También he probado poniéndole PAGE_EXECUTE_READWRITE, pero tampoco

Es que esto de la memoria no es mi fuerte xD

Saludos!


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 7 Noviembre 2011, 10:08 am
La bronca es COMO tienes declaradas las APIS... segun como las declares debes pasar los parametros de cierta manera...

para evitar estar poniendo mas y mas codigos...

unCrambleAPI (http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=41:uncrambleapi&catid=2:catprocmanager&Itemid=3)

Sangriento Infierno Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 7 Noviembre 2011, 19:06 pm
PAGE_WRITECOPY is missing..


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 7 Noviembre 2011, 19:55 pm
.
lammer

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 7 Noviembre 2011, 20:35 pm
.
lammer

Dulces Lunas!¡.

Sorry it was my mistake I was using old mMemory...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BUNNN en 10 Noviembre 2011, 23:30 pm
@Karcrack Run-pe doesn't works if i compile with "Remove Array Bound Check" enabled.
Checked with inject to: this exe and default browser.

I can't manage to make run-pe to work with this, only call api by name.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Karcrack en 11 Noviembre 2011, 00:11 am
I'm out of time atm... asap I'll run some tests... sorry
Looks you guys have the same problem: you're trying to write on non-writeable pages of memory... Anyway I'll do some test when I have free time...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 11 Noviembre 2011, 18:52 pm
@Karcrack Run-pe doesn't works if i compile with "Remove Array Bound Check" enabled.
Checked with inject to: this exe and default browser.

I can't manage to make run-pe to work with this, only call api by name.

heh? Why not invoking RunPE's APIs with the CallAPI then?


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 18 Noviembre 2011, 03:24 am
Someone on HH made cNtPel with 0 API's and 0 Types by modding this function do you think you would be able Karcrack?


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Unbr0ken en 18 Noviembre 2011, 08:04 am
Aguanta Karcrack, ¿sería como el uso de código inseguro en C#?, o ¿Punteros en C/C++?...


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 18 Noviembre 2011, 20:32 pm
¿Punteros en C/C++?...

De alguna manera si... es muy parecido, pero muy limitado.

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Unbr0ken en 18 Noviembre 2011, 23:25 pm
De alguna manera si... es muy parecido, pero muy limitado.

Dulces Lunas!¡.

Wow, flipante entonces, no sabía que podía llegar hasta allí desde VB6 :D.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: cobein en 20 Noviembre 2011, 23:27 pm
Muy bueno Karcrack, simple y efectivo como siempre, un lujo.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: Swellow en 1 Enero 2012, 18:02 pm
What is the alternative function for WriteProcessMemory guys?

Would be really great if anyone could tell me how to :/


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: demoniox12 en 14 Julio 2012, 19:41 pm
La bronca es COMO tienes declaradas las APIS... segun como las declares debes pasar los parametros de cierta manera...

para evitar estar poniendo mas y mas codigos...

unCrambleAPI (http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=41:uncrambleapi&catid=2:catprocmanager&Itemid=3)

Sangriento Infierno Lunas!¡.

Disculpen el revivir este post viejo.. pero podrias volver a subir el archivo?? Saludos!


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 16 Julio 2012, 20:06 pm
El código esta en diversos sitios...

http://foro.elhacker.net/programacion_visual_basic/mapiscramble_cifra_la_declaracion_de_tus_apis-t308388.0.html
Esta basado en:
http://foro.elhacker.net/programacion_visual_basic/source_extractapisexevb6_se_puede_ampliar-t307765.0.html

Por ahora no tengo el que publique en mi blog (voy a restaurar mi BDD).

Dulces Lunas!¡.


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: jmetin2 en 9 Octubre 2012, 19:48 pm
Disculpen por revivirtema, pero quiero saber como puedo llamar la api "CallWindowProc" con estas funciones?


Título: Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
Publicado por: BlackZeroX en 10 Octubre 2012, 04:57 am
Disculpen por revivirtema, pero quiero saber como puedo llamar la api "CallWindowProc" con estas funciones?

http://foro.elhacker.net/programacion_visual_basic/callapibyname_usando_solamente_rtlmovememory-t258018.0.html

De este(os) código(s) de cobein hay muchas modificaciones, usando google las encuentras.
mMemory y mi mMemoryEx solo es para acceso a zonas de memoria.

Opinion:
Deberían cerrar el tema ya que peguntan cosas fuera de lugar, es decir, cuestiones que no son dudas.

Dulces Lunas!¡.