From ffe14e3f53e3f9fd2d21b51c14cc6db40cdae622 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 24 Nov 2021 23:22:09 +0100 Subject: [PATCH] Added hexConverter helper-module --- src/dto/Packet.js | 14 ++++++++++++++ src/helper/hexConverter.js | 24 ++++++++++++++++++++++++ src/streamHandler/PacketStreamFactory.js | 3 ++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/helper/hexConverter.js diff --git a/src/dto/Packet.js b/src/dto/Packet.js index 699dbe0..4d1723f 100644 --- a/src/dto/Packet.js +++ b/src/dto/Packet.js @@ -13,6 +13,7 @@ const PacketType = { AssociationRequest: 'AssociationRequest', AssociationResponse: 'AssociationResponse', Disassociation: 'Disassociation', + Handshake: 'Handshake', Unknown: 'Unknown' } @@ -65,6 +66,17 @@ class DisassociationPacket extends Packet{ disassociationReason; } + +const HandshakeStage = { + 1: '1', + 2: '2', + 3: '3', + 4: '4' +} +class HandshakePacket extends Packet{ + handshakeStage; +} + // Specify exports module.exports = { PacketType, @@ -77,4 +89,6 @@ module.exports = { AuthenticationPacket, AssociationRequestPacket, AssociationResponsePacket, + HandshakeStage, + HandshakePacket, }; diff --git a/src/helper/hexConverter.js b/src/helper/hexConverter.js new file mode 100644 index 0000000..00c2e8c --- /dev/null +++ b/src/helper/hexConverter.js @@ -0,0 +1,24 @@ +// From https://stackoverflow.com/a/34356351 + +// Convert a hex string to a byte array +function hexToBytes(hex) { + for (var bytes = [], c = 0; c < hex.length; c += 2) + bytes.push(parseInt(hex.substr(c, 2), 16)); + return bytes; +} + +// Convert a byte array to a hex string +function bytesToHex(bytes) { + for (var hex = [], i = 0; i < bytes.length; i++) { + var current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i]; + hex.push((current >>> 4).toString(16)); + hex.push((current & 0xF).toString(16)); + } + return hex.join(""); +} + +// Specify exports +module.exports = { + hexToBytes, + bytesToHex +} \ No newline at end of file diff --git a/src/streamHandler/PacketStreamFactory.js b/src/streamHandler/PacketStreamFactory.js index c99a525..0a5b980 100644 --- a/src/streamHandler/PacketStreamFactory.js +++ b/src/streamHandler/PacketStreamFactory.js @@ -1,7 +1,7 @@ const logger = require.main.require("./helper/logger.js")("PacketStreamFactory"); const { Transform } = require('stream'); const { DateTime } = require("luxon"); -const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket } = require.main.require('./dto/Packet.js'); +const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket, HandshakePacket, HandshakeStage } = require.main.require('./dto/Packet.js'); const PACKET_TYPE_MAP = { "Beacon": PacketType.Beacon, @@ -17,6 +17,7 @@ const PACKET_TYPE_MAP = { "Assoc Request": PacketType.AssociationRequest, "Assoc Response": PacketType.AssociationResponse, "Disassociation:": PacketType.Disassociation, + "EAPOL": PacketType.Handshake, }; const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|');