Skip to content

Commit 4cfa1f9

Browse files
committed
Enhanced permissions checks, adds support for scans in containers
1 parent 76c23f5 commit 4cfa1f9

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rust-version = "1.90"
1616
[dependencies]
1717

1818
# CLI & utilities
19+
caps = "0.5.6"
1920
clap = { version = "4.5", default-features = false, features = ["std", "suggestions", "color", "help"] }
2021
ansi_term = "0.12"
2122
rand = "0.9"

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ fn main() {
4444
process::exit(0);
4545
}
4646

47-
if !cfg!(windows) && !utils::is_root_user() {
48-
eprintln!("Should run this binary as root or use --help for options");
47+
if !cfg!(windows) && !utils::has_network_capability() {
48+
eprintln!(
49+
"Should run this binary as root, an user with CAP_NET_RAW capabilities or use --help for options"
50+
);
4951
process::exit(1);
5052
}
5153

src/utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::env;
21
use std::process;
32
use std::sync::Arc;
43

54
use ansi_term::Color::{Green, Red};
5+
use caps::{CapSet, Capability, has_cap};
66
use ipnetwork::{IpNetwork, NetworkSize};
77
use pnet_datalink::NetworkInterface;
88
use serde::Serialize;
@@ -11,11 +11,15 @@ use crate::args::ScanOptions;
1111
use crate::network::{ResponseSummary, TargetDetails};
1212

1313
/**
14-
* Based on the current UNIX environment, find if the process is run as root
15-
* user. This approach only supports Linux-like systems (Ubuntu, Fedore, ...).
14+
* Check if the current user has the CAP_NET_RAW capability.
15+
*
16+
* For network operations like ARP scanning, you don't necessarily need full
17+
* root - you just need CAP_NET_RAW capability to perform scans. This was before
18+
* implemented as a minimalistic check to see if the "USER" env was set to root,
19+
* but failed to work in containerized environments.
1620
*/
17-
pub fn is_root_user() -> bool {
18-
env::var("USER").unwrap_or_else(|_| String::from("")) == *"root"
21+
pub fn has_network_capability() -> bool {
22+
has_cap(None, CapSet::Effective, Capability::CAP_NET_RAW).unwrap_or(false)
1923
}
2024

2125
/**

0 commit comments

Comments
 (0)