From 54a54b0d0d3365dcad90e09d48ea9257487f35e9 Mon Sep 17 00:00:00 2001 From: Matt Wimbler Date: Sun, 22 Jun 2025 18:23:33 +0200 Subject: basic icmp comms --- drone/Cargo.toml | 8 ++++++++ drone/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 drone/Cargo.toml create mode 100644 drone/src/main.rs (limited to 'drone') diff --git a/drone/Cargo.toml b/drone/Cargo.toml new file mode 100644 index 0000000..6d6aaf5 --- /dev/null +++ b/drone/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "himmel-drone" +version = "0.1.0" +edition = "2024" + +[dependencies] +pnet = { version = "0.31.0", features = ["std"] } + diff --git a/drone/src/main.rs b/drone/src/main.rs new file mode 100644 index 0000000..600a5f7 --- /dev/null +++ b/drone/src/main.rs @@ -0,0 +1,32 @@ +use pnet::packet::icmp::{IcmpPacket, IcmpTypes, checksum}; +use pnet::packet::icmp::echo_request::MutableEchoRequestPacket; +use pnet::packet::{Packet}; +use pnet::transport::{transport_channel, TransportChannelType, TransportProtocol}; +use pnet::packet::ip::IpNextHeaderProtocols; +use std::net::IpAddr; + +fn main() { + let attacker_ip: IpAddr = "192.168.1.86".parse().unwrap(); + + let protocol = TransportChannelType::Layer4(TransportProtocol::Ipv4(IpNextHeaderProtocols::Icmp)); + let (mut tx, _) = transport_channel(1024, protocol).expect("Failed to open channel"); + + let mut buffer = [0u8; 64]; + let mut packet = MutableEchoRequestPacket::new(&mut buffer).unwrap(); + + packet.set_icmp_type(IcmpTypes::EchoRequest); + packet.set_identifier(1234); + packet.set_sequence_number(1); + + let payload = b"hello"; + packet.set_payload(payload); + + let icmp_packet = IcmpPacket::new(packet.packet()).unwrap(); + let chksum = checksum(&icmp_packet); + packet.set_checksum(chksum); + + match tx.send_to(packet, attacker_ip) { + Ok(_) => println!("Packet sent"), + Err(e) => eprintln!("Send failed: {:?}", e), + } +} -- cgit v1.2.3