forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added prompt and admin check to collector. (Velocidex#634)
- Loading branch information
Showing
61 changed files
with
564 additions
and
154 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//+ build: !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func checkAdmin() { | ||
if *artificat_command_collect_admin_flag && syscall.Geteuid() != 0 { | ||
fmt.Println("Velociraptor requires administrator level access. Use a 'Run as administrator' command shell to launch the binary.") | ||
os.Exit(-1) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//+ build: windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func checkAdmin() { | ||
if *artificat_command_collect_admin_flag && !IsAdmin() { | ||
fmt.Println("Velociraptor requires administrator level access. Use a 'Run as administrator' command shell to launch the binary.") | ||
os.Exit(-1) | ||
} | ||
} | ||
|
||
// https://github.com/golang/go/issues/28804 | ||
func IsAdmin() bool { | ||
var sid *windows.SID | ||
|
||
// Although this looks scary, it is directly copied from the | ||
// official windows documentation. The Go API for this is a | ||
// direct wrap around the official C++ API. | ||
// See https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-checktokenmembership | ||
err := windows.AllocateAndInitializeSid( | ||
&windows.SECURITY_NT_AUTHORITY, | ||
2, | ||
windows.SECURITY_BUILTIN_DOMAIN_RID, | ||
windows.DOMAIN_ALIAS_RID_ADMINS, | ||
0, 0, 0, 0, 0, 0, | ||
&sid) | ||
if err != nil { | ||
fmt.Printf("SID Error: %s\n", err) | ||
return false | ||
} | ||
defer windows.FreeSid(sid) | ||
|
||
// This appears to cast a null pointer so I'm not sure why this | ||
// works, but this guy says it does and it Works for Me™: | ||
// https://github.com/golang/go/issues/28804#issuecomment-438838144 | ||
token := windows.Token(0) | ||
|
||
member, err := token.IsMember(sid) | ||
if err != nil { | ||
fmt.Printf("Token Membership Error: %s", err) | ||
return false | ||
} | ||
|
||
// Also note that an admin is _not_ necessarily considered | ||
// elevated. | ||
// For elevation see https://github.com/mozey/run-as-admin | ||
fmt.Printf("IsElevated %v\n", token.IsElevated()) | ||
fmt.Printf("Member %v\n", member) | ||
return token.IsElevated() || member | ||
} |
Oops, something went wrong.