Skip to content

Commit f7ce966

Browse files
committed
Add cleartext-protocol simulator
2 parents e5c842a + 07a8f3e commit f7ce966

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ The modules packaged with the utility are listed in the table below.
141141
| Module | Description |
142142
| ------------- | -------------------------------------------------------------------------------- |
143143
| `c2` | Generates both DNS and IP traffic to a random list of known C2 destinations |
144+
| `cleartext` | Generates random cleartext traffic to an Internet service operated by AlphaSOC |
144145
| `dga` | Simulates DGA traffic using random labels and top-level domains |
145146
| `imposter` | Generates DNS traffic to a list of imposter domains |
146147
| `irc` | Connects to a random list of public IRC servers |

cmd/run/run.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ var allModules = []Module{
342342
Timeout: 3 * time.Second,
343343
HostMsg: "Simulating Telegram Bot API traffic to %s",
344344
},
345+
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",
353+
},
345354
}
346355

347356
type Simulation struct {

simulator/cleartext-protocol.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package simulator
2+
3+
import (
4+
"context"
5+
"math/rand"
6+
"net"
7+
"time"
8+
)
9+
10+
// generateRandomData genereates n random bytes.
11+
// TODO: this method should be moved to utils along with all the other use cases of generating random data
12+
func generateRandomData(n int) []byte {
13+
src := rand.NewSource(time.Now().Unix())
14+
r := rand.New(src)
15+
buffer := make([]byte, n)
16+
_, _ = r.Read(buffer)
17+
return buffer
18+
}
19+
20+
// CleartextProtocolSimulator simulates cleartext protocol traffic
21+
type CleartextProtocolSimulator struct {
22+
bind BindAddr
23+
data []byte
24+
}
25+
26+
// NewCleartextProtocolSimulator creates new instance of CleartextProtocolSimulator
27+
func NewCleartextProtocolSimulator() *CleartextProtocolSimulator {
28+
return &CleartextProtocolSimulator{}
29+
}
30+
31+
func (cps *CleartextProtocolSimulator) Init(bind BindAddr) error {
32+
cps.bind = bind
33+
34+
// random bytes are generated in Init because it's not necessary
35+
// to generate them everytime Simulate method is run
36+
data := generateRandomData(1000)
37+
38+
cps.data = data
39+
40+
return nil
41+
}
42+
43+
func (CleartextProtocolSimulator) Cleanup() {
44+
45+
}
46+
47+
// Simulate cleartext protocol traffic
48+
func (cps *CleartextProtocolSimulator) Simulate(ctx context.Context, dst string) error {
49+
d := &net.Dialer{LocalAddr: &net.TCPAddr{IP: cps.bind.Addr}}
50+
conn, err := d.DialContext(ctx, "tcp", dst)
51+
52+
if err != nil {
53+
return err
54+
}
55+
defer conn.Close()
56+
57+
if _, err = conn.Write(cps.data); err != nil {
58+
return err
59+
}
60+
61+
if _, err = conn.Read(nil); err != nil {
62+
return err
63+
}
64+
65+
return nil
66+
}
67+
68+
// Hosts returns IP:port pairs used to connect to AlphaSOC sandbox
69+
func (cps *CleartextProtocolSimulator) Hosts(scope string, size int) ([]string, error) {
70+
var hosts []string
71+
72+
ports := []string{"21", "23", "110", "143", "873"}
73+
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]))
85+
}
86+
87+
return hosts, nil
88+
}

0 commit comments

Comments
 (0)