Skip to content

Instantly share code, notes, and snippets.

@raresteak
Last active March 15, 2019 16:52
Show Gist options
  • Save raresteak/ea537dc433c8f00cbd09c20e02c6c4fe to your computer and use it in GitHub Desktop.
Save raresteak/ea537dc433c8f00cbd09c20e02c6c4fe to your computer and use it in GitHub Desktop.
Enumerate users with sudo access on a system
#!/bin/bash
###############################################################################
#Script Name : enumerate_sudo_users
#Description : Check which users on system can sudo with some form of
# privileged access.
#Author : Github raresteak
###############################################################################
[[ "$TRACE" ]] && set -x
[[ "$HEADER" ]] && echo "UserName,SystemName" # Useful for putting in a spreadsheet
main() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
for user in $(compgen -u); do
(((sudo -l -U $user | grep "^User") | grep -v "not allowed") | awk {'print $2","$9'} ) | sed "s/://g"
done
}
main
@raresteak
Copy link
Author

raresteak commented Mar 15, 2019

Run script as root.

Sample output is username comma servername

root,server01
jackn,server01
dba,server01
printop,server01

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