Skip to content

Instantly share code, notes, and snippets.

@vi
Created July 25, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi/f977cc3097d47b07c3ad to your computer and use it in GitHub Desktop.
Save vi/f977cc3097d47b07c3ad to your computer and use it in GitHub Desktop.
Do prctl(PR_SET_NO_NEW_PRIVS) and exec
// Pre-built static i386 version: http://vi-server.org/pub/no_new_privs
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/prctl.h>
int main(int argc, char* argv[])
{
if (argc == 1 || !strcmp(argv[1], "--help")) {
printf("Usage: no_new_privs program arguments...\n");
printf(" It disables filesystem-based privilege elevation for started programs.\n");
printf(" ping, passwd, su, sudo and others will not work\n");
return 1;
}
#ifndef PR_SET_NO_NEW_PRIVS
#define PR_SET_NO_NEW_PRIVS 38
#endif
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) {
perror("prctl(PR_SET_NO_NEW_PRIVS)");
return 2;
}
execvp(argv[1], argv+1);
perror("execvp");
return 127;
}
@scott1980
Copy link

20161125_135848_HDR

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