-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEnableAllTokens.go
85 lines (77 loc) · 2.45 KB
/
EnableAllTokens.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
package main
import (
"fmt"
"golang.org/x/sys/windows"
)
var tokens = []string{
"SeAssignPrimaryTokenPrivilege",
"SeAuditPrivilege",
"SeBackupPrivilege",
"SeChangeNotifyPrivilege",
"SeCreateGlobalPrivilege",
"SeCreatePagefilePrivilege",
"SeCreatePermanentPrivilege",
"SeCreateSymbolicLinkPrivilege",
"SeCreateTokenPrivilege",
"SeDebugPrivilege",
"SeDelegateSessionUserImpersonatePrivilege",
"SeEnableDelegationPrivilege",
"SeImpersonatePrivilege",
"SeIncreaseQuotaPrivilege",
"SeIncreaseBasePriorityPrivilege",
"SeIncreaseWorkingSetPrivilege",
"SeLoadDriverPrivilege",
"SeLockMemoryPrivilege",
"SeMachineAccountPrivilege",
"SeManageVolumePrivilege",
"SeProfileSingleProcessPrivilege",
"SeRelabelPrivilege",
"SeRemoteShutdownPrivilege",
"SeRestorePrivilege",
"SeSecurityPrivilege",
"SeShutdownPrivilege",
"SeSyncAgentPrivilege",
"SeSystemtimePrivilege",
"SeSystemEnvironmentPrivilege",
"SeSystemProfilePrivilege",
"SeTakeOwnershipPrivilege",
"SeTcbPrivilege",
"SeTimeZonePrivilege",
"SeTrustedCredManAccessPrivilege",
"SeUndockPrivilege",
}
func main() {
hProcess := windows.CurrentProcess()
var hToken windows.Token
err := windows.OpenProcessToken(hProcess, windows.TOKEN_ADJUST_PRIVILEGES|windows.TOKEN_QUERY, &hToken)
if err != nil {
fmt.Println("Error opening process token:", err)
return
}
defer hToken.Close()
for _, token := range tokens {
var luid windows.LUID
err := windows.LookupPrivilegeValue(nil, windows.StringToUTF16Ptr(token), &luid)
if err != nil {
fmt.Printf("Error looking up privilege value for %s: %v\n", token, err)
continue
}
tp := windows.Tokenprivileges{
PrivilegeCount: 1,
Privileges: [1]windows.LUIDAndAttributes{
{Luid: luid, Attributes: windows.SE_PRIVILEGE_ENABLED},
},
}
err = windows.AdjustTokenPrivileges(hToken, false, &tp, 0, nil, nil)
if err != nil {
fmt.Printf("Error adjusting token privileges for %s: %v\n", token, err)
continue
}
if windows.GetLastError() == windows.ERROR_NOT_ALL_ASSIGNED {
fmt.Printf("The privilege %s was not assigned.\n", token)
} else {
fmt.Printf("The privilege %s was successfully adjusted.\n", token)
}
}
fmt.Scanln()
}