From 50b134f33b7c18a72eafd379f0bd3bc542069aa8 Mon Sep 17 00:00:00 2001 From: Daplie Date: Wed, 15 Mar 2017 17:55:59 -0600 Subject: [PATCH] SOA record can be parsed if there are no compression pointers present in the rdata --- parser/type.soa.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/parser/type.soa.js b/parser/type.soa.js index 6550f8f..175047b 100644 --- a/parser/type.soa.js +++ b/parser/type.soa.js @@ -20,35 +20,49 @@ exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) { var dv = new DataView(rdataAb); var cpcount = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).cpcount; var offset = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).byteLength; - - + var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).labels; + console.log("offset is: " + offset); + console.log("cpcount is: " + cpcount); + console.log("the labels are : " + labels); + console.log("rdstart is: " + record.rdstart); for(var i = 0; i < dv.byteLength;i++){ console.log(parseInt(dv.getUint8(i), 10).toString(16)); } // Primary NS - //record.name_server = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; + record.name_server = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; // var offset = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).byteLength; // Admin MB. This email address is always preceeded by 6 Bytes of the name_server data and email_addr length. // ie: ns1.example.com, where ns1 is 3 bytes, example.com represented by 2 bytes (c0 0c - compression pointer) and then // 1 more byte representing the email_addr length. // TODO: email_addr probably shouldn't be parsed this way. The email_addr length byte is probably there to parse this in a more robust way // we just have to figure that out - - //record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart+offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; - + + if (cpcount > 0){ + // do something awesome with compression pointers to get the email address + + console.log("name server length is: " + record.name_server.length); + var email_len = parseInt(dv.getUint8(0), 10) + ;dv.getUint16(0) + console.log("email_start is: " + email_len); + record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart , { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; + + } + else { + + record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; + } // Serial Number - record.sn = dv.getUint32(dv.byteLength - 20); + record.sn = dv.getUint32(dv.byteLength - 20, false); // Refresh Interval - record.ref = dv.getUint32(dv.byteLength - 16); + record.ref = dv.getUint32(dv.byteLength - 16, false); // Retry Interval - record.ret = dv.getUint32(dv.byteLength - 12); + record.ret = dv.getUint32(dv.byteLength - 12, false); // Expiration Limit - record.ex = dv.getUint32(dv.byteLength - 8); + record.ex = dv.getUint32(dv.byteLength - 8, false); // Minimum TTL - record.nx = dv.getUint32(dv.byteLength - 4); + record.nx = dv.getUint32(dv.byteLength - 4, false); return record;