-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathxnufuzz.c
executable file
·212 lines (191 loc) · 4.51 KB
/
xnufuzz.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
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Use this program at your own risk. It will cause data loss and crashes.
*/
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>
#include <sched.h>
/*
* This ignore list is customized for xnu-1486.2.11 (10.6.2).
*/
int ignore[] = {
8, /* old creat */
11, /* old execv */
17, /* old break */
19, /* old lseek */
21, /* old mount */
22, /* old umount */
38, /* old stat */
40, /* old lstat */
45, /* old ktrace */
62, /* old fstat */
63, /* used internally , reserved */
64, /* old getpagesize */
67, /* old vread */
68, /* old vwrite */
69, /* old sbrk */
70, /* old sstk */
71, /* old mmap */
72, /* old vadvise */
77, /* old vlimit */
84, /* old wait */
87, /* old gethostname */
88, /* old sethostname */
91, /* old getdopt */
94, /* old setdopt */
99, /* old accept */
101, /* old send */
102, /* old recv */
103, /* old sigreturn */
107, /* old vtimes */
108, /* old sigvec */
109, /* old sigblock */
110, /* old sigsetmask */
112, /* old sigstack */
113, /* old recvmsg */
114, /* old sendmsg */
115, /* old vtrace */
119, /* old resuba */
125, /* old recvfrom */
129, /* old truncate */
130, /* old ftruncate */
141, /* old getpeername */
143, /* old sethostid */
144, /* old getrlimit */
145, /* old setrlimit */
146, /* old killpg */
148, /* old setquota */
149, /* old qquota */
150, /* old getsockname */
156, /* old getdirentries */
160, /* old async_daemon */
162, /* old getdomainname */
163, /* old setdomainname */
164, /* */
166, /* old exportfs */
168, /* old ustat */
170, /* old table */
171, /* old wait3 */
172, /* old rpause */
174, /* old getdents */
175, /* old gc_control */
177, /* */
178, /* */
179, /* */
186, /* */
193, /* */
198, /* __syscall */
213, /* Reserved for AppleTalk */
214, /* */
215, /* */
224, /* old checkuseraccess / fsgetpath ( which moved to 427 ) */
246, /* */
249, /* */
257, /* */
312, /* old __pthread_cond_timedwait */
321, /* old __pthread_cond_wait */
323, /* */
326, /* */
335, /* old utrace */
352, /* */
373, /* */
374, /* */
375, /* */
376, /* */
377, /* */
378, /* */
379
};
int getseed(void) {
int fd = open("/dev/urandom", O_RDONLY);
int r;
if (fd < 0) {
perror("open");
exit(0);
}
read(fd, &r, sizeof(r));
close(fd);
return(r);
}
void getrand(char *p) {
int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) {
perror("open");
exit(0);
}
read(fd, p, 128);
close(fd);
return;
}
unsigned long getnumber(void) {
int state;
state = rand() % 5;
switch(state) {
case 0:
return rand();
break;
case 1:
return( 0xffffff00 | (rand() % 256));
case 2:
return 0x8000;
case 3:
return 0xffff;
case 4:
return 0x80000000;
}
}
unsigned long getarg(void) {
int state = rand() % 5;
static char b[128];
switch(state) {
/* userland addr */
case 0:
return 0x0804fd00;
break;
/* unmapped addr */
case 1: return 0x0000a000;
break;
/* kernel addr, this is a guess ... should actually get a real one ... */
case 2: return 0xc01fa0b6;
break;
/* some number */
case 3: return getnumber();
break;
case 4: getrand(b);
return &b;
break;
}
}
int mem_fuzz() {
unsigned long arg[8];
long *p;
int i, syscallnr, flag;
srand(getseed());
while(1) {
do {
flag = 0;
syscallnr = (rand() % 253);
for (i = 0; i < (sizeof(ignore) / sizeof(ignore[0])); i++) {
if (ignore[i] == syscallnr ) {
flag = 1;
break;
}
}
} while (flag);
p = arg;
for (i = 0; i < 8; i++) {
*p++ = getarg();
}
printf("syscall(%d, %p, %p, %p, %p, %p, %p, %p, %p);\n",
syscallnr, arg[0], arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]);
fflush(stdout);
usleep(5);
syscall(syscallnr, arg[0], arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]);
}
}
int main(void) {
mem_fuzz();
}
/* EOF */