Merge branch 'gchq:master' into feature/docker-multiplatform-build

This commit is contained in:
PathToLife 2025-02-16 00:54:09 +00:00 committed by GitHub
commit 324560aeae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 5805 additions and 3269 deletions

8406
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -160,7 +160,7 @@
"notepack.io": "^3.0.1", "notepack.io": "^3.0.1",
"ntlm": "^0.1.3", "ntlm": "^0.1.3",
"nwmatcher": "^1.4.4", "nwmatcher": "^1.4.4",
"otp": "0.1.3", "otpauth": "9.3.6",
"path": "^0.12.7", "path": "^0.12.7",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"process": "^0.11.10", "process": "^0.11.10",

View file

@ -274,7 +274,8 @@
"Unicode Text Format", "Unicode Text Format",
"Remove Diacritics", "Remove Diacritics",
"Unescape Unicode Characters", "Unescape Unicode Characters",
"Convert to NATO alphabet" "Convert to NATO alphabet",
"Convert Leet Speak"
] ]
}, },
{ {
@ -326,7 +327,9 @@
"Unescape string", "Unescape string",
"Pseudo-Random Number Generator", "Pseudo-Random Number Generator",
"Sleep", "Sleep",
"File Tree" "File Tree",
"Take nth bytes",
"Drop nth bytes"
] ]
}, },
{ {

View file

@ -0,0 +1,113 @@
/**
* @author bartblaze []
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* Convert Leet Speak operation
*/
class ConvertLeetSpeak extends Operation {
/**
* ConvertLeetSpeak constructor
*/
constructor() {
super();
this.name = "Convert Leet Speak";
this.module = "Default";
this.description = "Converts to and from Leet Speak";
this.infoURL = "https://wikipedia.org/wiki/Leet";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Direction",
type: "option",
value: ["To Leet Speak", "From Leet Speak"],
defaultIndex: 0
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const direction = args[0];
if (direction === "To Leet Speak") {
return input.replace(/[abcdefghijklmnopqrstuvwxyz]/gi, char => {
return toLeetMap[char.toLowerCase()] || char;
});
} else if (direction === "From Leet Speak") {
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/g, char => {
return fromLeetMap[char] || char;
});
}
}
}
const toLeetMap = {
"a": "4",
"b": "b",
"c": "c",
"d": "d",
"e": "3",
"f": "f",
"g": "g",
"h": "h",
"i": "1",
"j": "j",
"k": "k",
"l": "l",
"m": "m",
"n": "n",
"o": "0",
"p": "p",
"q": "q",
"r": "r",
"s": "5",
"t": "7",
"u": "u",
"v": "v",
"w": "w",
"x": "x",
"y": "y",
"z": "z"
};
const fromLeetMap = {
"4": "a",
"b": "b",
"c": "c",
"d": "d",
"3": "e",
"f": "f",
"g": "g",
"h": "h",
"1": "i",
"j": "j",
"k": "k",
"l": "l",
"m": "m",
"n": "n",
"0": "o",
"p": "p",
"q": "q",
"r": "r",
"5": "s",
"7": "t",
"u": "u",
"v": "v",
"w": "w",
"x": "x",
"y": "y",
"z": "z"
};
export default ConvertLeetSpeak;

View file

@ -0,0 +1,79 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Drop nth bytes operation
*/
class DropNthBytes extends Operation {
/**
* DropNthBytes constructor
*/
constructor() {
super();
this.name = "Drop nth bytes";
this.module = "Default";
this.description = "Drops every nth byte starting with a given byte.";
this.infoURL = "";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
name: "Drop every",
type: "number",
value: 4
},
{
name: "Starting at",
type: "number",
value: 0
},
{
name: "Apply to each line",
type: "boolean",
value: false
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const n = args[0];
const start = args[1];
const eachLine = args[2];
if (parseInt(n, 10) !== n || n <= 0) {
throw new OperationError("'Drop every' must be a positive integer.");
}
if (parseInt(start, 10) !== start || start < 0) {
throw new OperationError("'Starting at' must be a positive or zero integer.");
}
let offset = 0;
const output = [];
for (let i = 0; i < input.length; i++) {
if (eachLine && input[i] === 0x0a) {
output.push(0x0a);
offset = i + 1;
} else if (i - offset < start || (i - (start + offset)) % n !== 0) {
output.push(input[i]);
}
}
return output;
}
}
export default DropNthBytes;

View file

@ -5,16 +5,14 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import otp from "otp"; import * as OTPAuth from "otpauth";
import ToBase32 from "./ToBase32.mjs";
/** /**
* Generate HOTP operation * Generate HOTP operation
*/ */
class GenerateHOTP extends Operation { class GenerateHOTP extends Operation {
/** /**
* GenerateHOTP constructor *
*/ */
constructor() { constructor() {
super(); super();
@ -31,11 +29,6 @@ class GenerateHOTP extends Operation {
"type": "string", "type": "string",
"value": "" "value": ""
}, },
{
"name": "Key size",
"type": "number",
"value": 32
},
{ {
"name": "Code length", "name": "Code length",
"type": "number", "type": "number",
@ -50,21 +43,26 @@ class GenerateHOTP extends Operation {
} }
/** /**
* @param {ArrayBuffer} input *
* @param {Object[]} args
* @returns {string}
*/ */
run(input, args) { run(input, args) {
const otpObj = otp({ const secretStr = new TextDecoder("utf-8").decode(input).trim();
name: args[0], const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
keySize: args[1],
codeLength: args[2],
secret: (new ToBase32).run(input, []).split("=")[0],
});
const counter = args[3];
return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`;
}
const hotp = new OTPAuth.HOTP({
issuer: "",
label: args[0],
algorithm: "SHA1",
digits: args[1],
counter: args[2],
secret: OTPAuth.Secret.fromBase32(secret)
});
const uri = hotp.toString();
const code = hotp.generate();
return `URI: ${uri}\n\nPassword: ${code}`;
}
} }
export default GenerateHOTP; export default GenerateHOTP;

View file

@ -5,20 +5,17 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import otp from "otp"; import * as OTPAuth from "otpauth";
import ToBase32 from "./ToBase32.mjs";
/** /**
* Generate TOTP operation * Generate TOTP operation
*/ */
class GenerateTOTP extends Operation { class GenerateTOTP extends Operation {
/** /**
* GenerateTOTP constructor *
*/ */
constructor() { constructor() {
super(); super();
this.name = "Generate TOTP"; this.name = "Generate TOTP";
this.module = "Default"; this.module = "Default";
this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OAUTH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.<br><br>Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds."; this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OAUTH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.<br><br>Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds.";
@ -31,11 +28,6 @@ class GenerateTOTP extends Operation {
"type": "string", "type": "string",
"value": "" "value": ""
}, },
{
"name": "Key size",
"type": "number",
"value": 32
},
{ {
"name": "Code length", "name": "Code length",
"type": "number", "type": "number",
@ -55,22 +47,27 @@ class GenerateTOTP extends Operation {
} }
/** /**
* @param {ArrayBuffer} input *
* @param {Object[]} args
* @returns {string}
*/ */
run(input, args) { run(input, args) {
const otpObj = otp({ const secretStr = new TextDecoder("utf-8").decode(input).trim();
name: args[0], const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
keySize: args[1],
codeLength: args[2],
secret: (new ToBase32).run(input, []).split("=")[0],
epoch: args[3],
timeSlice: args[4]
});
return `URI: ${otpObj.totpURL}\n\nPassword: ${otpObj.totp()}`;
}
const totp = new OTPAuth.TOTP({
issuer: "",
label: args[0],
algorithm: "SHA1",
digits: args[1],
period: args[3],
epoch: args[2] * 1000, // Convert seconds to milliseconds
secret: OTPAuth.Secret.fromBase32(secret)
});
const uri = totp.toString();
const code = totp.generate();
return `URI: ${uri}\n\nPassword: ${code}`;
}
} }
export default GenerateTOTP; export default GenerateTOTP;

View file

@ -0,0 +1,79 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Take nth bytes operation
*/
class TakeNthBytes extends Operation {
/**
* TakeNthBytes constructor
*/
constructor() {
super();
this.name = "Take nth bytes";
this.module = "Default";
this.description = "Takes every nth byte starting with a given byte.";
this.infoURL = "";
this.inputType = "byteArray";
this.outputType = "byteArray";
this.args = [
{
name: "Take every",
type: "number",
value: 4
},
{
name: "Starting at",
type: "number",
value: 0
},
{
name: "Apply to each line",
type: "boolean",
value: false
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const n = args[0];
const start = args[1];
const eachLine = args[2];
if (parseInt(n, 10) !== n || n <= 0) {
throw new OperationError("'Take every' must be a positive integer.");
}
if (parseInt(start, 10) !== start || start < 0) {
throw new OperationError("'Starting at' must be a positive or zero integer.");
}
let offset = 0;
const output = [];
for (let i = 0; i < input.length; i++) {
if (eachLine && input[i] === 0x0a) {
output.push(0x0a);
offset = i + 1;
} else if (i - offset >= start && (i - (start + offset)) % n === 0) {
output.push(input[i]);
}
}
return output;
}
}
export default TakeNthBytes;

View file

@ -575,12 +575,11 @@ Top Drawer`, {
}), }),
it("Generate HOTP", () => { it("Generate HOTP", () => {
const result = chef.generateHOTP("Cut The Mustard", { const result = chef.generateHOTP("JBSWY3DPEHPK3PXP", {
name: "colonel",
}); });
const expected = `URI: otpauth://hotp/colonel?secret=IN2XIICUNBSSATLVON2GC4TE const expected = `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0
Password: 034148`; Password: 282760`;
assert.strictEqual(result.toString(), expected); assert.strictEqual(result.toString(), expected);
}), }),

View file

@ -54,11 +54,13 @@ import "./tests/Comment.mjs";
import "./tests/Compress.mjs"; import "./tests/Compress.mjs";
import "./tests/ConditionalJump.mjs"; import "./tests/ConditionalJump.mjs";
import "./tests/ConvertCoordinateFormat.mjs"; import "./tests/ConvertCoordinateFormat.mjs";
import "./tests/ConvertLeetSpeak.mjs";
import "./tests/ConvertToNATOAlphabet.mjs"; import "./tests/ConvertToNATOAlphabet.mjs";
import "./tests/Crypt.mjs"; import "./tests/Crypt.mjs";
import "./tests/CSV.mjs"; import "./tests/CSV.mjs";
import "./tests/DateTime.mjs"; import "./tests/DateTime.mjs";
import "./tests/DefangIP.mjs"; import "./tests/DefangIP.mjs";
import "./tests/DropNthBytes.mjs";
import "./tests/ECDSA.mjs"; import "./tests/ECDSA.mjs";
import "./tests/ELFInfo.mjs"; import "./tests/ELFInfo.mjs";
import "./tests/Enigma.mjs"; import "./tests/Enigma.mjs";
@ -149,6 +151,7 @@ import "./tests/StripUDPHeader.mjs";
import "./tests/Subsection.mjs"; import "./tests/Subsection.mjs";
import "./tests/SwapCase.mjs"; import "./tests/SwapCase.mjs";
import "./tests/SymmetricDifference.mjs"; import "./tests/SymmetricDifference.mjs";
import "./tests/TakeNthBytes.mjs";
import "./tests/TextEncodingBruteForce.mjs"; import "./tests/TextEncodingBruteForce.mjs";
import "./tests/ToFromInsensitiveRegex.mjs"; import "./tests/ToFromInsensitiveRegex.mjs";
import "./tests/TranslateDateTimeFormat.mjs"; import "./tests/TranslateDateTimeFormat.mjs";

View file

@ -0,0 +1,33 @@
/**
* @author bartblaze []
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Convert to Leet Speak: basic text",
input: "leet",
expectedOutput: "l337",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["To Leet Speak"]
}
]
},
{
name: "Convert from Leet Speak: basic leet",
input: "l337",
expectedOutput: "leet",
recipeConfig: [
{
op: "Convert Leet Speak",
args: ["From Leet Speak"]
}
]
}
]);

View file

@ -0,0 +1,123 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/**
* Drop nth bytes tests
*/
TestRegister.addTests([
{
name: "Drop nth bytes: Nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Nothing (apply to each line)",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Basic single line",
input: "0123456789",
expectedOutput: "1235679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Basic single line (apply to each line)",
input: "0123456789",
expectedOutput: "1235679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Complex single line",
input: "0123456789",
expectedOutput: "01234678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Drop nth bytes: Complex single line (apply to each line)",
input: "0123456789",
expectedOutput: "01234678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, true],
},
],
},
{
name: "Drop nth bytes: Basic multi line",
input: "01234\n56789",
expectedOutput: "123\n5689",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Drop nth bytes: Basic multi line (apply to each line)",
input: "01234\n56789",
expectedOutput: "123\n678",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Drop nth bytes: Complex multi line",
input: "01234\n56789",
expectedOutput: "012345679",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Drop nth bytes: Complex multi line (apply to each line)",
input: "012345\n6789ab",
expectedOutput: "01234\n6789a",
recipeConfig: [
{
op: "Drop nth bytes",
args: [4, 5, true],
},
],
}
]);

View file

@ -11,12 +11,12 @@ import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([ TestRegister.addTests([
{ {
name: "Generate HOTP", name: "Generate HOTP",
input: "12345678901234567890", input: "JBSWY3DPEHPK3PXP",
expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224", expectedOutput: `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0\n\nPassword: 282760`,
recipeConfig: [ recipeConfig: [
{ {
op: "Generate HOTP", op: "Generate HOTP",
args: ["", 32, 6, 0], args: ["", 6, 0], // [Name, Code length, Counter]
}, },
], ],
}, },

View file

@ -0,0 +1,123 @@
/**
* @author Oshawk [oshawk@protonmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/**
* Take nth bytes tests
*/
TestRegister.addTests([
{
name: "Take nth bytes: Nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Nothing (apply to each line)",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Basic single line",
input: "0123456789",
expectedOutput: "048",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Basic single line (apply to each line)",
input: "0123456789",
expectedOutput: "048",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Complex single line",
input: "0123456789",
expectedOutput: "59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Take nth bytes: Complex single line (apply to each line)",
input: "0123456789",
expectedOutput: "59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, true],
},
],
},
{
name: "Take nth bytes: Basic multi line",
input: "01234\n56789",
expectedOutput: "047",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, false],
},
],
},
{
name: "Take nth bytes: Basic multi line (apply to each line)",
input: "01234\n56789",
expectedOutput: "04\n59",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 0, true],
},
],
},
{
name: "Take nth bytes: Complex multi line",
input: "01234\n56789",
expectedOutput: "\n8",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, false],
},
],
},
{
name: "Take nth bytes: Complex multi line (apply to each line)",
input: "012345\n6789ab",
expectedOutput: "5\nb",
recipeConfig: [
{
op: "Take nth bytes",
args: [4, 5, true],
},
],
}
]);