Skip to content

Commit

Permalink
DNS-SD, test and debug
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 7, 2024
1 parent dc204c0 commit 6ee1769
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 306 deletions.
30 changes: 23 additions & 7 deletions Protest/Front/dns-sd.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class DnsSD extends Console {
option.textContent = transportOptions[i];
transportMethodInput.appendChild(option);
}
transportMethodInput.value = this.args.transport;
transportMethodInput.value = "UDP";

const Apply = ()=> {
this.args.type = recordTypeInput.value;
Expand Down Expand Up @@ -305,6 +305,11 @@ class DnsSD extends Console {
result.className = "tool-result collapsed";
result.textContent = "";

const status = document.createElement("div");
status.className = "tool-status";
status.textContent = "";
element.appendChild(status);

const remove = document.createElement("div");
remove.className = "tool-remove";

Expand All @@ -313,6 +318,7 @@ class DnsSD extends Console {
this.hashtable[entryKey] = {
element: element,
result: result,
status: status,
expand: false,
list: []
};
Expand All @@ -337,7 +343,7 @@ class DnsSD extends Console {

this.args.entries.push(entryKey);

try {
/*try*/ {
let url = `tools/dnssdlookup?query=${encodeURIComponent(query)}&type=${type ?? this.args.type}&timeout=${this.args.timeout}`;
if (this.args.isStandard) url += "&standard=true";
if (this.args.isInverse) url += "&inverse=true";
Expand All @@ -362,7 +368,16 @@ class DnsSD extends Console {
hexBox.style.backgroundImage = "url(mono/hexviewer.svg?light)";
hexBox.style.cursor = "pointer";
element.appendChild(hexBox);
hexBox.onclick = ()=> new HexViewer({exchange:[{direction:"query", data:json.req},{direction:"response", data:json.res}], protocol:"dns"});

hexBox.onclick = ()=>{
new HexViewer({
protocol:"mdns",
exchange:[
{direction:"query", data:json.req},
{direction:"response", data:json.res}
]
});
};
}

if (json.error) {
Expand All @@ -388,12 +403,13 @@ class DnsSD extends Console {
name.textContent = json.replace;
}

status.style.visibility = "hidden";

for (let i = 0; i < json.answer.length; i++) {

const box = document.createElement("div");
result.appendChild(box);

console.log(json);

const label = document.createElement("div");
label.textContent = json.answer[i].type;
label.style.display = "inline-block";
Expand All @@ -415,9 +431,9 @@ console.log(json);
box.append(label, string);
}
}
catch (ex) {
/*catch (ex) {
console.error(ex);
}
}*/
}

Remove(domain) {
Expand Down
168 changes: 155 additions & 13 deletions Protest/Front/hexviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,19 @@ class HexViewer extends Window {
this.asciiBox.textContent = "";
this.list.textContent = "";

for (let i = 0; i < exchange.length; i++) {
const PlotPacket = (direction, data)=> {
const hexSeparator = document.createElement("div");
hexSeparator.textContent = exchange[i].direction;
hexSeparator.textContent = direction;
hexSeparator.className = "hexviewer-separator";
this.hexBox.appendChild(hexSeparator);

const asciiSeparator = document.createElement("div");
asciiSeparator.textContent = exchange[i].direction;
asciiSeparator.textContent = direction;
asciiSeparator.className = "hexviewer-separator";
this.asciiBox.appendChild(asciiSeparator);

const listSeparator = document.createElement("div");
listSeparator.textContent = exchange[i].direction;
listSeparator.textContent = direction;
listSeparator.className = "hexviewer-separator";
this.list.appendChild(listSeparator);

Expand All @@ -301,19 +301,19 @@ class HexViewer extends Window {
const charContainer = document.createElement("div");
this.asciiBox.appendChild(charContainer);

for (let j = 0; j < exchange[i].data.length; j++) {
for (let j=0; j<data.length; j++) {
const hex = document.createElement("div");
hex.textContent = exchange[i].data[j].toString(16).padStart(2, "0");
hex.textContent = data[j].toString(16).padStart(2, "0");
hexContainer.appendChild(hex);

const char = document.createElement("div");
charContainer.appendChild(char);

if (exchange[i].data[j] < 33) {
if (data[j] < 33) {
char.textContent = ".";
}
else {
char.textContent = String.fromCharCode(exchange[i].data[j]);
char.textContent = String.fromCharCode(data[j]);
}

hex.onmouseenter = char.onmouseenter = ()=>{
Expand All @@ -328,9 +328,23 @@ class HexViewer extends Window {
}

switch (protocol) {
case "dns" : this.PopulateDnsLabels(hexContainer, charContainer, exchange[i].data); break;
case "ntp" : this.PopulateNtpLabels(hexContainer, charContainer, exchange[i].data); break;
case "dhcp": this.PopulateDhcpLabels(hexContainer, charContainer, exchange[i].data); break;
case "dns" : this.PopulateDnsLabels(hexContainer, charContainer, data); break;
case "mdns" : this.PopulateMdnsLabels(hexContainer, charContainer, data); break;
case "ntp" : this.PopulateNtpLabels(hexContainer, charContainer, data); break;
case "dhcp" : this.PopulateDhcpLabels(hexContainer, charContainer, data); break;
}
};

for (let i=0; i<exchange.length; i++) {
if (exchange[i].data.length > 0) {
if (exchange[i].data[0] instanceof Array) {
for (let j=0; j<exchange[i].data.length; j++) {
PlotPacket(exchange[i].direction, exchange[i].data[j]);
}
}
else {
PlotPacket(exchange[i].direction, exchange[i].data);
}
}
}
}
Expand Down Expand Up @@ -391,12 +405,12 @@ class HexViewer extends Window {
let isResponse = (stream[2] & 0b10000000) > 0;
let options = (stream[2] & 0b01111000) >> 3;
let isAuthoritative = (stream[2] & 0b00000100) > 0;
let isTrancated = (stream[2] & 0b00000010) > 0;
let isTruncated = (stream[2] & 0b00000010) > 0;
let isRecursive = (stream[2] & 0b00000001) > 0;
this.PopulateLabel(`Response: ${isResponse}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Options: ${options}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Authoritative: ${isAuthoritative}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Trancated: ${isTrancated}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Truncated: ${isTruncated}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Recursive: ${isRecursive}`, 1, hexContainer, charContainer, 2, 1);

if (isResponse) {
Expand Down Expand Up @@ -537,7 +551,135 @@ class HexViewer extends Window {

count++;
}
}

PopulateMdnsLabels(hexContainer, charContainer, stream, index) {
if (!(stream[index] instanceof Array)) {
this.PopulateDnsLabels(hexContainer, charContainer, stream);
return;
}

const transactionId = stream[index][0].toString(16).padStart(2,"0") + stream[index][1].toString(16).padStart(2,"0");
this.PopulateLabel(`Transaction ID: 0x${transactionId}`, 0, hexContainer, charContainer, 0, 2);

const flags = stream[index][2].toString(16).padStart(2,"0") + stream[index][3].toString(16).padStart(2,"0");
this.PopulateLabel(`Flags: 0x${flags}`, 0, hexContainer, charContainer, 2, 2);

let isResponse = (stream[index][2] & 0b10000000) > 0;
let options = (stream[index][2] & 0b01111000) >> 3;
let isAuthoritative = (stream[index][2] & 0b00000100) > 0;
let isTruncated = (stream[index][2] & 0b00000010) > 0;
let isRecursive = (stream[index][2] & 0b00000001) > 0;
this.PopulateLabel(`Response: ${isResponse}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Options: ${options}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Authoritative: ${isAuthoritative}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Truncated: ${isTruncated}`, 1, hexContainer, charContainer, 2, 1);
this.PopulateLabel(`Recursive: ${isRecursive}`, 1, hexContainer, charContainer, 2, 1);

if (isResponse) {
let isRecursionAvailable = (stream[index][3] & 0b10000000) > 0;
let isAnswerAuthenticated = (stream[index][3] & 0b00100000) > 0;
let nonAuthenticatedData = (stream[index][3] & 0b00010000) > 0;
let replyCode = stream[index][3] & 0b00001111;
this.PopulateLabel(`Recursion is available: ${isRecursionAvailable}`, 1, hexContainer, charContainer, 3, 1);
this.PopulateLabel(`Answer is authenticated: ${isAnswerAuthenticated}`, 1, hexContainer, charContainer, 3, 1);
this.PopulateLabel(`Non authenticated data: ${nonAuthenticatedData}`, 1, hexContainer, charContainer, 3, 1);
this.PopulateLabel(`Reply code: ${replyCode}`, 1, hexContainer, charContainer, 3, 1);
}

const qCount = stream[index][4] << 8 | stream[index][5];
this.PopulateLabel(`Questions counter: ${qCount}`, 0, hexContainer, charContainer, 4, 2);

const anCount = stream[index][6] << 8 | stream[index][7];
this.PopulateLabel(`Answers counter: ${anCount}`, 0, hexContainer, charContainer, 6, 2);

const auCount = stream[index][8] << 8 | stream[index][9];
this.PopulateLabel(`Authority RRs: ${auCount}`, 0, hexContainer, charContainer, 8, 2);

const adCount = stream[index][10] << 8 | stream[index][11];
this.PopulateLabel(`Additional RRs: ${adCount}`, 0, hexContainer, charContainer, 10, 2);

let offset = 12;
let count = 0;
while (offset < stream.length && count < qCount + anCount + auCount + adCount) { //answers
let start = offset;
let end = offset;

switch (stream[offset]) {
case 0xc0: //pointer
end += 2;
break;

default:
while (end < stream.length && stream[end] !== 0) {
end++;
}
break;
}

const first = this.PopulateLabel("Name", 1, hexContainer, charContainer, start, end - start);

offset = end + 1;

let type = (stream[offset] << 8) | stream[offset+1];
this.PopulateLabel(`Type: ${type}`, 1, hexContainer, charContainer, offset, 2);
offset += 2;

let class_ = (stream[offset] << 8) | stream[offset+1];
this.PopulateLabel(`Class: ${class_}`, 1, hexContainer, charContainer, offset, 2);
offset += 2;

let ttl = (stream[offset] << 24) | (stream[offset+1] << 16) | (stream[offset+2] << 8) | stream[offset+3];
this.PopulateLabel(`TTL: ${ttl}`, 1, hexContainer, charContainer, offset, 4);
offset += 4;

let len = (stream[offset] << 8) | stream[offset+1];
this.PopulateLabel(`Length: ${len}`, 1, hexContainer, charContainer, offset, 2);
offset += 2;

let data;
switch (type) {
case 1: //A
if (len === 4) {
data = `${stream[offset]}.${stream[offset+1]}.${stream[offset+2]}.${stream[offset+3]}`;
this.PopulateLabel(data, 1, hexContainer, charContainer, offset, len);
}
break;

case 28: //AAAA
if (len === 16) {
data = "";
for (let j = 0; j < 16; j+=2) {
if (j > 0) data += ":";
data += stream[offset + j].toString(16).padStart(2, "0");
data += stream[offset + j + 1].toString(16).padStart(2, "0");
}
this.PopulateLabel(data, 1, hexContainer, charContainer, offset, len);
}
break;

default:
this.PopulateLabel("Answer", 1, hexContainer, charContainer, offset, len);
break;
}
offset += len;

end = offset;

let element;
if (count < qCount + anCount) {
element = this.PopulateLabel("Answer: ", 0, hexContainer, charContainer, start, end - start);
}
else if (count < qCount + anCount + auCount) {
element = this.PopulateLabel("Authority: ", 0, hexContainer, charContainer, start, end - start);
}
else if (count < qCount + anCount + auCount + adCount) {
element = this.PopulateLabel("Additional: ", 0, hexContainer, charContainer, start, end - start);
}
this.list.insertBefore(element, first);

count++;
}
}

PopulateNtpLabels(hexContainer, charContainer, stream) {
Expand Down
3 changes: 2 additions & 1 deletion Protest/Front/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const LOADER = {
"ip phone" : "mono/ipphone.svg",
"lamp" : "mono/lamp.svg",
"laptop" : "mono/laptop.svg",
"nas" : "mono/server.svg",
"nas" : "mono/nas.svg",
"nvr" : "mono/nvr.svg",
"media player" : "mono/mediaplayer.svg",
"music player" : "mono/mediaplayer.svg",
"multiprinter" : "mono/multiprinter.svg",
Expand Down
3 changes: 3 additions & 0 deletions Protest/Front/mono/nas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6ee1769

Please sign in to comment.