-
Notifications
You must be signed in to change notification settings - Fork 29
/
release_windows.go
170 lines (145 loc) · 7.04 KB
/
release_windows.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
package main
// writeDesktopFiles writes default scoring engine files to the desktop.
func writeDesktopFiles() {
firefoxBinary := `C:\Program Files\Mozilla Firefox\firefox.exe`
info("Writing ScoringReport.html shortcut to Desktop...")
cmdString := `$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut("C:\Users\` + conf.User + `\Desktop\ScoringReport.lnk"); $Shortcut.TargetPath = "` + firefoxBinary + `"; $Shortcut.Arguments = "C:\aeacus\assets\ScoringReport.html"; $Shortcut.Save()`
shellCommand(cmdString)
info("Writing ReadMe.html shortcut to Desktop...")
cmdString = `$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut("C:\Users\` + conf.User + `\Desktop\ReadMe.lnk"); $Shortcut.TargetPath = "` + firefoxBinary + `"; $Shortcut.Arguments = "C:\aeacus\assets\ReadMe.html"; $Shortcut.Save()`
shellCommand(cmdString)
info("Creating or emptying TeamID.txt file...")
cmdString = "echo 'YOUR-TEAMID-HERE' > C:\\aeacus\\TeamID.txt"
shellCommand(cmdString)
info("Changing Permissions of TeamID...")
powershellPermission := `
$ACL = Get-ACL C:\aeacus\TeamID.txt
$ACL.SetOwner([System.Security.Principal.NTAccount] $env:USERNAME)
Set-Acl -Path C:\aeacus\TeamID.txt -AclObject $ACL
`
shellCommand(powershellPermission)
info("Writing TeamID shortcut to Desktop...")
cmdString = `$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut("C:\Users\` + conf.User + `\Desktop\TeamID.lnk"); $Shortcut.TargetPath = "C:\aeacus\phocus.exe"; $Shortcut.Arguments = "-i yes"; $Shortcut.Save()`
shellCommand(cmdString)
// domain compatibility? doubt
}
// configureAutologin allows the current user to log in automatically.
func configureAutologin() {
info("Setting Up autologin for " + conf.User + "...")
powershellAutoLogin := `
function Test-RegistryValue {
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Value
)
try {
Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
$RegPath1Exists = Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Value "DefaultUsername"
if ($RegPath1Exists -eq $false) {
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultUsername" -Value $env:USERNAME -type String
}
elseif ($RegPath1Exists -eq $true) {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultUsername" -Value $env:USERNAME -type String
}
$RegPath2Exists = Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Value "AutoAdminLogon"
if ($RegPath2Exists -eq $false) {
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AutoAdminLogon" -Value 1 -type String
}
elseif ($RegPath2Exists -eq $true) {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AutoAdminLogon" -Value 1 -type String
}
`
shellCommand(powershellAutoLogin)
}
// installFont installs the Raleway font for ID Prompt.
func installFont() {
info("Installing Raleway font for ID Prompt...")
powershellFontInstall := `
$SourceDir = "C:\aeacus\assets\fonts\Raleway"
$Source = "C:\aeacus\assets\fonts\Raleway\*"
$Destination = (New-Object -ComObject Shell.Application).Namespace(0x14)
$TempFolder = "C:\Windows\Temp\Fonts"
# Create the source directory if it doesn't already exist
New-Item -ItemType Directory -Force -Path $SourceDir | Out-Null
New-Item $TempFolder -Type Directory -Force | Out-Null
Get-ChildItem -Path $Source -Include '*.ttf','*.ttc','*.otf' -Recurse | ForEach {
If (-not(Test-Path "C:\Windows\Fonts\$($_.Name)")) {
$Font = "$TempFolder\$($_.Name)"
# Copy font to local temporary folder
Copy-Item $($_.FullName) -Destination $TempFolder
# Install font
$Destination.CopyHere($Font,0x10)
# Delete temporary copy of font
Remove-Item $Font -Force
}
}
`
shellCommand(powershellFontInstall)
}
// installService installs the Aeacus service on Windows.
func installService() {
info("Installing service with sc.exe...")
cmdString := `sc.exe create CSSClient binPath= "C:\aeacus\phocus.exe" start= "auto" DisplayName= "CSSClient"`
shellCommand(cmdString)
info("Setting service description...")
cmdString = `sc.exe description CSSClient "This is Aeacus's Competition Scoring System client. Don't stop or mess with this unless you want to not get points, and maybe have your registry deleted."`
shellCommand(cmdString)
info("Setting up TeamID scheduled task...")
idTaskCreate := `
$action = New-ScheduledTaskAction -Execute "C:\aeacus\phocus.exe" -Argument "-i yes"
$trigger = New-ScheduledTaskTrigger -AtLogon
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
Register-ScheduledTask -TaskName "TeamID" -Description "Scheduled Task to ensure Aeacus TeamID prompt is displayed when needed" -Action $action -Trigger $trigger -Principal $principal
`
serviceTaskCreate := `
$action = New-ScheduledTaskAction -Execute "net.exe" -Argument "start CSSClient"
$trigger = New-ScheduledTaskTrigger -AtLogon
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
Register-ScheduledTask -TaskName "CSSClient" -Description "Scheduled Task to ensure the CSSClient service remains up" -Action $action -Trigger $trigger -Principal $principal
`
shellCommand(idTaskCreate)
shellCommand(serviceTaskCreate)
addExclusions := `
Add-MpPreference -ExclusionPath "C:\aeacus\phocus.exe"
Add-MpPreference -ExclusionPath "C:\aeacus\"
`
shellCommand(addExclusions)
}
// cleanUp clears out sensitive files left behind by image developers or the
// scoring engine.
func cleanUp() {
info("Removing scoring.conf and ReadMe.conf...")
shellCommand("Remove-Item -Force C:\\aeacus\\scoring.conf")
shellCommand("Remove-Item -Path 'C:\\aeacus\\[R|r]*.conf' -Force")
info("Removing previous.txt...")
shellCommand("Remove-Item -Force C:\\aeacus\\previous.txt")
if !ask("Do you want to remove cache and history files from this machine?") {
return
}
info("Emptying recycle bin...")
shellCommand("Clear-RecycleBin -Force")
info("Clearing recently used...")
shellCommand("Remove-Item -Force '${env:USERPROFILE}\\AppData\\Roaming\\Microsoft\\Windows\\Recent*.lnk'")
info("Clearing run.exe command history...")
clearRunScript := `$path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU"
$arr = (Get-Item -Path $path).Property
foreach($item in $arr)
{
if($item -ne "MRUList")
{
Remove-ItemProperty -Path $path -Name $item -ErrorAction SilentlyContinue
}
}`
shellCommand(clearRunScript)
info("Removing Command History for Powershell")
shellCommand("Remove-Item (Get-PSReadlineOption).HistorySavePath")
warn("Done with automatic cleanup! You need to remove aeacus.exe manually. The only things you need in the C:\\aeacus directory is phocus, scoring.dat, TeamID.txt, and the assets directory.")
}