We need to deal with the tcpdump headers as well :eyeroll:
This commit is contained in:
parent
7616ab95f3
commit
e59a0b2943
2 changed files with 34 additions and 2 deletions
35
index.js
35
index.js
|
@ -5,10 +5,17 @@ if(typeof(atob) === 'undefined') {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var encodedPacket = "1MOyoQIABAAAAAAAAAAAAAAABAABAAAAKPfFWWMZCwBRAAAAUQAAAExg3kp+6eSzGAoxpggARQAAQ66CQABAEXgXCgAAEAoAAAG90gA1AC+qDJSEAQAAAQAAAAAAAAphc3NldHMtY2RuBmdpdGh1YgNjb20AAAEAAQ=="
|
var encodedPacket = "1MOyoQIABAAAAAAAAAAAAAAABAABAAAAKPfFWWMZCwBRAAAAUQAAAExg3kp+6eSzGAoxpggARQAAQ66CQABAEXgXCgAAEAoAAAG90gA1AC+qDJSEAQAAAQAAAAAAAAphc3NldHMtY2RuBmdpdGh1YgNjb20AAAEAAQ=="
|
||||||
|
//convert to binary string to create ArrayBuffer
|
||||||
var packet = atob(encodedPacket);
|
var packet = atob(encodedPacket);
|
||||||
|
|
||||||
console.log(packet.length);
|
console.log("tcpdump length:", packet.length);
|
||||||
|
|
||||||
|
//The first 40 bytes are the tcpdump header
|
||||||
|
packet = packet.slice(40);
|
||||||
|
|
||||||
|
console.log("UDP length:", packet.length);
|
||||||
|
|
||||||
|
//We now have the raw UDP packet!
|
||||||
var buffer = new ArrayBuffer(packet.length);
|
var buffer = new ArrayBuffer(packet.length);
|
||||||
|
|
||||||
var view = new DataView(buffer)
|
var view = new DataView(buffer)
|
||||||
|
@ -18,7 +25,31 @@ if(typeof(atob) === 'undefined') {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < packet.length; ++i) {
|
for(i = 0; i < packet.length; ++i) {
|
||||||
console.log(view.getUint8(i).toString(16));
|
}
|
||||||
|
|
||||||
|
console.log("Result:", parseDNSHeader(view));
|
||||||
|
|
||||||
|
//Parse DNS Header (given the UDP payload)
|
||||||
|
function parseDNSHeader(view) {
|
||||||
|
return {
|
||||||
|
MessageID: getHId(view)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHId(view) {
|
||||||
|
return view.getUint16(0, false)
|
||||||
|
}
|
||||||
|
function getQR(view) {
|
||||||
|
|
||||||
|
}
|
||||||
|
function getOPCode(view) {
|
||||||
|
|
||||||
|
}
|
||||||
|
function getAA(view) {
|
||||||
|
|
||||||
|
}
|
||||||
|
function getTC(view) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
Loading…
Reference in a new issue