Skip to content

Instantly share code, notes, and snippets.

@Aptimex
Created November 21, 2025 20:40
Show Gist options
  • Select an option

  • Save Aptimex/4da07ced36d7770d5fa05d2e5e7ec095 to your computer and use it in GitHub Desktop.

Select an option

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
// 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