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

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 4 5 Ir Abajo Respuesta Imprimir
Autor Tema: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]  (Leído 22,367 veces)
Slek Hacker

Desconectado Desconectado

Mensajes: 35


El Conocimiento nos hace Libres...


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #10 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!


En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #11 en: 1 Noviembre 2011, 12:23 pm »

Puse el low donde iba el hi y viceversa jaja gracias Slek :) Lo corrijo :-*


En línea

Swellow

Desconectado Desconectado

Mensajes: 77


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #12 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?
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #13 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...
En línea

scapula

Desconectado Desconectado

Mensajes: 10


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #14 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.
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #15 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...
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #16 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!¡.
« Última modificación: 4 Noviembre 2011, 03:27 am por BlackZeroX (Astaroth) » En línea

The Dark Shadow is my passion.
Dessa


Desconectado Desconectado

Mensajes: 624



Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #17 en: 3 Noviembre 2011, 01:08 am »

Como me cuesta manejar la p**a memoria !!!

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

Saludos

En línea

Adrian Desanti
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #18 en: 3 Noviembre 2011, 02:57 am »

Buena contribución BlackZeroX :)
Gracias ;)
En línea

scapula

Desconectado Desconectado

Mensajes: 10


Ver Perfil
Re: mMemory - WriteProcessMemory/vbaCopyBytes/RtlMoveMemory replacement [NOAPI!!!]
« Respuesta #19 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.  
En línea

Páginas: 1 [2] 3 4 5 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Split replacement
Programación Visual Basic
cobein 4 1,851 Último mensaje 18 Septiembre 2008, 01:15 am
por BlackZeroX
CallAPIByName usando solamente rtlMoveMemory
Programación Visual Basic
cobein 9 6,568 Último mensaje 9 Noviembre 2011, 08:52 am
por scapula
[VB-SNIPPET] htons() replacement
Programación Visual Basic
Karcrack 1 3,308 Último mensaje 26 Junio 2010, 23:15 pm
por LeandroA
[VB6+ASM] Alternativa CopyMemory/RtlMoveMemory/CopyBytes
Programación Visual Basic
Karcrack 6 5,286 Último mensaje 30 Julio 2010, 10:05 am
por Psyke1
Problema con MoveMem - Reemplazando RtlMoveMemory.
Programación Visual Basic
Shackles 4 2,634 Último mensaje 23 Junio 2012, 17:19 pm
por Shackles
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines