-
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.
Merge pull request #18 from projectdiscovery/move-packages-from-naabu
move packages from naabu
- Loading branch information
Showing
11 changed files
with
120 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 @@ | ||
# permissionutils | ||
The package contains various helpers about permissions/privileges |
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,5 @@ | ||
package permissionutil | ||
|
||
import "errors" | ||
|
||
var ErrNotImplemented = errors.New("not implemented") |
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,11 @@ | ||
package permissionutil | ||
|
||
var ( | ||
IsRoot bool | ||
HasCapNetRaw bool | ||
) | ||
|
||
func init() { | ||
IsRoot, _ = checkCurrentUserRoot() | ||
HasCapNetRaw, _ = checkCurrentUserCapNetRaw() | ||
} |
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 @@ | ||
//go:build darwin | ||
|
||
package permissionutil | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// checkCurrentUserRoot checks if the current user is root | ||
func checkCurrentUserRoot() (bool, error) { | ||
return os.Geteuid() == 0, nil | ||
} | ||
|
||
// checkCurrentUserCapNetRaw checks if the current user has the CAP_NET_RAW capability | ||
func checkCurrentUserCapNetRaw() (bool, error) { | ||
return false, ErrNotImplemented | ||
} |
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,43 @@ | ||
//go:build linux || unix | ||
|
||
package permissionutil | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"runtime" | ||
|
||
raceutil "github.com/projectdiscovery/utils/race" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// checkCurrentUserRoot checks if the current user is root | ||
func checkCurrentUserRoot() (bool, error) { | ||
return os.Geteuid() == 0, nil | ||
} | ||
|
||
// checkCurrentUserCapNetRaw checks if the current user has the CAP_NET_RAW capability | ||
func checkCurrentUserCapNetRaw() (bool, error) { | ||
if raceutil.Enabled { | ||
return false, errors.New("race detector enabled") | ||
} | ||
// runtime.LockOSThread interferes with race detection | ||
header := unix.CapUserHeader{ | ||
Version: unix.LINUX_CAPABILITY_VERSION_3, | ||
Pid: int32(os.Getpid()), | ||
} | ||
data := unix.CapUserData{} | ||
runtime.LockOSThread() | ||
defer runtime.UnlockOSThread() | ||
|
||
err := unix.Capget(&header, &data) | ||
if err != nil { | ||
return false, err | ||
} | ||
data.Inheritable = (1 << unix.CAP_NET_RAW) | ||
if err = unix.Capset(&header, &data); err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} |
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,13 @@ | ||
//go:build windows | ||
|
||
package permissionutil | ||
|
||
// checkCurrentUserRoot on windows is not implemented | ||
func checkCurrentUserRoot() (bool, error) { | ||
return false, ErrNotImplemented | ||
} | ||
|
||
// checkCurrentUserCapNetRaw on windows is not implemented | ||
func checkCurrentUserCapNetRaw() (bool, error) { | ||
return false, ErrNotImplemented | ||
} |
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 raceutil reports if the Go race detector is enabled. | ||
package raceutil | ||
|
||
// 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 raceutil reports if the Go race detector is enabled. | ||
package raceutil | ||
|
||
// Enabled reports if the race detector is enabled. | ||
const Enabled = true |