mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Merge remote-tracking branch 'upstream/master' into render-markdown
This commit is contained in:
commit
45fccb94e1
49 changed files with 834 additions and 772 deletions
|
@ -71,8 +71,8 @@ class AESDecrypt extends Operation {
|
|||
* @throws {OperationError} if cannot decrypt input or invalid key length
|
||||
*/
|
||||
run(input, args) {
|
||||
const key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||
mode = args[2],
|
||||
inputType = args[3],
|
||||
outputType = args[4],
|
||||
|
|
|
@ -64,7 +64,7 @@ class BlurImage extends Operation {
|
|||
throw new OperationError(`Error loading image. (${err})`);
|
||||
}
|
||||
try {
|
||||
switch (blurType){
|
||||
switch (blurType) {
|
||||
case "Fast":
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Fast blurring image...");
|
||||
|
|
|
@ -29,12 +29,12 @@ class ChangeIPFormat extends Operation {
|
|||
{
|
||||
"name": "Input format",
|
||||
"type": "option",
|
||||
"value": ["Dotted Decimal", "Decimal", "Hex"]
|
||||
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
|
||||
},
|
||||
{
|
||||
"name": "Output format",
|
||||
"type": "option",
|
||||
"value": ["Dotted Decimal", "Decimal", "Hex"]
|
||||
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ class ChangeIPFormat extends Operation {
|
|||
if (lines[i] === "") continue;
|
||||
let baIp = [];
|
||||
let octets;
|
||||
let decimal;
|
||||
|
||||
if (inFormat === outFormat) {
|
||||
output += lines[i] + "\n";
|
||||
|
@ -70,11 +69,10 @@ class ChangeIPFormat extends Operation {
|
|||
}
|
||||
break;
|
||||
case "Decimal":
|
||||
decimal = lines[i].toString();
|
||||
baIp.push(decimal >> 24 & 255);
|
||||
baIp.push(decimal >> 16 & 255);
|
||||
baIp.push(decimal >> 8 & 255);
|
||||
baIp.push(decimal & 255);
|
||||
baIp = this.fromNumber(lines[i].toString(), 10);
|
||||
break;
|
||||
case "Octal":
|
||||
baIp = this.fromNumber(lines[i].toString(), 8);
|
||||
break;
|
||||
case "Hex":
|
||||
baIp = fromHex(lines[i]);
|
||||
|
@ -100,6 +98,10 @@ class ChangeIPFormat extends Operation {
|
|||
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
||||
output += decIp.toString() + "\n";
|
||||
break;
|
||||
case "Octal":
|
||||
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
||||
output += "0" + decIp.toString(8) + "\n";
|
||||
break;
|
||||
case "Hex":
|
||||
hexIp = "";
|
||||
for (j = 0; j < baIp.length; j++) {
|
||||
|
@ -115,6 +117,22 @@ class ChangeIPFormat extends Operation {
|
|||
return output.slice(0, output.length-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an array of IP address octets from a numerical value.
|
||||
* @param {string} value The value of the IP address
|
||||
* @param {number} radix The numeral system to be used
|
||||
* @returns {number[]}
|
||||
*/
|
||||
fromNumber(value, radix) {
|
||||
const decimal = parseInt(value, radix);
|
||||
const baIp = [];
|
||||
baIp.push(decimal >> 24 & 255);
|
||||
baIp.push(decimal >> 16 & 255);
|
||||
baIp.push(decimal >> 8 & 255);
|
||||
baIp.push(decimal & 255);
|
||||
return baIp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ChangeIPFormat;
|
||||
|
|
|
@ -111,7 +111,7 @@ class DNSOverHTTPS extends Operation {
|
|||
* @returns {JSON}
|
||||
*/
|
||||
function extractData(data) {
|
||||
if (typeof(data) == "undefined"){
|
||||
if (typeof(data) == "undefined") {
|
||||
return [];
|
||||
} else {
|
||||
const dataValues = [];
|
||||
|
|
|
@ -20,7 +20,7 @@ class ExtractDomains extends Operation {
|
|||
|
||||
this.name = "Extract domains";
|
||||
this.module = "Regex";
|
||||
this.description = "Extracts domain names.<br>Note that this will not include paths. Use <strong>Extract URLs</strong> to find entire URLs.";
|
||||
this.description = "Extracts fully qualified domain names.<br>Note that this will not include paths. Use <strong>Extract URLs</strong> to find entire URLs.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
|
|
|
@ -58,7 +58,7 @@ class FlipImage extends Operation {
|
|||
try {
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Flipping image...");
|
||||
switch (flipAxis){
|
||||
switch (flipAxis) {
|
||||
case "Horizontal":
|
||||
image.flip(true, false);
|
||||
break;
|
||||
|
|
|
@ -47,7 +47,7 @@ class GenerateLoremIpsum extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
const [length, lengthType] = args;
|
||||
if (length < 1){
|
||||
if (length < 1) {
|
||||
throw new OperationError("Length must be greater than 0");
|
||||
}
|
||||
switch (lengthType) {
|
||||
|
|
|
@ -48,7 +48,7 @@ class ImageFilter extends Operation {
|
|||
*/
|
||||
async run(input, args) {
|
||||
const [filterType] = args;
|
||||
if (!isImage(new Uint8Array(input))){
|
||||
if (!isImage(new Uint8Array(input))) {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class MicrosoftScriptDecoder extends Operation {
|
|||
run(input, args) {
|
||||
const matcher = /#@~\^.{6}==(.+).{6}==\^#~@/;
|
||||
const encodedData = matcher.exec(input);
|
||||
if (encodedData){
|
||||
if (encodedData) {
|
||||
return MicrosoftScriptDecoder._decode(encodedData[1]);
|
||||
} else {
|
||||
return "";
|
||||
|
|
|
@ -134,7 +134,7 @@ CMYK: ${cmyk}
|
|||
static _hslToRgb(h, s, l) {
|
||||
let r, g, b;
|
||||
|
||||
if (s === 0){
|
||||
if (s === 0) {
|
||||
r = g = b = l; // achromatic
|
||||
} else {
|
||||
const hue2rgb = function hue2rgb(p, q, t) {
|
||||
|
|
84
src/core/operations/ParseUDP.mjs
Normal file
84
src/core/operations/ParseUDP.mjs
Normal file
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* @author h345983745 []
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Stream from "../lib/Stream.mjs";
|
||||
import {toHex} from "../lib/Hex.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Parse UDP operation
|
||||
*/
|
||||
class ParseUDP extends Operation {
|
||||
|
||||
/**
|
||||
* ParseUDP constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Parse UDP";
|
||||
this.module = "Default";
|
||||
this.description = "Parses a UDP header and payload (if present).";
|
||||
this.infoURL = "https://wikipedia.org/wiki/User_Datagram_Protocol";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "json";
|
||||
this.presentType = "html";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @returns {Object}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (input.byteLength < 8) {
|
||||
throw new OperationError("Need 8 bytes for a UDP Header");
|
||||
}
|
||||
|
||||
const s = new Stream(new Uint8Array(input));
|
||||
// Parse Header
|
||||
const UDPPacket = {
|
||||
"Source port": s.readInt(2),
|
||||
"Destination port": s.readInt(2),
|
||||
"Length": s.readInt(2),
|
||||
"Checksum": toHex(s.getBytes(2), "")
|
||||
};
|
||||
// Parse data if present
|
||||
if (s.hasMore()) {
|
||||
UDPPacket.Data = toHex(s.getBytes(UDPPacket.Length - 8), "");
|
||||
}
|
||||
|
||||
return UDPPacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the UDP Packet in a table style
|
||||
* @param {Object} data
|
||||
* @returns {html}
|
||||
*/
|
||||
present(data) {
|
||||
const html = [];
|
||||
html.push("<table class='table table-hover table-sm table-bordered table-nonfluid' style='table-layout: fixed'>");
|
||||
html.push("<tr>");
|
||||
html.push("<th>Field</th>");
|
||||
html.push("<th>Value</th>");
|
||||
html.push("</tr>");
|
||||
|
||||
for (const key in data) {
|
||||
html.push("<tr>");
|
||||
html.push("<td style=\"word-wrap:break-word\">" + key + "</td>");
|
||||
html.push("<td>" + data[key] + "</td>");
|
||||
html.push("</tr>");
|
||||
}
|
||||
html.push("</table>");
|
||||
return html.join("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default ParseUDP;
|
|
@ -41,7 +41,7 @@ class ScanForEmbeddedFiles extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n",
|
||||
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any sufficiently long file is likely to contain these magic bytes coincidentally.\n",
|
||||
numFound = 0;
|
||||
const categories = [],
|
||||
data = new Uint8Array(input);
|
||||
|
|
|
@ -62,7 +62,7 @@ class SharpenImage extends Operation {
|
|||
async run(input, args) {
|
||||
const [radius, amount, threshold] = args;
|
||||
|
||||
if (!isImage(new Uint8Array(input))){
|
||||
if (!isImage(new Uint8Array(input))) {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class SwapEndianness extends Operation {
|
|||
const word = data.slice(i, i + wordLength);
|
||||
|
||||
// Pad word if too short
|
||||
if (padIncompleteWords && word.length < wordLength){
|
||||
if (padIncompleteWords && word.length < wordLength) {
|
||||
for (j = word.length; j < wordLength; j++) {
|
||||
word.push(0);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class UNIXTimestampToWindowsFiletime extends Operation {
|
|||
|
||||
input = new BigNumber(input);
|
||||
|
||||
if (units === "Seconds (s)"){
|
||||
if (units === "Seconds (s)") {
|
||||
input = input.multipliedBy(new BigNumber("10000000"));
|
||||
} else if (units === "Milliseconds (ms)") {
|
||||
input = input.multipliedBy(new BigNumber("10000"));
|
||||
|
@ -65,7 +65,7 @@ class UNIXTimestampToWindowsFiletime extends Operation {
|
|||
|
||||
input = input.plus(new BigNumber("116444736000000000"));
|
||||
|
||||
if (format === "Hex"){
|
||||
if (format === "Hex") {
|
||||
return input.toString(16);
|
||||
} else {
|
||||
return input.toFixed();
|
||||
|
|
|
@ -57,7 +57,7 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
|||
|
||||
input = input.minus(new BigNumber("116444736000000000"));
|
||||
|
||||
if (units === "Seconds (s)"){
|
||||
if (units === "Seconds (s)") {
|
||||
input = input.dividedBy(new BigNumber("10000000"));
|
||||
} else if (units === "Milliseconds (ms)") {
|
||||
input = input.dividedBy(new BigNumber("10000"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue