Created
November 21, 2025 20:40
-
-
Save Aptimex/4da07ced36d7770d5fa05d2e5e7ec095 to your computer and use it in GitHub Desktop.
Wrapper that can leverage SUID/SGID bits to execute other files that cannot directly benefit from those bits
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
| // https://engineering.purdue.edu/ECN/Support/KB/Docs/HowToSUIDSGIDscripts | |
| // Can target executable binaries and scripts | |
| // Compile: gcc -static ./suid-wrapper.c -o ./suid-wrapper | |
| // Prep: chmod u+s ./suid-wrapper | |
| int main(int argc, char ** argv) | |
| { | |
| /* Reset uid/gid */ | |
| setregid(getegid(), getegid()); | |
| setreuid(geteuid(), geteuid()); | |
| /* Attempt to execute script */ | |
| execv("./path/to/executable/file", argv); | |
| /* Reach here if execv failed */ | |
| perror("execv"); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment