Skip to content

Instantly share code, notes, and snippets.

@rweichler
Last active October 28, 2017 17:46
Show Gist options
  • Select an option

  • Save rweichler/82da580dfe1c23f9ed3b853a3cab74f8 to your computer and use it in GitHub Desktop.

Select an option

Save rweichler/82da580dfe1c23f9ed3b853a3cab74f8 to your computer and use it in GitHub Desktop.
setuid
#!/bin/sh
#set permissions of setuid binary
chown root:wheel /path/to/setuid
chmod 6755 /path/to/setuid
#include <unistd.h>
int main(int argc, char ** argv)
{
uid_t olduid = getuid();
gid_t oldgid = getgid();
setuid(0);
setgid(0);
int result = execv(argv[1], &argv[1]);
setuid(olduid);
setgid(oldgid);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment