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:
parent
5ab43a10fe
commit
a03b50ead4
@ -11,13 +11,9 @@ tmux -2 attach -t bindshell
|
||||
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 split-window -h "target/debug/ex-revshell-beacon $IP"
|
||||
tmux -2 attach -t revshell
|
||||
'''
|
||||
@ -19,7 +19,7 @@ use std::{
|
||||
net::Ipv4Addr,
|
||||
};
|
||||
|
||||
use libc::{c_int, c_uint, AF_INET};
|
||||
use libc::{c_int, c_uint, AF_INET, AF_LLC};
|
||||
|
||||
use crate::{
|
||||
error,
|
||||
@ -175,17 +175,35 @@ pub fn get_macs_and_src_for_ip(
|
||||
|
||||
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 neighs_ = neighs.iter().collect::<Vec<_>>();
|
||||
|
||||
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 neigh = neighs
|
||||
.iter()
|
||||
.find(|n| n.ifindex() == link.ifindex())
|
||||
.map(|n| n.lladdr().hw_address().try_into().ok())
|
||||
.flatten()
|
||||
.unwrap_or([0xFFu8; 6]);
|
||||
|
||||
let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?;
|
||||
|
||||
@ -193,7 +211,7 @@ pub fn get_macs_and_src_for_ip(
|
||||
link.name(),
|
||||
(&srcip.local()?).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()
|
||||
}
|
||||
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
|
||||
.debug_struct("Addr")
|
||||
.field("addr", &self.hw_address())
|
||||
|
||||
@ -200,6 +200,10 @@ impl<T: State> Interface<T> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
std::str::from_utf8(self.dev_name.as_bytes()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Disabled> Interface<T> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user