|
|
@ -1,7 +1,7 @@
|
|
|
|
const logger = require.main.require("./helper/logger.js")("PacketStreamFactory");
|
|
|
|
const logger = require.main.require("./helper/logger.js")("PacketStreamFactory");
|
|
|
|
const { Transform } = require('stream');
|
|
|
|
const { Transform } = require('stream');
|
|
|
|
const { DateTime } = require("luxon");
|
|
|
|
const { DateTime } = require("luxon");
|
|
|
|
const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType } = require.main.require('./dto/Packet.js');
|
|
|
|
const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket } = require.main.require('./dto/Packet.js');
|
|
|
|
|
|
|
|
|
|
|
|
const PACKET_TYPE_MAP = {
|
|
|
|
const PACKET_TYPE_MAP = {
|
|
|
|
"Beacon": PacketType.Beacon,
|
|
|
|
"Beacon": PacketType.Beacon,
|
|
|
@ -14,6 +14,8 @@ const PACKET_TYPE_MAP = {
|
|
|
|
"Acknowledgment": PacketType.Acknowledgment,
|
|
|
|
"Acknowledgment": PacketType.Acknowledgment,
|
|
|
|
"BA": PacketType.BlockAcknowledgment,
|
|
|
|
"BA": PacketType.BlockAcknowledgment,
|
|
|
|
"Authentication": PacketType.Authentication,
|
|
|
|
"Authentication": PacketType.Authentication,
|
|
|
|
|
|
|
|
"Assoc Request": PacketType.AssociationRequest,
|
|
|
|
|
|
|
|
"Assoc Response": PacketType.AssociationResponse,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|');
|
|
|
|
const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|');
|
|
|
|
|
|
|
|
|
|
|
@ -76,6 +78,7 @@ class PacketStreamFactory extends Transform{
|
|
|
|
case PacketType.Beacon:
|
|
|
|
case PacketType.Beacon:
|
|
|
|
case PacketType.ProbeRequest:
|
|
|
|
case PacketType.ProbeRequest:
|
|
|
|
case PacketType.ProbeResponse:
|
|
|
|
case PacketType.ProbeResponse:
|
|
|
|
|
|
|
|
case PacketType.AssociationRequest:
|
|
|
|
newPacket = new PacketWithSSID();
|
|
|
|
newPacket = new PacketWithSSID();
|
|
|
|
newPacket.ssid = data.match(new RegExp(`(^| )${packetTypeStr} `+'\\'+`((.{0,32})`+'\\'+`)($| )`, 'i'))?.[2] ?? null;
|
|
|
|
newPacket.ssid = data.match(new RegExp(`(^| )${packetTypeStr} `+'\\'+`((.{0,32})`+'\\'+`)($| )`, 'i'))?.[2] ?? null;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -84,6 +87,11 @@ class PacketStreamFactory extends Transform{
|
|
|
|
newPacket = new AuthenticationPacket();
|
|
|
|
newPacket = new AuthenticationPacket();
|
|
|
|
newPacket.authenticationType = AUTHENTICATION_TYPE_MAP[data.match(/(?<=(^|\s)Authentication\s).{3,}(?=\:(\s|$))/i)[0]] ?? AuthenticationType.Unknown;
|
|
|
|
newPacket.authenticationType = AUTHENTICATION_TYPE_MAP[data.match(/(?<=(^|\s)Authentication\s).{3,}(?=\:(\s|$))/i)[0]] ?? AuthenticationType.Unknown;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PacketType.AssociationResponse:
|
|
|
|
|
|
|
|
newPacket = new AssociationResponsePacket();
|
|
|
|
|
|
|
|
newPacket.associationIsSuccessful = data.match(/Assoc Response\s.{0,30}Successful(?=\s|$)/img) ? true : false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(newPacket) packet = Object.assign(new newPacket, packet); // Use new, more specific, packet and copy old data over
|
|
|
|
if(newPacket) packet = Object.assign(new newPacket, packet); // Use new, more specific, packet and copy old data over
|
|
|
|
}
|
|
|
|
}
|
|
|
|