Skip to content

Commit 07a8f3e

Browse files
committed
move sandbox domain to Hosts method
1 parent cc18dd3 commit 07a8f3e

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

simulator/cleartext-protocol.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,23 @@ func generateRandomData(n int) []byte {
1919

2020
// CleartextProtocolSimulator simulates cleartext protocol traffic
2121
type CleartextProtocolSimulator struct {
22-
bind BindAddr
23-
TargetHostName string
24-
TargetIP string
25-
Data []byte
22+
bind BindAddr
23+
data []byte
2624
}
2725

2826
// NewCleartextProtocolSimulator creates new instance of CleartextProtocolSimulator
2927
func NewCleartextProtocolSimulator() *CleartextProtocolSimulator {
30-
const TargetHostName = "cleartext.sandbox-services.alphasoc.xyz"
31-
return &CleartextProtocolSimulator{TargetHostName: TargetHostName}
28+
return &CleartextProtocolSimulator{}
3229
}
3330

3431
func (cps *CleartextProtocolSimulator) Init(bind BindAddr) error {
3532
cps.bind = bind
3633

37-
ips, err := net.LookupIP(cps.TargetHostName)
38-
39-
if err != nil {
40-
return err
41-
}
42-
43-
// take the first IP address returned by LookupIP
44-
cps.TargetIP = ips[0].String()
45-
4634
// random bytes are generated in Init because it's not necessary
4735
// to generate them everytime Simulate method is run
4836
data := generateRandomData(1000)
4937

50-
cps.Data = data
38+
cps.data = data
5139

5240
return nil
5341
}
@@ -66,7 +54,7 @@ func (cps *CleartextProtocolSimulator) Simulate(ctx context.Context, dst string)
6654
}
6755
defer conn.Close()
6856

69-
if _, err = conn.Write(cps.Data); err != nil {
57+
if _, err = conn.Write(cps.data); err != nil {
7058
return err
7159
}
7260

@@ -83,8 +71,17 @@ func (cps *CleartextProtocolSimulator) Hosts(scope string, size int) ([]string,
8371

8472
ports := []string{"21", "23", "110", "143", "873"}
8573

86-
for _, port := range ports {
87-
hosts = append(hosts, net.JoinHostPort(cps.TargetIP, port))
74+
ips, err := net.LookupIP("cleartext.sandbox-services.alphasoc.xyz")
75+
76+
if err != nil {
77+
return nil, err
78+
}
79+
80+
// take the first IP address returned by LookupIP
81+
targetIP := ips[0].String()
82+
83+
for i := 0; i < len(ports) && i < size; i++ {
84+
hosts = append(hosts, net.JoinHostPort(targetIP, ports[i]))
8885
}
8986

9087
return hosts, nil

0 commit comments

Comments
 (0)