fix: added a default route for MAC addresses

there were issues with MAC addresses not having a valid route when it
couldn't find the right route
This commit is contained in:
Andrew Rioux 2023-05-12 17:33:22 -04:00
parent 5ab43a10fe
commit a03b50ead4
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
3 changed files with 50 additions and 14 deletions

View File

@ -11,13 +11,9 @@ tmux -2 attach -t bindshell
workspace = false workspace = false
dependencies = ["build"] dependencies = ["build"]
script = ''' script = '''
set -eux
tmux new-session -d -s revshell 'docker-compose up examples_revshell_server' tmux new-session -d -s revshell 'docker-compose up examples_revshell_server'
sleep 1 sleep 1
IP=$(docker-compose exec examples_revshell_server ip a show eth0 | awk '/inet/{print $2}' | awk -F'/' '{print $1}') IP=$(docker-compose exec examples_revshell_server ip a show eth0 | awk '/inet/{print $2}' | awk -F'/' '{print $1}')
echo $IP tmux split-window -h "target/debug/ex-revshell-beacon $IP"
sleep 1
COMMAND="target/debug/ex-revshell-beacon $IP"
tmux split-window -h "$COMMAND"
tmux -2 attach -t revshell tmux -2 attach -t revshell
''' '''

View File

@ -19,7 +19,7 @@ use std::{
net::Ipv4Addr, net::Ipv4Addr,
}; };
use libc::{c_int, c_uint, AF_INET}; use libc::{c_int, c_uint, AF_INET, AF_LLC};
use crate::{ use crate::{
error, error,
@ -175,17 +175,35 @@ pub fn get_macs_and_src_for_ip(
let link_ind = route.hop_iter().next()?.ifindex(); let link_ind = route.hop_iter().next()?.ifindex();
#[cfg(debug_assertions)]
{
for link in links.iter() {
println!("Link {}: {:?} ({})", link.name(), link.addr(), link.ifindex());
println!("\tAddrs:");
for addr in addrs.iter().filter(|addr| addr.ifindex() == link.ifindex()) {
if let Some(a) = addr.local() {
println!("\t\t{:?}", a)
}
}
println!("\tNeighbors:");
for neigh in neighs.iter().filter(|neigh| neigh.ifindex() == link.ifindex()) {
println!("\t\t{:?}, {:?}", neigh.dst(), neigh.lladdr());
}
}
}
let link = netlink::get_link_by_index(links, link_ind)?; let link = netlink::get_link_by_index(links, link_ind)?;
let neighs_ = neighs.iter().collect::<Vec<_>>(); let neighs_ = neighs.iter().collect::<Vec<_>>();
dbg!(neighs_.len()); let neigh = neighs
.iter()
for neigh in neighs_.iter() { .find(|n| n.ifindex() == link.ifindex())
println!("Neigh: {:?} -> {:?} ({})", neigh.lladdr(), neigh.dst(), neigh.ifindex()); .map(|n| n.lladdr().hw_address().try_into().ok())
} .flatten()
.unwrap_or([0xFFu8; 6]);
let neigh = neighs.iter().find(|n| n.ifindex() == link.ifindex())?;
let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?; let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?;
@ -193,7 +211,7 @@ pub fn get_macs_and_src_for_ip(
link.name(), link.name(),
(&srcip.local()?).try_into().ok()?, (&srcip.local()?).try_into().ok()?,
link.addr().hw_address().try_into().ok()?, link.addr().hw_address().try_into().ok()?,
neigh.lladdr().hw_address().try_into().ok()?, neigh,
)) ))
} }
@ -332,6 +350,24 @@ impl Debug for Addr {
) )
.finish() .finish()
} }
AF_LLC => {
let octets = self.hw_address();
f.debug_struct("Addr")
.field(
"addr",
&format!(
"{:02X?}:{:02X?}:{:02X?}:{:02X?}:{:02X?}:{:02X?}",
octets[0],
octets[1],
octets[2],
octets[3],
octets[4],
octets[5],
)
)
.finish()
}
_ => f _ => f
.debug_struct("Addr") .debug_struct("Addr")
.field("addr", &self.hw_address()) .field("addr", &self.hw_address())

View File

@ -200,6 +200,10 @@ impl<T: State> Interface<T> {
Ok(()) Ok(())
} }
pub fn name(&self) -> &str {
std::str::from_utf8(self.dev_name.as_bytes()).unwrap()
}
} }
impl<T: Disabled> Interface<T> { impl<T: Disabled> Interface<T> {