Advertisement
YourMain12

Xynivilus API (Free executor + Can bypass Byfron)

May 4th, 2023
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.85 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace XynivilusAPI
  6. {
  7.     public class Xynivilus
  8.     {
  9.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  10.         private static extern IntPtr CreateRemoteThread(
  11.             IntPtr hProcess,
  12.             IntPtr lpThreadAttributes,
  13.             uint dwStackSize,
  14.             IntPtr lpStartAddress,
  15.             IntPtr lpParameter,
  16.             uint dwCreationFlags,
  17.             IntPtr lpThreadId
  18.         );
  19.  
  20.         [DllImport("kernel32.dll", SetLastError = true)]
  21.         static extern bool VirtualProtectEx(
  22.             IntPtr hProcess,
  23.             IntPtr lpAddress,
  24.             IntPtr dwSize,
  25.             uint flNewProtect,
  26.             out uint lpflOldProtect
  27.         );
  28.  
  29.         [DllImport("kernel32.dll")]
  30.         private static extern IntPtr OpenProcess(
  31.             uint dwDesiredAccess,
  32.             bool bInheritHandle,
  33.             int dwProcessId
  34.         );
  35.  
  36.         [DllImport("kernel32.dll")]
  37.         private static extern bool ReadProcessMemory(
  38.             IntPtr hProcess,
  39.             IntPtr lpBaseAddress,
  40.             [Out] byte[] lpBuffer,
  41.             int dwSize,
  42.             out IntPtr lpNumberOfBytesRead
  43.         );
  44.  
  45.         [DllImport("kernel32.dll")]
  46.         private static extern bool WriteProcessMemory(
  47.             IntPtr hProcess,
  48.             IntPtr lpBaseAddress,
  49.             byte[] lpBuffer,
  50.             int nSize,
  51.             out IntPtr lpNumberOfBytesWritten
  52.         );
  53.  
  54.         private static byte[] Shellcode = new byte[] {
  55.             // Insert your shellcode here
  56.         };
  57.  
  58.         public static void Inject(int pid)
  59.         {
  60.             try
  61.             {
  62.                 var processHandle = OpenProcess(0x001F0FFF, false, pid);
  63.  
  64.                 IntPtr address = VirtualAllocEx(
  65.                     processHandle,
  66.                     IntPtr.Zero,
  67.                     Shellcode.Length,
  68.                     0x1000,
  69.                     0x40
  70.                 );
  71.  
  72.                 IntPtr bytesWritten = IntPtr.Zero;
  73.                 bool result = WriteProcessMemory(
  74.                     processHandle,
  75.                     address,
  76.                     Shellcode,
  77.                     Shellcode.Length,
  78.                     out bytesWritten
  79.                 );
  80.  
  81.                 IntPtr threadId = IntPtr.Zero;
  82.                 IntPtr hThread = CreateRemoteThread(
  83.                     processHandle,
  84.                     IntPtr.Zero,
  85.                     0,
  86.                     address,
  87.                     IntPtr.Zero,
  88.                     0,
  89.                     threadId
  90.                 );
  91.  
  92.                 CloseHandle(hThread);
  93.                 VirtualFreeEx(processHandle, address, 0, 0x8000);
  94.                 CloseHandle(processHandle);
  95.             }
  96.             catch (Exception ex)
  97.             {
  98.                 Console.WriteLine(ex.Message);
  99.             }
  100.         }
  101.  
  102.         private static IntPtr VirtualAllocEx(
  103.             IntPtr hProcess,
  104.             IntPtr lpAddress,
  105.             int dwSize,
  106.             uint flAllocationType,
  107.             uint flProtect
  108.         )
  109.         {
  110.             IntPtr result = VirtualAllocEx(
  111.                 hProcess,
  112.                 lpAddress,
  113.                 (IntPtr)dwSize,
  114.                 flAllocationType,
  115.                 flProtect
  116.             );
  117.  
  118.             if (result == IntPtr.Zero)
  119.             {
  120.                 throw new Exception("Error allocating memory");
  121.             }
  122.  
  123.             return result;
  124.         }
  125.  
  126.         [DllImport("kernel32.dll")]
  127.         private static extern bool VirtualFreeEx(
  128.             IntPtr hProcess,
  129.             IntPtr lpAddress,
  130.             int dwSize,
  131.             uint dwFreeType
  132.         );
  133.  
  134.         [DllImport("kernel32.dll")]
  135.         private static extern bool CloseHandle(IntPtr hObject);
  136.     }
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement