-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathudp_packet.rs
More file actions
26 lines (22 loc) · 886 Bytes
/
udp_packet.rs
File metadata and controls
26 lines (22 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use ip_spoofing::{self, RawSocket, ReusablePacketWriter};
/// This example shows how to generate fake UDP packet
/// that delivers `b"hey"` bytes from "8.8.8.8:1234" to "127.0.0.1:5678".
///
/// I.e. the attacker changes its IPv4 address to 8.8.8.8 (Google Public DNS)
fn main() -> ip_spoofing::Result<()> {
//wrapper around raw sockets, requires root privileges
let socket = RawSocket::new()?;
//wrapper for writing packets in pre-allocated memory
let mut writer = ReusablePacketWriter::new();
//sends fake UDP packet
socket.send_fake_udp_packet(
&mut writer,
[8, 8, 8, 8], //source IPv4 address
1234, //source port
[127, 0, 0, 1], //destination IPv4 address
5678, //destination port
b"hey", //data
64, //TTL on most Linux machines is 64
)?;
Ok(())
}