Skip to content

Instantly share code, notes, and snippets.

@rusty-snake
Last active October 22, 2020 10:36
Show Gist options
  • Save rusty-snake/7ed6b2a5bed3a6a9709b0faf9fcc86ab to your computer and use it in GitHub Desktop.
Save rusty-snake/7ed6b2a5bed3a6a9709b0faf9fcc86ab to your computer and use it in GitHub Desktop.
firejail_seccomp_notify.sh - Notification on Seccomp violations, useful for debugging
#!/usr/bin/env bash
# Copyright © 2019,2020 rusty-snake
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
usage() {
echo "Usage:"
echo -e "\tNOTIFY_TOOL=\"<ZENITY|KDIALOG|NOTIFY-SEND>\" bash $0"
}
if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "-?" ]; then
usage "$@"
exit 0
fi
if [ ! -v "NOTIFY_TOOL" ]; then
printf "Error: \"NOTIFY_TOOL\" not set.\n"
usage "$@"
exit 1
fi
if [ "$NOTIFY_TOOL" == "ZENITY" ]; then
notify_cmd="zenity"
notify_args=(--title "Syscall violation" --warning --text)
elif [ "$NOTIFY_TOOL" == "KDIALOG" ]; then
notify_cmd="kdialog"
notify_args=(--title "Syscall violation" --sorry)
elif [ "$NOTIFY_TOOL" == "NOTIFY-SEND" ]; then
notify_cmd="notify-send"
notify_args=(--icon "dialog-warning" "Syscall violation")
else
printf "Error: Invalid value for NOTIFY_TOOL.\n"
usage "$@"
exit 1
fi
tmpdir=$(mktemp -d)
cleanup() {
kill %journalctl
rm -rf "$tmpdir"
}
trap cleanup EXIT
FIREJAIL_DEBUG_SYSCALLS=$tmpdir/firejail_debug-syscalls
firejail --debug-syscalls > "$FIREJAIL_DEBUG_SYSCALLS"
SHOW_SYSCALL_PIPE=$tmpdir/pipe
mkfifo "$SHOW_SYSCALL_PIPE"
show_syscall() {
grep --line-buffered -oE "syscall=[[:digit:]]{1,3}" | sed --unbuffered "s/syscall=//g" | xargs -L1 -I{} grep -E "^{}[[:space:]]" "$FIREJAIL_DEBUG_SYSCALLS" | sed --unbuffered -E "s/^[[:digit:]]{1,3}[[:space:]]+-[[:space:]]/syscall: /g"
}
journalctl --grep="SECCOMP" --output=json --follow | jq --unbuffered ".MESSAGE" | tee "$SHOW_SYSCALL_PIPE" | xargs -L1 -P0 --delimiter="\n" "$notify_cmd" "${notify_args[@]}" & show_syscall < "$SHOW_SYSCALL_PIPE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment