forked from frstgrbr/pneuma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (51 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"github.com/preludeorg/pneuma/sockets"
"github.com/preludeorg/pneuma/util"
"flag"
"log"
"math/rand"
"os"
"runtime"
"strings"
"time"
)
var (
key = "JWHQZM9Z4HQOYICDHW4OCJAXPPNHBA"
)
func pickName(chars int) string {
rand.Seed(time.Now().UnixNano())
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, chars)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func buildBeacon(name string, group string) sockets.Beacon {
pwd, _ := os.Getwd()
executable, _ := os.Executable()
return sockets.Beacon{
Name: name,
Range: group,
Pwd: pwd,
Location: executable,
Platform: runtime.GOOS,
Executors: util.DetermineExecutors(runtime.GOOS, runtime.GOARCH),
Links: make([]sockets.Instruction, 0),
}
}
func main() {
name := flag.String("name", pickName(12), "Give this agent a name")
contact := flag.String("contact", "tcp", "Which contact to use")
address := flag.String("address", "0.0.0.0:2323", "The ip:port of the socket listening post")
group := flag.String("range", "red", "Which range to associate to")
sleep := flag.Int("sleep", 60, "Number of seconds to sleep between beacons")
flag.Parse()
if !strings.Contains(*address, ":") {
log.Println("Your address is incorrect")
os.Exit(1)
}
log.Printf("[%s] agent at PID %d using key %s", *contact, os.Getpid(), key)
sockets.CommunicationChannels[*contact].Communicate(*address, *sleep, buildBeacon(*name, *group))
}