Skip to content

Commit a35ab97

Browse files
committed
Pick random hosts if returned more than requested
1 parent f7ce966 commit a35ab97

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

cmd/run/run.go

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
"math/rand"
78
"net"
89
"sort"
910
"strings"
@@ -243,13 +244,11 @@ var allModules = []Module{
243244
Timeout: 1 * time.Second,
244245
},
245246
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,
253252
},
254253
Module{
255254
Module: simulator.CreateModule(wisdom.NewWisdomHosts("cryptomining", wisdom.HostTypeIP), simulator.NewStratumMiner()),
@@ -296,22 +295,20 @@ var allModules = []Module{
296295
Timeout: 3 * time.Second,
297296
},
298297
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,
306304
},
307305
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,
315312
},
316313
Module{
317314
Module: simulator.CreateModule(wisdom.NewWisdomHosts("irc", wisdom.HostTypeDNS), simulator.NewIRCClient()),
@@ -334,22 +331,20 @@ var allModules = []Module{
334331
HostMsg: "Simulating IRC traffic to %s",
335332
},
336333
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",
344340
},
345341
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",
353348
},
354349
}
355350

@@ -444,6 +439,15 @@ func run(sims []*Simulation, bind simulator.BindAddr, size int) error {
444439
continue
445440
}
446441

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+
447451
// Wrap module execution in a function, so we can recover from panics
448452
func() {
449453
defer func() {

simulator/cleartext-protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (cps *CleartextProtocolSimulator) Hosts(scope string, size int) ([]string,
8080
// take the first IP address returned by LookupIP
8181
targetIP := ips[0].String()
8282

83-
for i := 0; i < len(ports) && i < size; i++ {
84-
hosts = append(hosts, net.JoinHostPort(targetIP, ports[i]))
83+
for _, port := range ports {
84+
hosts = append(hosts, net.JoinHostPort(targetIP, port))
8585
}
8686

8787
return hosts, nil

simulator/oast.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,5 @@ func (oast *OAST) Simulate(ctx context.Context, host string) error {
7979

8080
// Hosts returns a list of default domains used by Interactsh.
8181
func (OAST) Hosts(scope string, size int) ([]string, error) {
82-
var hosts []string
83-
for _, i := range rand.Perm(len(InteractshDefaultDomains)) {
84-
hosts = append(hosts, InteractshDefaultDomains[i])
85-
if len(hosts) == size {
86-
break
87-
}
88-
}
89-
return hosts, nil
82+
return InteractshDefaultDomains, nil
9083
}

0 commit comments

Comments
 (0)