-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfcfuzz.h
105 lines (92 loc) · 2.67 KB
/
rfcfuzz.h
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hidp.h>
#include <bluetooth/rfcomm.h>
#include <asm/byteorder.h>
#define MAXSIZE 4096
#define IT 512
#define LENGTH 20
#define BUFCODE 100
void rfcfuzz(char *bdstr_addr, int maxsize, int maxcrash)
{
char *buf, *savedbuf;
struct sockaddr_rc addr;
//struct hidp_conndel_req addr;
int sock, i, size;
int crash_count=0, savedsize;
if ((sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
perror("socket");
exit(EXIT_FAILURE);
}
memset(&addr, 0, sizeof(addr));
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 6;
if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("bind");
exit(EXIT_FAILURE);
}
str2ba(bdstr_addr, &addr.rc_bdaddr);
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("connect");
exit(EXIT_FAILURE);
}
if(!(savedbuf = (char *) malloc ((int) maxsize + 1))) {
perror("malloc");
exit(EXIT_FAILURE);
}
while(1) // Initite loop (ctrl-c to stop...)
{
size=rand() % maxsize;
if(size == 0)
size=1;
if(!(buf = (char *) malloc ((int) size + 1))) {
perror("malloc");
exit(EXIT_FAILURE);
}
bzero(buf, size);
for(i=0 ; i<size ; i++)
buf[i] = (char) rand();
putchar('.');
fflush(stdout);
if(send(sock, buf, size, 0) <= 0)
{
crash_count++;
fprintf(stdout, "\n%s BT stack may have crashed. This device seems to be vulnerable to buggy packets.\n", bdstr_addr);
fprintf(stdout, "Please, ensure that the device has really crashed doing a bt scan for instance.\n");
fprintf(stdout, "\t----------------------------------------------------\n");
fprintf(stdout, "\tHost\t\t%s\n", bdstr_addr);
fprintf(stdout, "\tPacket size\t%d\n", savedsize);
fprintf(stdout, "\t----------------------------------------------------\n");
fprintf(stdout, "\tPacket dump\n\t");
for(i=0 ; i<savedsize ; i++)
{
fprintf(stdout, "0x%.2X ", (unsigned char) savedbuf[i]);
if( (i%30) == 29)
fprintf(stdout, "\n\t");
}
fprintf(stdout, "\n\t----------------------------------------------------\n");
fprintf(stdout, "char replay_buggy_packet[]=\"");
for(i=0 ; i<savedsize ; i++)
{
fprintf(stdout, "\\x%.2X", (unsigned char) savedbuf[i]);
}
fprintf(stdout, "\";\n");
if((crash_count == maxcrash) && (maxcrash != 0) && (maxcrash >= 0))
{
free(buf);
free(savedbuf);
exit(EXIT_SUCCESS);
}
}
memcpy(savedbuf, buf, size); // Get the previous packet, not this one...
savedsize = size;
free(buf);
}
}