Skip to content

Commit 64799b3

Browse files
committed
Remove empty lines
1 parent c4c691f commit 64799b3

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

cmd/run.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
var (
1818
fast bool
1919
ifaceName string
20-
simulatorNames = []string{"c2-dns", "dga", "scan", "spambot", "tunnel"}
20+
simulatorNames = []string{"c2-dns", "c2-ip", "dga", "scan", "spambot", "tunnel"}
2121
)
2222

2323
func newRunCommand() *cobra.Command {
@@ -86,6 +86,14 @@ var allsimualtors = []simulatorInfo{
8686
1 * time.Second,
8787
false,
8888
},
89+
{
90+
"c2-ip",
91+
[]string{"Preparing random sample of current C2 IP:port pairs"},
92+
"Connecting to %s",
93+
simulator.NewC2IP(),
94+
1 * time.Second,
95+
true,
96+
},
8997
{
9098
"dga",
9199
[]string{"Generating list of DGA domains"},

simulator/c2_ip.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package simulator
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"io/ioutil"
7+
"math/rand"
8+
"net"
9+
"net/http"
10+
11+
"github.com/pkg/errors"
12+
)
13+
14+
// C2IP simulator.
15+
type C2IP struct{}
16+
17+
// NewC2IP creates c2 dns simulator.
18+
func NewC2IP() *C2IP {
19+
return &C2IP{}
20+
}
21+
22+
// Simulate c2 dns traffic.
23+
func (*C2IP) Simulate(ctx context.Context, extIP net.IP, host string) error {
24+
d := &net.Dialer{
25+
LocalAddr: &net.TCPAddr{IP: extIP},
26+
}
27+
28+
conn, err := d.DialContext(ctx, "tcp", host)
29+
if err != nil {
30+
return err
31+
}
32+
conn.Close()
33+
return nil
34+
}
35+
36+
// Hosts returns hosts marked c2 dns threat.
37+
func (t *C2IP) Hosts() ([]string, error) {
38+
const nLookup = 10
39+
resp, err := http.Get("https://api.open.wisdom.alphasoc.net/v1/c2-ip")
40+
if err != nil {
41+
return nil, err
42+
}
43+
defer resp.Body.Close()
44+
45+
b, err := ioutil.ReadAll(resp.Body)
46+
if err != nil {
47+
return nil, errors.Wrapf(err, "alnfo read body error")
48+
}
49+
50+
response := &struct {
51+
Hosts []string `json:"hosts"`
52+
}{}
53+
54+
if err := json.Unmarshal(b, response); err != nil {
55+
return nil, errors.Wrapf(err, "alnfo parse body error")
56+
}
57+
58+
var (
59+
hosts []string
60+
idx = rand.Perm(len(response.Hosts))
61+
)
62+
for n, i := 0, 0; n < len(response.Hosts) && i < nLookup; n, i = n+1, i+1 {
63+
hosts = append(hosts, response.Hosts[idx[n]])
64+
}
65+
return hosts, nil
66+
}

simulator/scan.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (*PortScan) Simulate(ctx context.Context, extIP net.IP, host string) error
4848
conn, err := d.DialContext(ctx, "tcp", host)
4949
if err != nil {
5050
return err
51-
5251
}
5352
conn.Close()
5453
return nil

0 commit comments

Comments
 (0)