Skip to content

Instantly share code, notes, and snippets.

@williamspatrick
Created September 21, 2015 16:10
Show Gist options
  • Save williamspatrick/68e2ac08fcff24ff0c3f to your computer and use it in GitHub Desktop.
Save williamspatrick/68e2ac08fcff24ff0c3f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
main( int argc, char ** argv, char ** envp )
{
if( argc <= 1 ) {
errno = EINVAL;
perror( "insufficient arguments" );
return errno;
}
if( 0 != geteuid()) {
errno = EPERM;
perror( "not setuid" );
}
if( setgid(0) ) perror( "setgid" );
if( setuid(0) ) perror( "setuid" );
execvpe( argv[1], &argv[1], envp );
perror( argv[0] );
return errno;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment