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
|
#include <fcntl.h>
#include <libwifi.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <pcap/pcap.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "beacon_data.h"
int get_interface_mac_address(int sock, const char *interface, unsigned char *output)
{
struct ifreq ifr = {0};
strcpy(ifr.ifr_name, interface);
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
{
return -1;
}
memcpy(output, ifr.ifr_hwaddr.sa_data, 6);
return 0;
}
int main(int argc, char **argv)
{
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1)
{
printf("Could not open socket.\n");
return 1;
}
unsigned char tx_addr[6];
if (get_interface_mac_address(sock, "wlo1", tx_addr))
{
printf("Could not get hardware address.\n");
return 2;
}
static unsigned char bcast[] = "\xFF\xFF\xFF\xFF\xFF\xFF";
struct libwifi_beacon beacon = {0};
if (libwifi_create_beacon(&beacon, bcast, tx_addr, tx_addr, "ballze", 7))
{
printf("Could not create beacon frame.\n");
return 3;
}
libwifi_remove_tag(&beacon.tags, TAG_SSID);
unsigned char payload_data[BEACON_PAYLOAD_LENGTH + 8];
payload_data[0] = 0x00;
payload_data[1] = 0x09;
payload_data[2] = 0xBF;
payload_data[3] = 0x00;
payload_data[4] = 0xFF;
payload_data[5] = 0xFF;
payload_data[6] = 0x00;
payload_data[7] = 0x00;
memcpy(payload_data + 8, kBeaconPayloads[0], BEACON_PAYLOAD_LENGTH);
if (libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, payload_data, BEACON_PAYLOAD_LENGTH + 8))
{
printf("Could not add beacon data tag.\n");
return 6;
}
size_t beacon_size = libwifi_get_beacon_length(&beacon);
unsigned char *beacon_output = (unsigned char *)malloc(beacon_size);
if (beacon_output == NULL)
{
printf("Could not allocate beacon output.\n");
return 4;
}
if (libwifi_dump_beacon(&beacon, beacon_output, beacon_size) < 0)
{
printf("Could not dump beacon.\n");
return 5;
}
libwifi_free_beacon(&beacon);
int fd = open("output.dat", O_WRONLY | O_CREAT, 00600);
static unsigned char radiotap[] = "\x00\x00\x08\x00\x00\x00\x00\x00";
write(fd, radiotap, 8);
write(fd, beacon_output, beacon_size);
close(fd);
free(beacon_output);
return 0;
}
|