Created
January 20, 2025 19:51
-
-
Save mattaereal/b65a0d62fa7f40a46aefddb251d56330 to your computer and use it in GitHub Desktop.
Check binaries for capabilities
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
#!/bin/bash | |
# Function to find binaries with capabilities | |
find_cap_binaries() { | |
# Get all directories in $PATH | |
IFS=':' read -r -a path_dirs <<< "$PATH" | |
# Loop through each directory | |
for dir in "${path_dirs[@]}"; do | |
# Check if the directory exists | |
if [[ -d "$dir" ]]; then | |
echo "Checking binaries in: $dir" | |
# Loop through all files in the directory | |
for file in "$dir"/*; do | |
# Check if the file is a regular file and executable | |
if [[ -f "$file" && -x "$file" ]]; then | |
# Use getcap to check for capabilities | |
capabilities=$(getcap "$file") | |
if [[ -n "$capabilities" ]]; then | |
echo "$capabilities" | |
fi | |
fi | |
done | |
fi | |
done | |
} | |
# Run the function | |
find_cap_binaries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment