-
Notifications
You must be signed in to change notification settings - Fork 30
/
web.go
249 lines (214 loc) Β· 11.8 KB
/
web.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
package main
import (
"fmt"
"html"
"math"
"os"
"runtime"
"strings"
"time"
)
func genReport(img *imageData) {
// displayTeamID is used for the tiling background.
var displayTeamID string
if len(teamID) < 7 {
displayTeamID = "1010 1101"
} else {
displayTeamID = html.EscapeString(teamID)
}
header := `<!DOCTYPE html> <html> <head> <meta http-equiv="refresh" content="60"> <title>Aeacus Scoring Report</title> <style type="text/css"> h1 { text-align: center; } h2 { text-align: center; } body { font-family: Arial, Verdana, sans-serif; font-size: 14px; margin: 0; padding: 0; width: 100%; height: 100%; background: url('./img/background.png'); background-size: cover; background-attachment: fixed; background-position: top center; background-color: #336699; } ul { margin-top: 0.5rem; } .red {color: red;} .green {color: green;} .blue {color: blue;} .gray {color: gray;} .main { margin-top: 10px; margin-bottom: 10px; margin-left: auto; margin-right: auto; padding: 0px; border-radius: 12px; background-color: white; width: 900px; max-width: 100%; min-width: 600px; box-shadow: 0px 0px 12px #003366; } .text { padding: 12px; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .center { text-align: center; } .binary { position: relative; overflow: hidden; } .binary::before { position: absolute; top: -1000px; left: -1000px; display: block; width: 500%; height: 300%; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); content: attr(data-binary); opacity: 0.15; line-height: 2em; letter-spacing: 2px; color: #369; font-size: 10px; pointer-events: none; } </style> <meta http-equiv="refresh"> </head> <body><div class="main"><div class="text"><div class="binary" data-binary="` + displayTeamID + `"><p align=center style="width:100%;text-align:center"><img align=middle style="width:180px; float:middle" src="./img/logo.png"></p>`
footer := `</p> <br> <p align=center style="text-align:center"> The Aeacus project is free and open source software. This project is in no way endorsed or affiliated with the Air Force Association or the University of Texas at San Antonio. </p> </div> </div> </div> </body> </html>`
genTime := time.Now()
var htmlFile strings.Builder
htmlFile.WriteString(header)
htmlFile.WriteString("<h1>" + html.EscapeString(conf.Title) + "</h1>")
htmlFile.WriteString("<h2>Report Generated At: " + genTime.Format("2006/01/02 15:04:05 MST") + " </h2>")
htmlFile.WriteString(`<script>var bin = document.querySelectorAll('.binary'); [].forEach.call(bin, function(el) { el.dataset.binary = Array(10000).join(el.dataset.binary + ' ') }); var currentdate = new Date().getTime(); gendate = Date.parse('0000/00/00 00:00:00 UTC'); diff = Math.abs(currentdate - gendate); if ( gendate > 0 && diff > 1000 * 60 * 5 ) { document.write('<span class="red"><h2>WARNING: CSS Scoring service may not be running</h2></span>'); } </script>`)
if conf.Remote != "" {
if teamID == "" {
htmlFile.WriteString(`<h3 class="center">Current Team ID: <span class="red">N/A</span></h3>`)
} else {
htmlFile.WriteString(`<h3 class="center">Current Team ID: ` + html.EscapeString(teamID) + `</h3>`)
}
}
htmlFile.WriteString(fmt.Sprintf(`<h2> %d out of %d points received</h2>`, img.Score, img.TotalPoints))
if conf.Remote != "" {
htmlFile.WriteString(`<a href="` + html.EscapeString(conf.Remote) + `">Click here to view the public scoreboard</a><br>`)
htmlFile.WriteString(`<a href="` + html.EscapeString(conf.Remote) + `/announcements` + `">Click here to view the announcements</a><br>`)
htmlFile.WriteString(`<p><h3>Connection Status: <span class="` + conn.OverallColor + `">` + conn.OverallStatus + `<span></h3>`)
htmlFile.WriteString(`Internet Connectivity Check: <span class="` + conn.NetColor + `">` + conn.NetStatus + `</span><br>`)
htmlFile.WriteString(`Aeacus Server Connection Status: <span class="` + conn.ServerColor + `">` + conn.ServerStatus + `</span></p>`)
} else {
htmlFile.WriteString(`<p><h3>Connection Status: <span class="` + conn.OverallColor + `">` + conn.OverallStatus + `<span></h3>`)
htmlFile.WriteString(`Internet Connectivity Check: <span class="gray">N/A</span><br>`)
htmlFile.WriteString(`Aeacus Server Connection Status: <span class="gray">N/A</span><br>`)
}
htmlFile.WriteString(fmt.Sprintf(`<h3> %d penalties assessed, for a loss of %.0f points: </h3> <p> <span class="red">`, len(img.Penalties), math.Abs(float64(img.Detracts))))
// for each penalty:
for _, penalty := range img.Penalties {
deobfuscateData(&penalty.Message)
htmlFile.WriteString(fmt.Sprintf("%s - %.0f pts<br>", html.EscapeString(penalty.Message), math.Abs(float64(penalty.Points))))
obfuscateData(&penalty.Message)
}
htmlFile.WriteString(fmt.Sprintf(`</span> </p> <h3> %d out of %d scored security issues fixed, for a gain of %d points:</h3><p>`, len(img.Points), img.ScoredVulns, img.Contribs))
// for each point:
for _, point := range img.Points {
deobfuscateData(&point.Message)
htmlFile.WriteString(fmt.Sprintf("%s - %d pts<br>", html.EscapeString(point.Message), point.Points))
obfuscateData(&point.Message)
}
htmlFile.WriteString("</p>")
// for each hint:
for _, hint := range img.Hints {
if len(hint.Messages) == 1 {
deobfuscateData(&hint.Messages[0])
htmlFile.WriteString(fmt.Sprintf("<span class='gray'>(%d pts) <b>Hint</b>: %s</span><br>", hint.Points, html.EscapeString(hint.Messages[0])))
obfuscateData(&hint.Messages[0])
} else if len(hint.Messages) > 1 {
htmlFile.WriteString(fmt.Sprintf("<p style='margin-bottom: 0'><span class='gray'>(%d pts) <b>Hints:</b></span></p><ul>", hint.Points))
for i := range hint.Messages {
deobfuscateData(&hint.Messages[i])
htmlFile.WriteString(fmt.Sprintf("<li><span class='gray'>%s</span></li>", html.EscapeString(hint.Messages[i])))
obfuscateData(&hint.Messages[i])
}
htmlFile.WriteString("</ul></span>")
}
}
htmlFile.WriteString(footer)
info("Writing HTML to ScoringReport.html...")
writeFile(dirPath+"assets/ScoringReport.html", htmlFile.String())
}
// genReadMe generates a competition ReadMe with some built-in defaults from
// your ReadMe.conf.
func genReadMe() {
header := `
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aeacus README</title>
<style>
body {
background-image: url("./img/background.png");
background-size: cover;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
text-align: center;
font-size: 36px;
margin: 10px;
padding: 0 14px 10px 0px;
width: 100%;
height: 100%;
color: #0D2E5B !important
}
h2 {
font-size: 18px;
margin: 30px 0 10px 0;
padding: 0;
width: 100%;
height: 100%;
color: #0D2E5B !important
}
pre {
font-size: 16px
}
.main {
margin-top: 25px;
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
padding: 0px;
background-color: white;
max-width: 100%
}
.text {
padding-top: 12px;
padding-bottom: 12px;
padding-left: 40px;
padding-right: 40px
}
.center {
text-align: center
}
</style>
<div style="width: 80%; margin-left: auto; margin-right: auto; display: block" >
<div class="main">
<div class="text">
<p align="center">
<img src="./img/logo.png" style="width: 250px">
</p>
`
footer := `<h2>Competition Guidelines</h2><ul><li> In order to provide a better competition experience, you are
<b>NOT</b> required to change the password of the primary, auto-login, user account.
Changing the password of a user that is set to automatically log in may lock you out of your computer.
</li><li> Authorized administrator passwords were correct the last time you did a password audit,
but are not guaranteed to be currently accurate.</li><li> Do not disable or stop the CSSClient service or process.
</li><li> Do not remove any authorized users or their home directories.</li><li>
The time zone of this image is set to UTC. Please do not change the time zone, date, or time on this image.</li><li>
You can view your current scoring report by double-clicking the "Scoring Report" desktop icon.</li><li>
JavaScript is required for some error messages that appear on the "Scoring Report."
To ensure that you only receive correct error messages, please do not disable JavaScript.</li><li>
Some security settings may prevent the Stop Scoring application from running.
If this happens, the safest way to stop scoring is to suspend the virtual machine.
You should <b>NOT</b> power on the VM again before deleting.</li></ul>
<p align="center" style="text-align:center">
The Aeacus Project is in no way affiliated or endorsed by the Air Force Association or the University of Texas at
San Antonio.
</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<div class="footer"><div class="footer-copyright-wrap"><div class="container"><div class="footer-copyright-content">
<ul><li>Copyright Never ©</li><li>No rights reserved</li></ul></div></div></div></div></body></html>`
headerTheSequel := `<p> Please read the entire README thoroughly before modifying anything on this computer.</p>
<h2>Unique Identifier</h2>
<p> If you have not yet entered a valid Team ID, please do so immediately by double clicking on the "Team ID" icon
on the desktop.
If you do not enter a valid Team ID this VM may stop functioning after a short period of time.
</p><h2>Forensics Questions</h2><p> If there are "Forensics Questions" on your Desktop, you will receive points for
answering these questions correctly.
Valid (scored) "Forensics Questions" will only be located directly on your Desktop.
Please read all "Forensics Questions" thoroughly before modifying this computer, as you may change something that
prevents you from answering the question correctly.
</p><h2>Competition Scenario</h2><p>
This company's security policies require that all user accounts be password protected.
Employees are required to choose secure passwords, however this policy may not be currently enforced on this
computer.
The presence of any non-work related media files and "hacking tools" on any computers is strictly prohibited.
This company currently does not use any centralized maintenance or polling tools to manage their IT equipment.
This computer is for official business use only by authorized users. This is a critical computer in a production
environment.
Please do <b>NOT</b> attempt to upgrade the operating system on this machine.</p>`
var htmlFile strings.Builder
htmlFile.WriteString(header)
htmlFile.WriteString("<h1><b>" + conf.OS + " " + conf.Title + " README</b></h1>")
htmlFile.WriteString(headerTheSequel)
htmlFile.WriteString("<h2><b>" + conf.OS + "</b></h2>")
htmlFile.WriteString(`<p>
It is company policy to use only ` + conf.OS + ` on this computer. It is also company policy to use only the
latest, official, stable ` + conf.OS + ` packages available for required software and services on this computer.
Management has decided that the default web browser for all users on this computer should be the latest stable
version of Firefox.`)
if runtime.GOOS == "linux" {
htmlFile.WriteString(` Company policy is to never let users log in as root.
If administrators need to run commands as root, they are required to use the "sudo" command.`)
}
htmlFile.WriteString("</p>")
// Check for common variations of ReadMe.conf.
var userReadMe string
var err error
readMeFiles := []string{"ReadMe.conf", "README.conf", "readme.conf"}
for _, readme := range readMeFiles {
userReadMe, err = readFile(readme)
if err == nil {
break
}
}
if err != nil {
fail("No ReadMe.conf file found!")
os.Exit(1)
}
htmlFile.WriteString(userReadMe)
htmlFile.WriteString(footer)
info("Writing HTML to ReadMe.html...")
writeFile(dirPath+"assets/ReadMe.html", htmlFile.String())
}