mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Tidied up 'Parse UDP' operation
This commit is contained in:
parent
46fa7475cf
commit
0031345383
3 changed files with 16 additions and 23 deletions
|
@ -3,7 +3,6 @@
|
||||||
[](https://travis-ci.org/gchq/CyberChef)
|
[](https://travis-ci.org/gchq/CyberChef)
|
||||||
[](https://david-dm.org/gchq/CyberChef)
|
[](https://david-dm.org/gchq/CyberChef)
|
||||||
[](https://www.npmjs.com/package/cyberchef)
|
[](https://www.npmjs.com/package/cyberchef)
|
||||||

|
|
||||||
[](https://github.com/gchq/CyberChef/blob/master/LICENSE)
|
[](https://github.com/gchq/CyberChef/blob/master/LICENSE)
|
||||||
[](https://gitter.im/gchq/CyberChef?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
[](https://gitter.im/gchq/CyberChef?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||||
|
|
||||||
|
|
|
@ -24,37 +24,35 @@ class ParseUDP extends Operation {
|
||||||
this.module = "Default";
|
this.module = "Default";
|
||||||
this.description = "Parses a UDP header and payload (if present).";
|
this.description = "Parses a UDP header and payload (if present).";
|
||||||
this.infoURL = "https://wikipedia.org/wiki/User_Datagram_Protocol";
|
this.infoURL = "https://wikipedia.org/wiki/User_Datagram_Protocol";
|
||||||
this.inputType = "byteArray";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "json";
|
this.outputType = "json";
|
||||||
this.presentType = "html";
|
this.presentType = "html";
|
||||||
this.args = [];
|
this.args = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Uint8Array} input
|
* @param {ArrayBuffer} input
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
|
if (input.byteLength < 8) {
|
||||||
if (input.length < "8"){
|
|
||||||
throw new OperationError("Need 8 bytes for a UDP Header");
|
throw new OperationError("Need 8 bytes for a UDP Header");
|
||||||
}
|
}
|
||||||
|
|
||||||
const s = new Stream(input);
|
const s = new Stream(new Uint8Array(input));
|
||||||
//Parse Header
|
// Parse Header
|
||||||
const UDPPacket = {
|
const UDPPacket = {
|
||||||
"Source port": s.readInt(2),
|
"Source port": s.readInt(2),
|
||||||
"Destination port": s.readInt(2),
|
"Destination port": s.readInt(2),
|
||||||
"Length": s.readInt(2),
|
"Length": s.readInt(2),
|
||||||
"Checksum": toHex(s.getBytes(2), "0x")
|
"Checksum": toHex(s.getBytes(2), "")
|
||||||
};
|
};
|
||||||
//Parse data if present
|
// Parse data if present
|
||||||
if (s.hasMore()){
|
if (s.hasMore()) {
|
||||||
UDPPacket.Data = toHex(s.getBytes(UDPPacket.Length - 8), "0x");
|
UDPPacket.Data = toHex(s.getBytes(UDPPacket.Length - 8), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return UDPPacket;
|
return UDPPacket;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,22 +62,18 @@ class ParseUDP extends Operation {
|
||||||
*/
|
*/
|
||||||
present(data) {
|
present(data) {
|
||||||
const html = [];
|
const html = [];
|
||||||
html.push("<table class='table table-hover table-sm table-bordered' style='table-layout: fixed'>");
|
html.push("<table class='table table-hover table-sm table-bordered table-nonfluid' style='table-layout: fixed'>");
|
||||||
html.push("<tr>");
|
html.push("<tr>");
|
||||||
html.push("<th>Field</th>");
|
html.push("<th>Field</th>");
|
||||||
html.push("<th>Value</th>");
|
html.push("<th>Value</th>");
|
||||||
html.push("</tr>");
|
html.push("</tr>");
|
||||||
|
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
switch (key){
|
|
||||||
default: {
|
|
||||||
html.push("<tr>");
|
html.push("<tr>");
|
||||||
html.push("<td style=\"word-wrap:break-word\">" + key + "</td>");
|
html.push("<td style=\"word-wrap:break-word\">" + key + "</td>");
|
||||||
html.push("<td>" + data[key] + "</td>");
|
html.push("<td>" + data[key] + "</td>");
|
||||||
html.push("</tr>");
|
html.push("</tr>");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
html.push("</table>");
|
html.push("</table>");
|
||||||
return html.join("");
|
return html.join("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ TestRegister.addTests([
|
||||||
{
|
{
|
||||||
name: "Parse UDP: No Data - JSON",
|
name: "Parse UDP: No Data - JSON",
|
||||||
input: "04 89 00 35 00 2c 01 01",
|
input: "04 89 00 35 00 2c 01 01",
|
||||||
expectedOutput: "{\"Source port\":1161,\"Destination port\":53,\"Length\":44,\"Checksum\":\"0x010x01\"}",
|
expectedOutput: "{\"Source port\":1161,\"Destination port\":53,\"Length\":44,\"Checksum\":\"0101\"}",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "From Hex",
|
op: "From Hex",
|
||||||
|
@ -30,7 +30,7 @@ TestRegister.addTests([
|
||||||
}, {
|
}, {
|
||||||
name: "Parse UDP: With Data - JSON",
|
name: "Parse UDP: With Data - JSON",
|
||||||
input: "04 89 00 35 00 2c 01 01 02 02",
|
input: "04 89 00 35 00 2c 01 01 02 02",
|
||||||
expectedOutput: "{\"Source port\":1161,\"Destination port\":53,\"Length\":44,\"Checksum\":\"0x010x01\",\"Data\":\"0x020x02\"}",
|
expectedOutput: "{\"Source port\":1161,\"Destination port\":53,\"Length\":44,\"Checksum\":\"0101\",\"Data\":\"0202\"}",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "From Hex",
|
op: "From Hex",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue