Skip to content

Instantly share code, notes, and snippets.

@qutorial
Forked from jblyberg/suid-wrapper.c
Created February 6, 2018 13:13
Show Gist options
  • Save qutorial/77cc0a28e4edf19b846e419ee65ed204 to your computer and use it in GitHub Desktop.
Save qutorial/77cc0a28e4edf19b846e419ee65ed204 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment