-
Notifications
You must be signed in to change notification settings - Fork 59
/
main.go
218 lines (184 loc) · 5.96 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
var verbosePtr, huntSockPtr, huntHttpPtr, huntDockerPtr, toJsonPtr, autopwnPtr, cicdPtr, reconPtr, metaDataPtr, findDockerdPtr, scrapeGcpMeta, alwaysSucceedPtr, k8secrets, pwnKeyctl *bool
var validSocks []string
var exitCode int
var keyMin, keyMax *int
var pathPtr, aggressivePtr, hijackPtr, wordlistPtr, endpointList, pushToS3ptr, s3BucketPtr, awsRegionPtr, cgroupPtr, configPtr, revDNSPtr *string
type IpAddress struct {
Address string
}
type Interface struct {
Name string
Addresses []IpAddress
}
type Config struct {
Payload string
Verbose bool
Cicd bool
AlwaysSucceed bool
Endpoints string
WordList string
Path string
Mode string
Min int
Max int
}
func main() {
fmt.Println("[+] Break Out The Box")
exitCode = 0
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
pathPtr = flag.String("path", "/", "Path to Start Scanning for UNIX Domain Sockets")
verbosePtr = flag.Bool("verbose", false, "Verbose output")
huntSockPtr = flag.Bool("find-sockets", false, "Hunt for Available UNIX Domain Sockets")
huntHttpPtr = flag.Bool("find-http", false, "Hunt for Available UNIX Domain Sockets with HTTP")
autopwnPtr = flag.Bool("autopwn", false, "Attempt to autopwn exposed sockets")
cicdPtr = flag.Bool("cicd", false, "Attempt to autopwn but don't drop to TTY,return exit code 1 if successful else 0")
reconPtr = flag.Bool("recon", false, "Perform Recon of the Container ENV")
metaDataPtr = flag.Bool("metadata", false, "Attempt to find metadata services")
aggressivePtr = flag.String("aggr", "nil", "Attempt to exploit RuncPWN")
hijackPtr = flag.String("hijack", "nil", "Attempt to hijack binaries on host")
wordlistPtr = flag.String("wordlist", "nil", "Provide a wordlist")
endpointList = flag.String("endpoints", "nil", "Provide a textfile with endpoints to use for test")
findDockerdPtr = flag.Bool("find-docker", false, "Attempt to find Dockerd")
pushToS3ptr = flag.String("s3push", "nil", "Push a file to S3 e.g Full command to push to https://YOURBUCKET.s3.eu-west-2.amazonaws.com/FILENAME would be: -region eu-west-2 -s3bucket YOURBUCKET -s3push FILENAME")
s3BucketPtr = flag.String("s3bucket", "nil", "Provide a bucket name for S3 Push")
awsRegionPtr = flag.String("region", "nil", "Provide a AWS Region e.g eu-west-2")
scrapeGcpMeta = flag.Bool("scrape-gcp", false, "Attempt to scrape the GCP metadata service")
cgroupPtr = flag.String("pwn-privileged", "nil", "Provide a command payload to try exploit --privilege CGROUP release_agent's")
alwaysSucceedPtr = flag.Bool("always-succeed", false, "Always set BOtB's Exit code to Zero")
configPtr = flag.String("config", "nil", "Load config from provided yaml file")
revDNSPtr = flag.String("rev-dns", "nil", "Perform reverse DNS lookups on a subnet. Parameter must be in CIDR notation, e.g., -rev-dns 192.168.0.0/24")
k8secrets = flag.Bool("k8secrets", false, "Identify and Verify K8's Secrets")
pwnKeyctl = flag.Bool("pwnKeyctl", false, "Abuse keyctl syscalls and extract data from Linux Kernel keyrings")
keyMin = flag.Int("keyMin", 1, " Minimum key id range (default 1)")
keyMax = flag.Int("keyMax", 100000000, " Maximum key id range (default 100000000) and max system value is 999999999")
flag.Parse()
if *configPtr != "nil" {
//prep the config with some defaults
cfg := Config{Path: ".", Verbose: false, Cicd: false, Payload: "nil"}
cfg, err := loadConfig(*configPtr, cfg)
if err != nil {
fmt.Println("[ERROR] Loading config", err)
return
}
*verbosePtr = cfg.Verbose
runCfgArgs(cfg)
} else {
runCMDArgs()
}
fmt.Println("[+] Finished")
if *alwaysSucceedPtr {
os.Exit(0)
} else {
os.Exit(exitCode)
}
}
func loadConfig(configPath string, config Config) (Config, error) {
fmt.Println("[+] Loading Config:", configPath)
source, err := ioutil.ReadFile(configPath)
if err != nil {
return config, err
}
err = yaml.Unmarshal(source, &config)
if err != nil {
return config, err
}
return config, nil
}
func runCfgArgs(cfg Config) {
switch cfg.Mode {
case "find-sockets":
findDomainSockets(cfg.Path)
case "find-http":
findHttpSockets(cfg.Path)
case "find-docker":
findDockerD()
case "metadata":
checkMetadataServices(cfg.Endpoints)
case "autopwn":
autopwn(cfg.Path, cfg.Cicd)
case "recon":
fmt.Println("[+] Performing Container Recon")
checkProcEnviron(cfg.WordList)
checkEnvVars(cfg.WordList)
case "scrape-gcp":
scrapeMetadataEndpoints(cfg.Endpoints)
case "hijack":
hijackBinaries(cfg.Payload)
case "aggr":
runcPwn(cfg.Payload)
case "pwn-privileged":
abuseCgroupPriv(cfg.Payload)
case "pwn-keyctl":
pwnKeyCtl(cfg.Max, cfg.Min)
default:
fmt.Println("[!] Invalid mode provided")
}
}
func runCMDArgs() {
if *pwnKeyctl {
pwnKeyCtl(*keyMin, *keyMax)
}
if *k8secrets {
idenitfyVerifyK8Secrets()
}
if *cgroupPtr != "nil" {
abuseCgroupPriv(*cgroupPtr)
}
if *scrapeGcpMeta {
scrapeMetadataEndpoints(*endpointList)
}
if *pushToS3ptr != "nil" {
if *s3BucketPtr == "nil" {
fmt.Println("[!] Please provide a bucket name")
return
}
if *awsRegionPtr == "nil" {
fmt.Println("[!] Please provide a region")
return
}
testUploadOfS3(*pushToS3ptr, *s3BucketPtr, *awsRegionPtr)
}
if *findDockerdPtr {
findDockerD()
}
if *huntHttpPtr {
findHttpSockets(*pathPtr)
}
if *hijackPtr != "nil" {
hijackBinaries(*hijackPtr)
}
if *aggressivePtr != "nil" {
runcPwn(*aggressivePtr)
}
if *reconPtr {
fmt.Println("[+] Performing Container Recon")
checkProcEnviron(*wordlistPtr)
checkEnvVars(*wordlistPtr)
}
if *metaDataPtr {
checkMetadataServices(*endpointList)
}
if *autopwnPtr {
autopwn(*pathPtr, *cicdPtr)
}
if *huntSockPtr {
fmt.Println("[+] Hunting Down UNIX Domain Sockets from:", *pathPtr)
sockets, _ := getValidSockets(*pathPtr)
for _, element := range sockets {
fmt.Println("[!] Valid Socket: " + element)
exitCode = 1
}
}
if *revDNSPtr != "nil" {
reverseDNS(*revDNSPtr)
}
}