Finished adding a basic flake

It can now build the Linux C2 beacon
This commit is contained in:
Andrew Rioux 2024-01-23 23:26:58 -05:00
parent b2278cc8e8
commit 4475d23d1d
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
10 changed files with 94 additions and 41 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ examples/bind-shell/key-generator/privkey
core core
**/core **/core
.direnv .direnv
result

8
Cargo.lock generated
View File

@ -475,6 +475,12 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.28" version = "0.3.28"
@ -783,6 +789,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"autotools", "autotools",
"cc", "cc",
"fs_extra",
"libc", "libc",
] ]
@ -901,6 +908,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"cmake", "cmake",
"errno 0.2.8", "errno 0.2.8",
"fs_extra",
"futures", "futures",
"libc", "libc",
"packets", "packets",

View File

@ -44,8 +44,13 @@
pkg-config pkg-config
]; ];
toolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile windowsBuildTools = buildTools ++ (with pkgs; [
./rust-toolchain.toml; pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
]);
toolchain =
pkgs.pkgsMusl.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
@ -54,36 +59,49 @@
commonArgs = { commonArgs = {
inherit src; inherit src;
#strictDeps = true; strictDeps = true;
#CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
SPARSE_BUILD_LIBPCAP = "${libpcap-src}"; SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
#SPARSE_BUILD_LIBNL = "${libnl}"; SPARSE_BUILD_LIBNL = "${libnl}";
nativeBuildInputs = buildTools;
buildInputs = buildTools;
doCheck = false;
}; };
commonWindowsArgs = commonArgs // { commonWindowsArgs = commonArgs // {
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
nativeBuildInputs = windowsBuildTools;
buildInputs = windowsBuildTools;
}; };
artifacts = craneLib.buildDepsOnly commonArgs; artifacts = craneLib.buildDepsOnly commonArgs;
windowsArtifacts = craneLib.buildDepsOnly commonWindowsArgs; windowsArtifacts = craneLib.buildDepsOnly commonWindowsArgs;
sparse-05-linux-server = craneLib.buildPackage (commonArgs // {
inherit artifacts;
pname = "sparse-05-server";
cargoExtraArgs = "-p sparse-05-server --locked";
});
sparse-05-windows-server = craneLib.buildPackage (commonWindowsArgs // {
inherit windowsArtifacts;
pname = "sparse-05-server";
cargoExtraArgs = "-p sparse-05-server --locked";
});
sparse-c2-linux-beacon = craneLib.buildPackage (commonArgs // { sparse-c2-linux-beacon = craneLib.buildPackage (commonArgs // {
inherit artifacts; inherit artifacts;
pname = "sparse-c2-beacon"; pname = "sparse-c2-beacon";
cargoExtraArgs = "-p sparse-c2-beacon --locked"; cargoExtraArgs = "-p sparse-c2-beacon --locked";
doCheck = false;
nativeBuildInputs = buildTools;
buildInputs = buildTools;
});
crate = craneLib.buildPackage (commonArgs // {
inherit artifacts;
buildInputs = buildTools;
}); });
in with pkgs; { in with pkgs; {
devShells.default = craneLib.devShell rec { devShells.default = craneLib.devShell rec {
@ -92,10 +110,11 @@
buildInputs = buildTools; buildInputs = buildTools;
SPARSE_BUILD_LIBPCAP = "${libpcap-src}"; SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
#SPARSE_BUILD_LIBNL = "${libnl}"; SPARSE_BUILD_LIBNL = "${libnl}";
}; };
packages = rec { packages = rec {
inherit sparse-05-linux-server sparse-05-windows-server;
inherit sparse-c2-linux-beacon; inherit sparse-c2-linux-beacon;
default = sparse-c2-linux-beacon; default = sparse-c2-linux-beacon;

View File

@ -11,3 +11,4 @@ libc = "0.2.142"
[build-dependencies] [build-dependencies]
autotools = "0.2" autotools = "0.2"
cc = "1.0" cc = "1.0"
fs_extra = "1.3.0"

View File

@ -13,10 +13,18 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use fs_extra::dir::{copy, CopyOptions};
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
cc::Build::new().file("src/bridge.c").compile("bridge"); cc::Build::new().file("src/bridge.c").compile("bridge");
let dst = autotools::Config::new("libnl").reconf("-vi").build(); let libnl_src = format!("{}/libnl_src", std::env::var("OUT_DIR").unwrap());
let mut options = CopyOptions::new();
options.copy_inside = true;
copy(std::env!("SPARSE_BUILD_LIBNL"), &libnl_src, &options);
let dst = autotools::Config::new(libnl_src).reconf("-vi").build();
println!("cargo:rustc-link-search=native={}/lib", dst.display()); println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=nl-3"); println!("cargo:rustc-link-lib=static=nl-3");

View File

@ -28,3 +28,4 @@ packets = { path = "../packets" }
[build-dependencies] [build-dependencies]
cmake = "0.1" cmake = "0.1"
fs_extra = "1.3.0"

View File

@ -13,24 +13,37 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
fn main() { use fs_extra::dir::{copy, CopyOptions};
let dst = cmake::Config::new(std::env!("SPARSE_BUILD_LIBPCAP"))
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_WITH_LIBNL", "OFF")
.define("DISABLE_BLUETOOTH", "ON")
.define("DISABLE_DAG", "ON")
.define("DISABLE_DBUS", "ON")
.define("DISABLE_DPDK", "ON")
.define("DISABLE_LINUX_USBMON", "ON")
.define("DISABLE_NETMAP", "ON")
.define("DISABLE_RDMA", "ON")
.define("DISABLE_SEPTEL", "ON")
.define("DISABLE_SNF", "ON")
.define("DISABLE_TC", "ON")
.define("PCAP_TYPE", "linux")
.build();
// panic!("hahahahah test {}", dst.display()); fn main() {
println!("cargo:rustc-link-search=native={}/lib", dst.display()); if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
println!("cargo:rustc-link-lib=pcap"); println!("cargo:rustc-lib-lib=pcap");
} else {
let libpcap_src = format!("{}/pcap_src", std::env::var("OUT_DIR").unwrap());
let mut options = CopyOptions::new();
options.copy_inside = true;
copy(std::env!("SPARSE_BUILD_LIBPCAP"), &libpcap_src, &options);
let dst = cmake::Config::new(&libpcap_src)
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_WITH_LIBNL", "OFF")
.define("DISABLE_BLUETOOTH", "ON")
.define("DISABLE_DAG", "ON")
.define("DISABLE_DBUS", "ON")
.define("DISABLE_DPDK", "ON")
.define("DISABLE_LINUX_USBMON", "ON")
.define("DISABLE_NETMAP", "ON")
.define("DISABLE_RDMA", "ON")
.define("DISABLE_SEPTEL", "ON")
.define("DISABLE_SNF", "ON")
.define("DISABLE_TC", "ON")
.define("PCAP_TYPE", "linux")
.build();
// panic!("hahahahah test {}", dst.display());
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-search=native={}/lib64", dst.display());
println!("cargo:rustc-link-lib=static=pcap");
}
} }

View File

@ -10,10 +10,12 @@ ecies-ed25519 = { version = "0.5.1", features = ["serde"] }
ed25519-dalek = "1.0.1" ed25519-dalek = "1.0.1"
libc = "0.2.147" libc = "0.2.147"
rand = "0.7" rand = "0.7"
raw_tty = "0.1.0"
rmp-serde = "1.1.2" rmp-serde = "1.1.2"
serde = { version = "1.0.188", features = ["derive"] } serde = { version = "1.0.188", features = ["derive"] }
sparse-05-common = { version = "0.1.0", path = "../sparse-05-common" } sparse-05-common = { version = "0.1.0", path = "../sparse-05-common" }
structopt = { version = "0.3.26", features = ["paw"] } structopt = { version = "0.3.26", features = ["paw"] }
tempfile = "3.8.0" tempfile = "3.8.0"
tokio = { version = "1.32.0", features = ["io-std", "net", "fs", "macros", "rt"] } tokio = { version = "1.32.0", features = ["io-std", "net", "fs", "macros", "rt"] }
[target.'cfg(unix)'.dependencies]
raw_tty = "0.1.0"

View File

@ -16,13 +16,13 @@ catconf = "0.1.2"
sparse-05-common = { version = "0.1.0", path = "../sparse-05-common" } sparse-05-common = { version = "0.1.0", path = "../sparse-05-common" }
ecies-ed25519 = { version = "0.5.1", features = ["serde"] } ecies-ed25519 = { version = "0.5.1", features = ["serde"] }
packets = { path = "../../packets" } packets = { path = "../../packets" }
pcap-sys = { path = "../../pcap-sys", optional = true }
[target.'cfg(unix)'.dependencies]
pcap-sys = { path = "../../pcap-sys" }
[build-dependencies] [build-dependencies]
cc = "1.0" cc = "1.0"
[features] [features]
default = ["pcap"]
docker-breakout = [] docker-breakout = []
exit = [] exit = []
pcap = ["dep:pcap-sys"]

View File

@ -9,7 +9,7 @@ use packets::{self, EthernetPkt};
use sparse_05_common::messages::TransportType; use sparse_05_common::messages::TransportType;
pub enum Interface { pub enum Interface {
#[cfg(target_os = "linux")] #[cfg(feature = "pcap")]
RawUdp(pcap_sys::Interface<pcap_sys::DevActivated>, u16), RawUdp(pcap_sys::Interface<pcap_sys::DevActivated>, u16),
Udp(UdpSocket, u16), Udp(UdpSocket, u16),
} }