From 323c594c914c2c9038a880ea87d2b07a47741841 Mon Sep 17 00:00:00 2001 From: Enrico204 Date: Mon, 23 Aug 2021 11:05:33 +0200 Subject: [PATCH] Add impersonate self syscall --- syscallex/advapi32_windows.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/syscallex/advapi32_windows.go b/syscallex/advapi32_windows.go index 77afd53..69f2203 100644 --- a/syscallex/advapi32_windows.go +++ b/syscallex/advapi32_windows.go @@ -42,6 +42,7 @@ var ( procCreateProcessWithLogonW = modadvapi32.NewProc("CreateProcessWithLogonW") procLogonUserW = modadvapi32.NewProc("LogonUserW") + procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf") procImpersonateLoggedOnUser = modadvapi32.NewProc("ImpersonateLoggedOnUser") procRevertToSelf = modadvapi32.NewProc("RevertToSelf") procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW") @@ -129,6 +130,23 @@ func LogonUser( return } +func ImpersonateSelf(impersonationLevel int) (err error) { + r1, _, e1 := syscall.Syscall( + procImpersonateSelf.Addr(), + 1, + uintptr(impersonationLevel), + 0, 0, + ) + if r1 == 0 { + if e1 != 0 { + err = e1 + } else { + err = syscall.EINVAL + } + } + return +} + func ImpersonateLoggedOnUser( token syscall.Token, ) (err error) {