|
|
@ -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, FlagType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket, HandshakePacket, HandshakeStage } = require.main.require('./dto/Packet.js');
|
|
|
|
const { PacketType, FlagType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket, HandshakePacket, HandshakeStage } = require.main.require("./dto/Packet.js");
|
|
|
|
const hexConv = require.main.require("./helper/hexConverter.js");
|
|
|
|
const hexConv = require.main.require("./helper/hexConverter.js");
|
|
|
|
const wifiStateAnalyser = require.main.require("./helper/wifiStateAnalyzer.js");
|
|
|
|
const wifiStateAnalyser = require.main.require("./helper/wifiStateAnalyzer.js");
|
|
|
|
|
|
|
|
|
|
|
@ -20,20 +20,20 @@ const PACKET_TYPE_MAP = {
|
|
|
|
"Disassociation:": PacketType.Disassociation,
|
|
|
|
"Disassociation:": PacketType.Disassociation,
|
|
|
|
"EAPOL": PacketType.Handshake,
|
|
|
|
"EAPOL": PacketType.Handshake,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|');
|
|
|
|
const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join("|");
|
|
|
|
|
|
|
|
|
|
|
|
const AUTHENTICATION_TYPE_MAP = {
|
|
|
|
const AUTHENTICATION_TYPE_MAP = {
|
|
|
|
"(Open System)-1": AuthenticationType.OpenSystem_1,
|
|
|
|
"(Open System)-1": AuthenticationType.OpenSystem_1,
|
|
|
|
"(Open System)-2": AuthenticationType.OpenSystem_2,
|
|
|
|
"(Open System)-2": AuthenticationType.OpenSystem_2,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const FLAG_TYPE_MAP = {
|
|
|
|
const FLAG_TYPE_MAP = {
|
|
|
|
"Retry": FlagType.Retry,
|
|
|
|
"Retry": FlagType.Retry,
|
|
|
|
"Pwr Mgmt": FlagType.PwrMgt,
|
|
|
|
"Pwr Mgmt": FlagType.PwrMgt,
|
|
|
|
"More Data": FlagType.MoreData,
|
|
|
|
"More Data": FlagType.MoreData,
|
|
|
|
"Protected": FlagType.Protected,
|
|
|
|
"Protected": FlagType.Protected,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const FLAG_TYPE_MAPS_REGEX = Object.keys(FLAG_TYPE_MAP).join('|');
|
|
|
|
const FLAG_TYPE_MAPS_REGEX = Object.keys(FLAG_TYPE_MAP).join("|");
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Read data from text-blocks and convert them to Packet
|
|
|
|
* Read data from text-blocks and convert them to Packet
|
|
|
@ -49,8 +49,8 @@ class PacketStreamFactory extends Transform{
|
|
|
|
_transform(chunk, encoding, next){
|
|
|
|
_transform(chunk, encoding, next){
|
|
|
|
let packet = new Packet();
|
|
|
|
let packet = new Packet();
|
|
|
|
|
|
|
|
|
|
|
|
const lines = chunk.split('\n');
|
|
|
|
const lines = chunk.split("\n");
|
|
|
|
const header = lines.splice(0, 1)[0]; // Grab first line, 'lines' is now the payload
|
|
|
|
const header = lines.splice(0, 1)[0]; // Grab first line, "lines" is now the payload
|
|
|
|
packet = this._handleHeader(packet, header);
|
|
|
|
packet = this._handleHeader(packet, header);
|
|
|
|
packet = this._handlePayload(packet, lines);
|
|
|
|
packet = this._handlePayload(packet, lines);
|
|
|
|
|
|
|
|
|
|
|
@ -62,7 +62,7 @@ class PacketStreamFactory extends Transform{
|
|
|
|
packet.timestampMicros = DateTime.fromISO(data.slice(0, 12)).toSeconds() + data.slice(12, 15)/1000000;
|
|
|
|
packet.timestampMicros = DateTime.fromISO(data.slice(0, 12)).toSeconds() + data.slice(12, 15)/1000000;
|
|
|
|
|
|
|
|
|
|
|
|
// Find flags
|
|
|
|
// Find flags
|
|
|
|
data.match(data.match(new RegExp('(?<=^|\\s)('+ FLAG_TYPE_MAPS_REGEX +')(?=$|\\s)', 'ig'))
|
|
|
|
data.match(data.match(new RegExp("(?<=^|\\s)("+ FLAG_TYPE_MAPS_REGEX +")(?=$|\\s)", "ig"))
|
|
|
|
?.forEach(match => packet.flags[FLAG_TYPE_MAP[match]] = true) // Set them to true in flags
|
|
|
|
?.forEach(match => packet.flags[FLAG_TYPE_MAP[match]] = true) // Set them to true in flags
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -73,11 +73,11 @@ class PacketStreamFactory extends Transform{
|
|
|
|
|
|
|
|
|
|
|
|
packet.signal = Number(data.match(/(?<=^|\s)-\d{2,3}(?=dBm\sSignal($|\s))/i)?.[0]) || null;
|
|
|
|
packet.signal = Number(data.match(/(?<=^|\s)-\d{2,3}(?=dBm\sSignal($|\s))/i)?.[0]) || null;
|
|
|
|
|
|
|
|
|
|
|
|
let packetTypeStr = data.match(new RegExp('(?<=^|\\s)('+ PACKET_TYPES_REGEX +')(?=$|\\s)', 'i'))?.[0];
|
|
|
|
let packetTypeStr = data.match(new RegExp("(?<=^|\\s)("+ PACKET_TYPES_REGEX +")(?=$|\\s)", "i"))?.[0];
|
|
|
|
if(packetTypeStr)
|
|
|
|
if(packetTypeStr)
|
|
|
|
packet.packetType = PACKET_TYPE_MAP[packetTypeStr];
|
|
|
|
packet.packetType = PACKET_TYPE_MAP[packetTypeStr];
|
|
|
|
else if(data.match(/(SA|TA|DA|RA|BSSID):.{17}\s*$/i)){
|
|
|
|
else if(data.match(/(SA|TA|DA|RA|BSSID):.{17}\s*$/i)){
|
|
|
|
packet.packetType = PacketType.NoData
|
|
|
|
packet.packetType = PacketType.NoData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
packet.packetType = PacketType.Unknown;
|
|
|
|
packet.packetType = PacketType.Unknown;
|
|
|
@ -97,12 +97,12 @@ class PacketStreamFactory extends Transform{
|
|
|
|
case PacketType.ProbeResponse:
|
|
|
|
case PacketType.ProbeResponse:
|
|
|
|
case PacketType.AssociationRequest:
|
|
|
|
case PacketType.AssociationRequest:
|
|
|
|
newPacket = new PacketWithSSID();
|
|
|
|
newPacket = new PacketWithSSID();
|
|
|
|
newPacket.ssid = data.match(new RegExp('(?<=(^|\\s)'+ packetTypeStr +'\\s\\().{0,32}(?=\\)($|\\s))', 'i'))?.[0] ?? null;
|
|
|
|
newPacket.ssid = data.match(new RegExp("(?<=(^|\\s)"+ packetTypeStr +"\\s\\().{0,32}(?=\\)($|\\s))", "i"))?.[0] ?? null;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PacketType.Authentication:
|
|
|
|
case PacketType.Authentication:
|
|
|
|
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:
|
|
|
|
case PacketType.AssociationResponse:
|
|
|
@ -121,16 +121,16 @@ class PacketStreamFactory extends Transform{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_handlePayload(packet, data){
|
|
|
|
_handlePayload(packet, data){
|
|
|
|
data = data.join('');
|
|
|
|
data = data.join("");
|
|
|
|
|
|
|
|
|
|
|
|
// Get payload-Hex-Data. If there is no data: empty
|
|
|
|
// Get payload-Hex-Data. If there is no data: empty
|
|
|
|
packet.payloadData = hexConv.hexToBytes(data.match(/(?<=\s)([A-F0-9]{1,4}(?=\s))/igm)?.join('') ?? '');
|
|
|
|
packet.payloadData = hexConv.hexToBytes(data.match(/(?<=\s)([A-F0-9]{1,4}(?=\s))/igm)?.join("") ?? "");
|
|
|
|
packet.payloadData.splice(packet.payloadData.length-4, 4); // Remove FrameCheck sequence
|
|
|
|
packet.payloadData.splice(packet.payloadData.length-4, 4); // Remove FrameCheck sequence
|
|
|
|
|
|
|
|
|
|
|
|
// Cover special cases with more data
|
|
|
|
// Cover special cases with more data
|
|
|
|
let newPacket;
|
|
|
|
let newPacket;
|
|
|
|
switch(packet.packetType){
|
|
|
|
switch(packet.packetType){
|
|
|
|
case PacketType.Handshake:
|
|
|
|
case PacketType.Handshake: {
|
|
|
|
newPacket = new HandshakePacket();
|
|
|
|
newPacket = new HandshakePacket();
|
|
|
|
|
|
|
|
|
|
|
|
// Read key-information
|
|
|
|
// Read key-information
|
|
|
@ -140,6 +140,7 @@ class PacketStreamFactory extends Transform{
|
|
|
|
newPacket.handshakeStage = wifiStateAnalyser.handshakeStageFromKeyInfo(keyInfo); // Get stage
|
|
|
|
newPacket.handshakeStage = wifiStateAnalyser.handshakeStageFromKeyInfo(keyInfo); // Get stage
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(newPacket) packet = Object.assign(newPacket, packet);
|
|
|
|
if(newPacket) packet = Object.assign(newPacket, packet);
|
|
|
|
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
return packet;
|
|
|
|