Skip to content

Instantly share code, notes, and snippets.

@michaeljclark
Created October 14, 2021 22:49
Show Gist options
  • Save michaeljclark/441e9096e79bbab75fa1700e33414332 to your computer and use it in GitHub Desktop.
Save michaeljclark/441e9096e79bbab75fa1700e33414332 to your computer and use it in GitHub Desktop.
search common directories for Linux ELF executables with executable stack
#!/bin/sh
# search common directories for Linux ELF executables with executable stack
is_elf() {
od -t x4 -N 4 $1 | sed -n 's/.*464c457f.*/YES/ p'
}
is_exec_stack() {
readelf -l $1 2>&1 | sed -n '/GNU_STACK/ {n; s/.*RWE.*$/YES/ p}'
}
for i in $(find /lib /bin /usr/lib /usr/bin -type f -a -executable); do
if [ "$(is_elf ${i})" = "YES" -a "$(is_exec_stack ${i})" = "YES" ]; then
echo $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment