Skip to content

Instantly share code, notes, and snippets.

@z4yx
Created Oct 13, 2014
Embed
What would you like to do?
fix LD_LIBRARY_PATH and set user id
#include <sys/types.h>
#include <sys/types.h>
#include <pwd.h>
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv_src)
{
char exe[PATH_MAX+10];
char *argv[256] = {0};
readlink("/proc/self/exe",exe,PATH_MAX);
strcat(exe, "_p");
memcpy(argv, argv_src, argc*sizeof(char*));
//char *argv[]={"./gogs","web",NULL};
//char *envp[]={"USER=git","PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin","HOME=/home/git","LD_LIBRARY_PATH=/usr/local/glibc2_14/lib/",NULL};
struct passwd *pwd = getpwnam("git");
if(getuid()==0 && pwd){
// fprintf(stderr,"uid: %d, gid: %d", pwd->pw_uid, pwd->pw_gid);
setgid(pwd->pw_gid);
setuid(pwd->pw_uid);
}
putenv("USER=git");
putenv("HOME=/home/git");
putenv("LD_LIBRARY_PATH=/usr/local/glibc2_14/lib/");
extern char **environ;
execve(exe,argv,environ);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment