From f8c2c11a4513aeda91aad9a7d199a2b0b1042111 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 27 Jun 2025 00:05:27 -0400 Subject: Format beacon frames --- src/main.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..aad5545 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} -- cgit 1.4.1