-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (77 loc) · 2.5 KB
/
main.go
File metadata and controls
92 lines (77 loc) · 2.5 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"Ansem/internal"
"context"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"sync"
"text/tabwriter"
)
type conf struct {
Directory string `yaml:"exploits_dir"`
Tick int `yaml:"tick"`
TeamFile string `yaml:"team_file"`
GameServer string `yaml:"gameserver"`
Workers int `yaml:"workers"`
SubmissionType string `yaml:"submission_type"`
FlagRegex string `yaml:"flag_regex"`
FlagAccepted string `yaml:"flag_accepted"`
Token string `yaml:"token"`
}
// Function that initialize the config
func (c *conf) getConf() *conf {
yamlFile, err := ioutil.ReadFile("configs/conf.yaml")
if err != nil {
log.Fatalf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return c
}
func main() {
var c conf
c.getConf()
//Fix path if the last char is not "/"
if c.Directory[len(c.Directory)-1] != '/' {
c.Directory = fmt.Sprintf("%s/", c.Directory)
}
//Aligned print
writer := new(tabwriter.Writer)
writer.Init(os.Stdout, 0, 8, 0, '\t', 0)
_, _ = fmt.Fprintf(writer, "Hi, I'm starting with these settings:\n\n"+
"Exploits Dir:\t%s\n"+
"Gameserver:\t%s\n"+
"Teamfile:\t%s\n"+
"SubmissionType:\t%s\n"+
"Flag Regex:\t%s\n"+
"Tick:\t%d\n"+
"Workers:\t%d\n"+
"Token:\t%s\n",
c.Directory, c.GameServer, c.TeamFile, c.SubmissionType, c.FlagRegex, c.Tick, c.Workers, c.Token)
writer.Flush()
toSubmit := make(chan string, 20)
wg := sync.WaitGroup{}
wg.Add(2)
exploitCtx := context.Background()
exploitCtx = context.WithValue(exploitCtx, "exploitDir", c.Directory)
exploitCtx = context.WithValue(exploitCtx, "tick", c.Tick)
exploitCtx = context.WithValue(exploitCtx, "fileTeam", c.TeamFile)
exploitCtx = context.WithValue(exploitCtx, "workers", c.Workers)
exploitCtx = context.WithValue(exploitCtx, "submit", toSubmit)
exploitCtx = context.WithValue(exploitCtx, "flagRegex", c.FlagRegex)
submitterCtx := context.Background()
submitterCtx = context.WithValue(submitterCtx, "gameServer", c.GameServer)
submitterCtx = context.WithValue(submitterCtx, "submit", toSubmit)
submitterCtx = context.WithValue(submitterCtx, "flagRegex", c.FlagRegex)
submitterCtx = context.WithValue(submitterCtx, "subType", c.SubmissionType)
submitterCtx = context.WithValue(submitterCtx, "flagAccepted", c.FlagAccepted)
submitterCtx = context.WithValue(submitterCtx, "token", c.Token)
go internal.StartExploiter(exploitCtx, &wg)
go internal.StartSubmitter(submitterCtx, &wg)
wg.Wait()
}