Skip to content

Commit 4314a3a

Browse files
send syn flood to eth3 (#131)
send syn flood to eth3
1 parent 7c57cf1 commit 4314a3a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

examples/syn-flood/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ The example is located in the `examples/syn-flood` sub-directory. To run the app
1414
/examples/syn-flood$ cargo run -- -f syn-flood.toml
1515
```
1616

17+
To observe the `SYN` flood traffic, in the vagrant VM, run `tcpdump` to capture packets sent to the destination IP address and port,
18+
19+
```
20+
$ sudo tcpdump -nn host 10.100.1.255 and port 80
21+
```
22+
1723
## Explanation
1824

19-
The application schedules a periodic pipeline on port `eth1`'s assigned core `1`. The pipeline will repeat every 10 milliseconds. Instead of receiving packets from the port, the pipeline uses `batch::poll_fn` to generate a batch of new SYN packets each iteration and sends them through the port. Every packet is assigned a different spoofed source IP address.
25+
The application schedules a periodic pipeline on port `eth1`'s assigned core `1`. The pipeline will repeat every 10 milliseconds. Instead of receiving packets from the port, the pipeline uses `batch::poll_fn` to generate a batch of new SYN packets each iteration and sends them to the interface `eth3` with assigned IP `10.100.1.255` on port `80`. Every packet is assigned a different spoofed source IP address.
2026

2127
On the main core `0`, a scheduled task prints out the port metrics once every second.
2228

examples/syn-flood/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use anyhow::Result;
2020
use capsule::batch::{Batch, Pipeline};
2121
use capsule::config::load_config;
2222
use capsule::metrics;
23+
use capsule::net::MacAddr;
2324
use capsule::packets::ip::v4::Ipv4;
2425
use capsule::packets::{Ethernet, Packet, Tcp4};
2526
use capsule::{batch, Mbuf, PortQueue, Runtime};
@@ -32,8 +33,9 @@ use tracing::{debug, error, Level};
3233
use tracing_subscriber::fmt;
3334

3435
fn install(qs: HashMap<String, PortQueue>) -> impl Pipeline {
35-
let mac = qs["eth1"].mac_addr();
36-
let localhost = Ipv4Addr::new(127, 0, 0, 1);
36+
let src_mac = qs["eth1"].mac_addr();
37+
let dst_ip = Ipv4Addr::new(10, 100, 1, 255);
38+
let dst_mac = MacAddr::new(0x02, 0x00, 0x00, 0xff, 0xff, 0xff);
3739

3840
// starts the src ip at 10.0.0.0
3941
let mut next_ip = 10u32 << 24;
@@ -46,14 +48,15 @@ fn install(qs: HashMap<String, PortQueue>) -> impl Pipeline {
4648
})
4749
.map(move |packet| {
4850
let mut ethernet = packet.push::<Ethernet>()?;
49-
ethernet.set_src(mac);
51+
ethernet.set_src(src_mac);
52+
ethernet.set_dst(dst_mac);
5053

5154
// +1 to gen the next ip
5255
next_ip += 1;
5356

5457
let mut v4 = ethernet.push::<Ipv4>()?;
5558
v4.set_src(next_ip.into());
56-
v4.set_dst(localhost);
59+
v4.set_dst(dst_ip);
5760

5861
let mut tcp = v4.push::<Tcp4>()?;
5962
tcp.set_syn();

0 commit comments

Comments
 (0)