Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Last active September 27, 2018 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ansemjo/816098f0227ad830e6644bd82e9d2c28 to your computer and use it in GitHub Desktop.
Save ansemjo/816098f0227ad830e6644bd82e9d2c28 to your computer and use it in GitHub Desktop.
wrapper for slimm609/checksec.sh which displays nicer-formatted output
#!/usr/bin/env bash
# wrapper script for slimm609/checksec.sh for nicer output format
# download https://github.com/slimm609/checksec.sh/blob/master/checksec to PATH
# further requires jq and objdump in PATH
CHECKSEC=checksec
set -e
# version information
$CHECKSEC --version
box() { printf ' [\033[1;%dm%s\033[0m] %s\n' "$1" "$2" "$3"; }
res() {
{ [[ $1 == yes ]] && box "32" "+" "$2"; } || \
{ [[ $1 == partial ]] && box "33" "*" "$3"; } || \
box "31" "-" "$4"; }
get() { jq -r ".file.$1"; }
inv() { [[ $(get "$1") == no ]] && echo yes || echo no; }
sec() {
# run test and receive json results
printf '\033[1mfile: %q\033[0m\n' "${1:?filename required}"
box "34" "i" "$(objdump -f "$1" | sed -n 's/.*file format //p')"
JSON=$($CHECKSEC --output json --file "$1")
# display results
echo $JSON | res "$(get relro)" {Full,Partial,No}\ RELRO
echo $JSON | res "$(get canary)" {,?,No\ }Canary\ found
echo $JSON | res "$(get nx)" NX\ {enabled,?,disabled}
echo $JSON | res "$(get pie)" PIE\ {enabled,?,disabled}
echo $JSON | res "$(inv rpath)" {No\ RUNPATH,?,RUNPATH\ present}
echo $JSON | res "$(inv symtables)" {No\ Symbols,?,Symbols\ found}
echo $JSON | res "$(get fortify_source)" {Fortify,?,Not\ fortified}
echo
}
for arg in "$@"; do
sec "$arg"
done
@ansemjo
Copy link
Author

ansemjo commented Sep 27, 2018

output sample

screenshot from 2018-09-27 23-11-40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment