Skip to content

Instantly share code, notes, and snippets.

@bunchc
Last active November 29, 2017 02:02
Show Gist options
  • Save bunchc/21171b2b49ca4fc7e4a39beba26988d3 to your computer and use it in GitHub Desktop.
Save bunchc/21171b2b49ca4fc7e4a39beba26988d3 to your computer and use it in GitHub Desktop.
Root Password is blank, so set it maybe?
#!/bin/bash
#
# @description Attempt at checking for and mitigating #isroot
#
##
# Get macOS version
OS_Version=$(sudo system_profiler SPSoftwareDataType | grep "System Version" | cut -d : -f 2 | cut -d " " -f 3 | sed "s:.[[:digit:]]*.$::g")
is_root_enabled () {
if sudo dscl . read /Users/root | grep -q AuthenticationAuthority; then
echo "Root is Enabled, checking if password is set.";
password_changed
else
echo "Disabled";
exit
fi
}
has_password () {
echo "Checking if root password was has been set."
if sudo dscl . read /Users/root | awk '/passwordLastSetTime/{getline; print}'; then
echo "Root password has been set.";
exit
else
echo "Root password is not set. Running 'sudo passwd -u root'";
sudo passwd -u root
fi
}
main () {
if [[ ${OS_Version} == "macOS 10.13" ]]; then
echo "Operating System is a match... checking."
is_root_enabled
else
echo "Operating System is NOT one we check for"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment