Created
November 5, 2012 19:22
-
-
Save vanhoefm/4019750 to your computer and use it in GitHub Desktop.
Bash drop priviliges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
running_setuid = uidget(); | |
... | |
if (running_setuid && privileged_mode == 0) | |
disable_priv_mode(); | |
... | |
// start interactive shell or execute command | |
} | |
/* Fetch uids and gids, return 1 if we're running setuid or setgid. */ | |
static int uidget() | |
{ | |
... | |
current_user.uid = getuid(); | |
current_user.gid = getgid(); | |
current_user.euid = geteuid(); | |
current_user.egid = getegid(); | |
/* See whether or not we are running setuid or setgid. */ | |
return (current_user.uid != current_user.euid) || | |
(current_user.gid != current_user.egid); | |
} | |
void disable_priv_mode() | |
{ | |
setuid (current_user.uid); | |
setgid (current_user.gid); | |
current_user.euid = current_user.uid; | |
current_user.egid = current_user.gid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment