Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Ozymandias42/f8da04ce73d26a23b718be10ea8bc28a to your computer and use it in GitHub Desktop.

Select an option

Save Ozymandias42/f8da04ce73d26a23b718be10ea8bc28a to your computer and use it in GitHub Desktop.
listCapabilitiesOfPID.sh
#!/usr/bin/env sh
INPUT=$1
CAPABILITIES=""
function parseCapsFromProc(){
grep CapPrm /proc/$1/status \
| awk '{print $2}'
}
function computeInput(){
#check if $1 is set at all of input is from pipe
if [ -z "${INPUT}" ]; then
read -r INPUT
echo $INPUT
fi
#check if input PID or Cap-Hex-representation
case $INPUT in
#if Cap-Hex-rep
0*) CAPABILITIES=$INPUT ;;
#else, default cse.
*) CAPABILITIES=$(parseCapsFromProc $INPUT) ;;
esac
}
case $1 in
--help) echo "help" ;;
*) computeInput ;;
esac
CAPABILITIES=$(\
capsh --decode=$CAPABILITIES | \
awk -F'=' '{print $2}' | \
tr ',' '\n'
)
printf "%s\n" ${CAPABILITIES:-"No Capabilities set for PID $PID"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment