Skip to content

Instantly share code, notes, and snippets.

@jblyberg
Created October 16, 2012 14:29
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jblyberg/3899599 to your computer and use it in GitHub Desktop.
Save jblyberg/3899599 to your computer and use it in GitHub Desktop.
A very small C wrapper for running shell scripts suid. Pretty dangerous, but handy.
#include <unistd.h>
#include <errno.h>
main( int argc, char ** argv, char ** envp )
{
if( setgid(getegid()) ) perror( "setgid" );
if( setuid(geteuid()) ) perror( "setuid" );
envp = 0; /* blocks IFS attack on non-bash shells */
system( "/path/to/bash/script", argv, envp );
perror( argv[0] );
return errno;
}
@stychos
Copy link

stychos commented Sep 19, 2019

how do you compile this? system() accepts only single argument

@thiagorb
Copy link

thiagorb commented Aug 9, 2021

I implemented a utility to make creating executable binaries with suid flag set a bit easier: https://github.com/thiagorb/suid-wrapper

With this utility you can create new binaries without having to write or modify source code, and you also don't need to compile (and therefore no compiler needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment