Skip to content

Instantly share code, notes, and snippets.

@mattaereal
Created January 20, 2025 19:51
Show Gist options
  • Save mattaereal/b65a0d62fa7f40a46aefddb251d56330 to your computer and use it in GitHub Desktop.
Save mattaereal/b65a0d62fa7f40a46aefddb251d56330 to your computer and use it in GitHub Desktop.
Check binaries for capabilities
#!/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