feat: added static linking against libnl

libnl will be used to help understand kernel routing tables
This commit is contained in:
Andrew Rioux 2023-04-30 23:04:53 -04:00
parent 9ebf4b931b
commit 2fc1916273
9 changed files with 68 additions and 17 deletions

View File

@ -15,7 +15,7 @@
FROM rust:1-alpine FROM rust:1-alpine
RUN apk add bash docker git cmake make automake musl-dev \ RUN apk add bash docker git cmake make automake musl-dev autoconf libtool \
flex bison linux-headers openssl-dev apache2-utils docker-compose && \ flex bison linux-headers openssl-dev apache2-utils docker-compose && \
mkdir /etc/docker && \ mkdir /etc/docker && \
echo '{ "storage-driver": "vfs" }' > /etc/docker/daemon.json echo '{ "storage-driver": "vfs" }' > /etc/docker/daemon.json

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "pcap-sys/libpcap"] [submodule "pcap-sys/libpcap"]
path = pcap-sys/libpcap path = pcap-sys/libpcap
url = https://github.com/the-tcpdump-group/libpcap url = https://github.com/the-tcpdump-group/libpcap
[submodule "nl-sys/libnl"]
path = nl-sys/libnl
url = https://github.com/thom311/libnl

10
Cargo.lock generated
View File

@ -25,6 +25,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "autotools"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef8da1805e028a172334c3b680f93e71126f2327622faef2ec3d893c0a4ad77"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "beacon" name = "beacon"
version = "0.1.0" version = "0.1.0"
@ -363,6 +372,7 @@ dependencies = [
name = "nl-sys" name = "nl-sys"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"autotools",
"libc", "libc",
] ]

View File

@ -1,5 +1,5 @@
[workspace] [workspace]
members = ["pcap-sys", "examples/bind-shell/*", "examples/reverse-shell/*", "nl-sys"] members = ["pcap-sys", "nl-sys", "examples/*/*"]
[profile.release] [profile.release]
strip = true strip = true

View File

@ -6,4 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
libc = "0.2.142" libc = "0.2.142"
[build-dependencies]
autotools = "0.2"

24
nl-sys/build.rs Normal file
View File

@ -0,0 +1,24 @@
// Copyright (C) 2023 Andrew Rioux
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
fn main() {
let dst = autotools::Config::new("libnl")
.reconf("-vi")
.build();
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=nl-3");
println!("cargo:rustc-link-lib=static=nl-route-3");
}

1
nl-sys/libnl Submodule

@ -0,0 +1 @@
Subproject commit cbafad9ddf24caef5230fef715d34f0539603be0

View File

@ -1,14 +0,0 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

24
nl-sys/src/main.rs Normal file
View File

@ -0,0 +1,24 @@
// Copyright (C) 2023 Andrew Rioux
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
enum nl_sock {}
extern {
fn nl_socket_alloc() -> nl_sock;
}
fn main() {
unsafe { nl_socket_alloc(); }
}