Skip to content

Instantly share code, notes, and snippets.

@jblyberg
Created October 16, 2012 14:29
Show Gist options
  • 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;
}
@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