@@ -19,35 +19,23 @@ func generateRandomData(n int) []byte {
19
19
20
20
// CleartextProtocolSimulator simulates cleartext protocol traffic
21
21
type CleartextProtocolSimulator struct {
22
- bind BindAddr
23
- TargetHostName string
24
- TargetIP string
25
- Data []byte
22
+ bind BindAddr
23
+ data []byte
26
24
}
27
25
28
26
// NewCleartextProtocolSimulator creates new instance of CleartextProtocolSimulator
29
27
func NewCleartextProtocolSimulator () * CleartextProtocolSimulator {
30
- const TargetHostName = "cleartext.sandbox-services.alphasoc.xyz"
31
- return & CleartextProtocolSimulator {TargetHostName : TargetHostName }
28
+ return & CleartextProtocolSimulator {}
32
29
}
33
30
34
31
func (cps * CleartextProtocolSimulator ) Init (bind BindAddr ) error {
35
32
cps .bind = bind
36
33
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
-
46
34
// random bytes are generated in Init because it's not necessary
47
35
// to generate them everytime Simulate method is run
48
36
data := generateRandomData (1000 )
49
37
50
- cps .Data = data
38
+ cps .data = data
51
39
52
40
return nil
53
41
}
@@ -66,7 +54,7 @@ func (cps *CleartextProtocolSimulator) Simulate(ctx context.Context, dst string)
66
54
}
67
55
defer conn .Close ()
68
56
69
- if _ , err = conn .Write (cps .Data ); err != nil {
57
+ if _ , err = conn .Write (cps .data ); err != nil {
70
58
return err
71
59
}
72
60
@@ -83,8 +71,17 @@ func (cps *CleartextProtocolSimulator) Hosts(scope string, size int) ([]string,
83
71
84
72
ports := []string {"21" , "23" , "110" , "143" , "873" }
85
73
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 ]))
88
85
}
89
86
90
87
return hosts , nil
0 commit comments