-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f61d879
commit 06212aa
Showing
10 changed files
with
92 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# privilegesutil | ||
The package contains various helpers for previleges |
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,7 @@ | ||
package privileges | ||
|
||
var IsPrivileged bool | ||
|
||
func init() { | ||
IsPrivileged = isPrivileged() | ||
} |
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,12 @@ | ||
//go:build darwin | ||
|
||
package privileges | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// isPrivileged checks if the current process has the CAP_NET_RAW capability or is root | ||
func isPrivileged() bool { | ||
return os.Geteuid() == 0 | ||
} |
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,34 @@ | ||
//go:build linux || unix | ||
|
||
package privileges | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
|
||
"github.com/projectdiscovery/naabu/v2/pkg/israce" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// isPrivileged checks if the current process has the CAP_NET_RAW capability or is root | ||
func isPrivileged() bool { | ||
// runtime.LockOSThread interferes with race detection | ||
if !israce.Enabled { | ||
header := unix.CapUserHeader{ | ||
Version: unix.LINUX_CAPABILITY_VERSION_3, | ||
Pid: int32(os.Getpid()), | ||
} | ||
data := unix.CapUserData{} | ||
runtime.LockOSThread() | ||
defer runtime.UnlockOSThread() | ||
|
||
if err := unix.Capget(&header, &data); err == nil { | ||
data.Inheritable = (1 << unix.CAP_NET_RAW) | ||
|
||
if err := unix.Capset(&header, &data); err == nil { | ||
return true | ||
} | ||
} | ||
} | ||
return os.Geteuid() == 0 | ||
} |
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,8 @@ | ||
//go:build windows | ||
|
||
package privileges | ||
|
||
// IsPrivileged on windows doesn't matter as we are using connect scan | ||
func isPrivileged() bool { | ||
return false | ||
} |
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,2 @@ | ||
# raceutil | ||
The package contains various helpers for race |
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,7 @@ | ||
//go:build !race | ||
|
||
// Package israce reports if the Go race detector is enabled. | ||
package israce | ||
|
||
// Enabled reports if the race detector is enabled. | ||
const Enabled = false |
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,7 @@ | ||
//go:build race | ||
|
||
// Package israce reports if the Go race detector is enabled. | ||
package israce | ||
|
||
// Enabled reports if the race detector is enabled. | ||
const Enabled = true |