about summary refs log tree commit diff stats
path: root/tools/validator/validator.h
blob: 33bc7c9c88d4945f1e4f539d6cb6ca7876e81c99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef TOOLS_VALIDATOR_VALIDATOR_H
#define TOOLS_VALIDATOR_VALIDATOR_H

namespace com::fourisland::lingo2_archipelago {

struct CollectedInfo;

void ValidateCollectedInfo(const CollectedInfo& info);

}  // namespace com::fourisland::lingo2_archipelago

#endif /* TOOLS_VALIDATOR_VALIDATOR_H */
Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <libwifi.h>

#include <pcap.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int has_radiotap = 0;

void handle_pkt(unsigned char *args, const struct pcap_pkthdr *header, const unsigned char *packet) {
    unsigned long data_len = header->caplen;
    unsigned char *data = (unsigned char *) packet;

    // Initialise a libwifi_frame struct and populate it
    struct libwifi_frame frame = {0};
    int ret = libwifi_get_wifi_frame(&frame, data, data_len, has_radiotap);
    if (ret != 0) {
        return;
    }

    // Ensure the parsed frame is a data frame
    if (frame.frame_control.type == TYPE_DATA) {
        // Ensure the parsed data frame is a WPA handshake
        if (libwifi_check_wpa_handshake(&frame) > 0) {
            // Use libwifi to get the EAPOL message part, and also pretty-print it
            int part = libwifi_check_wpa_message(&frame);
            printf("WPA Handshake Message: %d (%s)\n", part, libwifi_get_wpa_message_string(&frame));

            // Initlaise a WPA Authentication Data struct and populate it
            struct libwifi_wpa_auth_data data = {0};
            libwifi_get_wpa_data(&frame, &data);

            // Print all of the available WPA Auth data
            printf("EAPOL: Version: %d\n", data.version);
            printf("EAPOL: Type: %d\n", data.type);
            printf("EAPOL: Length: %d\n", data.length);
            printf("EAPOL: Descriptor: %d\n", data.descriptor);
            printf("EAPOL: Key Info: Information: 0x%04x\n", data.key_info.information);
            printf("EAPOL: Key Info: Key Length: %d\n", data.key_info.key_length);
            printf("EAPOL: Key Info: Replay Counter: %lu\n", data.key_info.replay_counter);
            printf("EAPOL: Key Info: Nonce: ");
            for (size_t i = 0; i < sizeof(data.key_info.nonce); ++i) {
                printf("%02x ", data.key_info.nonce[i]);
            }
            printf("\n");

            printf("EAPOL: Key Info: IV: ");
            for (size_t i = 0; i < sizeof(data.key_info.iv); ++i) {
                printf("%02x ", data.key_info.iv[i]);
            }
            printf("\n");

            printf("EAPOL: Key Info: RSC: ");
            for (size_t i = 0; i < sizeof(data.key_info.rsc); ++i) {
                printf("%02x ", data.key_info.rsc[i]);
            }
            printf("\n");

            printf("EAPOL: Key Info: ID: ");
            for (size_t i = 0; i < sizeof(data.key_info.id); ++i) {
                printf("%02x ", data.key_info.id[i]);
            }
            printf("\n");

            printf("EAPOL: Key Info: MIC: ");
            for (size_t i = 0; i < sizeof(data.key_info.mic); ++i) {
                printf("%02x ", data.key_info.mic[i]);
            }
            printf("\n");

            printf("EAPOL: Key Info: Key Data Length: %d\n", data.key_info.key_data_length);
            if (data.key_info.key_data_length) {
                printf("EAPOL: Key Info: Key Data: ");
                for (size_t i = 0; i < data.key_info.key_data_length; ++i) {
                    printf("%02x ", data.key_info.key_data[i]);
                }
                printf("\n");
            }

            // Cleanup the WPA Data
            libwifi_free_wpa_data(&data);

            printf("\n");
        }
    }

    // Clean up the libwifi frame
    libwifi_free_wifi_frame(&frame);
}

void helpexit() {
    fprintf(stderr, "[!] Usage: ./parse_eapol --file <file.pcap>\n");
    exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {
    pcap_t *handle = NULL;
    pcap_dumper_t *dumper = NULL;
    char errbuf[PCAP_ERRBUF_SIZE];

    if (argc < 2) {
        helpexit();
    }
    if (strcmp(argv[1], "--file") == 0) {
        if ((handle = pcap_open_offline(argv[2], errbuf)) == NULL) {
            fprintf(stderr, "[!] Error opening file %s (%s)\n", argv[2], errbuf);
            exit(EXIT_FAILURE);
        }
    } else {
        helpexit();
    }

    int linktype = pcap_datalink(handle);
    if (linktype == DLT_IEEE802_11_RADIO) {
        has_radiotap = 1;
    }
    if (linktype != DLT_IEEE802_11 && linktype != DLT_IEEE802_11_RADIO) {
        fprintf(stderr, "[!] 802.11 and radiotap headers not provided (%d)\n", pcap_datalink(handle));
        pcap_close(handle);
        exit(EXIT_FAILURE);
    }

    printf("[+] Setup Complete\n");

    dumper = pcap_dump_open(handle, "/tmp/parse_eapol.pcap");
    pcap_loop(handle, -1 /*INFINITY*/, &handle_pkt, (unsigned char *) dumper);

    pcap_dump_close(dumper);
    pcap_close(handle);

    return 0;
}