4
4
"context"
5
5
"flag"
6
6
"fmt"
7
+ "math/rand"
7
8
"net"
8
9
"sort"
9
10
"strings"
@@ -243,13 +244,11 @@ var allModules = []Module{
243
244
Timeout : 1 * time .Second ,
244
245
},
245
246
Module {
246
- Module : simulator .NewTunnel (),
247
- Name : "tunnel-dns" ,
248
- Pipeline : PipelineDNS ,
249
- NumOfHosts : 1 ,
250
- // HeaderMsg: "Preparing DNS tunnel hostnames",
251
- HostMsg : "Simulating DNS tunneling via *.%s" ,
252
- Timeout : 10 * time .Second ,
247
+ Module : simulator .NewTunnel (),
248
+ Name : "tunnel-dns" ,
249
+ Pipeline : PipelineDNS ,
250
+ HostMsg : "Simulating DNS tunneling via *.%s" ,
251
+ Timeout : 10 * time .Second ,
253
252
},
254
253
Module {
255
254
Module : simulator .CreateModule (wisdom .NewWisdomHosts ("cryptomining" , wisdom .HostTypeIP ), simulator .NewStratumMiner ()),
@@ -296,22 +295,20 @@ var allModules = []Module{
296
295
Timeout : 3 * time .Second ,
297
296
},
298
297
Module {
299
- Module : simulator .NewSSHTransfer (),
300
- Name : "ssh-transfer" ,
301
- Pipeline : PipelineIP ,
302
- NumOfHosts : 1 ,
303
- HeaderMsg : "Preparing to send randomly generated data to a standard SSH port" ,
304
- Timeout : 5 * time .Minute ,
305
- Fast : true ,
298
+ Module : simulator .NewSSHTransfer (),
299
+ Name : "ssh-transfer" ,
300
+ Pipeline : PipelineIP ,
301
+ HeaderMsg : "Preparing to send randomly generated data to a standard SSH port" ,
302
+ Timeout : 5 * time .Minute ,
303
+ Fast : true ,
306
304
},
307
305
Module {
308
- Module : simulator .NewSSHExfil (),
309
- Name : "ssh-exfil" ,
310
- Pipeline : PipelineIP ,
311
- NumOfHosts : 1 ,
312
- HeaderMsg : "Preparing to send randomly generated data to a non-standard SSH port" ,
313
- Timeout : 5 * time .Minute ,
314
- Fast : true ,
306
+ Module : simulator .NewSSHExfil (),
307
+ Name : "ssh-exfil" ,
308
+ Pipeline : PipelineIP ,
309
+ HeaderMsg : "Preparing to send randomly generated data to a non-standard SSH port" ,
310
+ Timeout : 5 * time .Minute ,
311
+ Fast : true ,
315
312
},
316
313
Module {
317
314
Module : simulator .CreateModule (wisdom .NewWisdomHosts ("irc" , wisdom .HostTypeDNS ), simulator .NewIRCClient ()),
@@ -334,22 +331,20 @@ var allModules = []Module{
334
331
HostMsg : "Simulating IRC traffic to %s" ,
335
332
},
336
333
Module {
337
- Module : simulator .NewTelegramBot (),
338
- Name : "telegram-bot" ,
339
- Pipeline : PipelineDNS ,
340
- NumOfHosts : 1 ,
341
- HeaderMsg : "Preparing to simulate Telegram bot traffic" ,
342
- Timeout : 3 * time .Second ,
343
- HostMsg : "Simulating Telegram Bot API traffic to %s" ,
334
+ Module : simulator .NewTelegramBot (),
335
+ Name : "telegram-bot" ,
336
+ Pipeline : PipelineDNS ,
337
+ HeaderMsg : "Preparing to simulate Telegram bot traffic" ,
338
+ Timeout : 3 * time .Second ,
339
+ HostMsg : "Simulating Telegram Bot API traffic to %s" ,
344
340
},
345
341
Module {
346
- Module : simulator .NewCleartextProtocolSimulator (),
347
- Name : "cleartext" ,
348
- Pipeline : PipelineIP ,
349
- NumOfHosts : 5 ,
350
- HeaderMsg : "Preparing to simulate cleartext protocol traffic" ,
351
- Timeout : 3 * time .Second ,
352
- HostMsg : "Sending random data to %s" ,
342
+ Module : simulator .NewCleartextProtocolSimulator (),
343
+ Name : "cleartext" ,
344
+ Pipeline : PipelineIP ,
345
+ HeaderMsg : "Preparing to simulate cleartext protocol traffic" ,
346
+ Timeout : 3 * time .Second ,
347
+ HostMsg : "Sending random data to %s" ,
353
348
},
354
349
}
355
350
@@ -444,6 +439,15 @@ func run(sims []*Simulation, bind simulator.BindAddr, size int) error {
444
439
continue
445
440
}
446
441
442
+ // Pick random hosts if we have more than we need
443
+ if numOfHosts > 0 && len (hosts ) > numOfHosts {
444
+ newHosts := make ([]string , numOfHosts )
445
+ for n , k := range rand .Perm (len (hosts ))[:numOfHosts ] {
446
+ newHosts [n ] = hosts [k ]
447
+ }
448
+ hosts = newHosts
449
+ }
450
+
447
451
// Wrap module execution in a function, so we can recover from panics
448
452
func () {
449
453
defer func () {
0 commit comments