mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Added Bcrypt, Scrypt, BSON and string operations along with many new tests.
This commit is contained in:
parent
2f5b0533d8
commit
715ca1c292
28 changed files with 1290 additions and 84 deletions
|
@ -1,4 +1,5 @@
|
|||
import utf8 from "utf8";
|
||||
import moment from "moment-timezone";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -201,21 +202,34 @@ const Utils = {
|
|||
* Utils.parseEscapedChars("\\n");
|
||||
*/
|
||||
parseEscapedChars: function(str) {
|
||||
return str.replace(/(\\)?\\([nrtbf]|x[\da-fA-F]{2})/g, function(m, a, b) {
|
||||
return str.replace(/(\\)?\\([bfnrtv0'"]|x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]{1,6}\})/g, function(m, a, b) {
|
||||
if (a === "\\") return "\\"+b;
|
||||
switch (b[0]) {
|
||||
case "n":
|
||||
return "\n";
|
||||
case "r":
|
||||
return "\r";
|
||||
case "t":
|
||||
return "\t";
|
||||
case "0":
|
||||
return "\0";
|
||||
case "b":
|
||||
return "\b";
|
||||
case "t":
|
||||
return "\t";
|
||||
case "n":
|
||||
return "\n";
|
||||
case "v":
|
||||
return "\v";
|
||||
case "f":
|
||||
return "\f";
|
||||
case "r":
|
||||
return "\r";
|
||||
case '"':
|
||||
return '"';
|
||||
case "'":
|
||||
return "'";
|
||||
case "x":
|
||||
return Utils.chr(parseInt(b.substr(1), 16));
|
||||
return String.fromCharCode(parseInt(b.substr(1), 16));
|
||||
case "u":
|
||||
if (b[1] === "{")
|
||||
return String.fromCodePoint(parseInt(b.slice(2, -1), 16));
|
||||
else
|
||||
return String.fromCharCode(parseInt(b.substr(1), 16));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -322,14 +336,14 @@ const Utils = {
|
|||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||
* Utils.convertToByteArray("Привет", "utf8");
|
||||
* // returns "ÐÑивеÑ"
|
||||
* Utils.convertToByteString("Привет", "utf8");
|
||||
*
|
||||
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||
* Utils.convertToByteArray("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
|
||||
* // returns "ÐдÑавÑÑвÑйÑе"
|
||||
* Utils.convertToByteString("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
|
||||
*
|
||||
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||
* Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
|
||||
* // returns "ÐдÑавÑÑвÑйÑе"
|
||||
* Utils.convertToByteString("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
|
||||
*/
|
||||
convertToByteString: function(str, type) {
|
||||
switch (type.toLowerCase()) {
|
||||
|
|
|
@ -52,6 +52,7 @@ const Categories = [
|
|||
"From HTML Entity",
|
||||
"URL Encode",
|
||||
"URL Decode",
|
||||
"Escape Unicode Characters",
|
||||
"Unescape Unicode Characters",
|
||||
"To Quoted Printable",
|
||||
"From Quoted Printable",
|
||||
|
@ -99,6 +100,8 @@ const Categories = [
|
|||
"Substitute",
|
||||
"Derive PBKDF2 key",
|
||||
"Derive EVP key",
|
||||
"Bcrypt",
|
||||
"Scrypt",
|
||||
"Pseudo-Random Number Generator",
|
||||
]
|
||||
},
|
||||
|
@ -275,6 +278,10 @@ const Categories = [
|
|||
"Compare SSDEEP hashes",
|
||||
"Compare CTPH hashes",
|
||||
"HMAC",
|
||||
"Bcrypt",
|
||||
"Bcrypt compare",
|
||||
"Bcrypt parse",
|
||||
"Scrypt",
|
||||
"Fletcher-8 Checksum",
|
||||
"Fletcher-16 Checksum",
|
||||
"Fletcher-32 Checksum",
|
||||
|
@ -311,6 +318,8 @@ const Categories = [
|
|||
"To Snake case",
|
||||
"To Camel case",
|
||||
"To Kebab case",
|
||||
"BSON serialise",
|
||||
"BSON deserialise",
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -912,6 +912,34 @@ const OperationConfig = {
|
|||
}
|
||||
]
|
||||
},
|
||||
"Escape Unicode Characters": {
|
||||
module: "Default",
|
||||
description: "Converts characters to their unicode-escaped notations.<br><br>Supports the prefixes:<ul><li><code>\\u</code></li><li><code>%u</code></li><li><code>U+</code></li></ul>e.g. <code>σου</code> becomes <code>\\u03C3\\u03BF\\u03C5</code>",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Prefix",
|
||||
type: "option",
|
||||
value: Unicode.PREFIXES
|
||||
},
|
||||
{
|
||||
name: "Encode all chars",
|
||||
type: "boolean",
|
||||
value: false
|
||||
},
|
||||
{
|
||||
name: "Padding",
|
||||
type: "number",
|
||||
value: 4
|
||||
},
|
||||
{
|
||||
name: "Uppercase hex",
|
||||
type: "boolean",
|
||||
value: true
|
||||
}
|
||||
]
|
||||
},
|
||||
"From Quoted Printable": {
|
||||
module: "Default",
|
||||
description: "Converts QP-encoded text back to standard text.",
|
||||
|
@ -2417,7 +2445,7 @@ const OperationConfig = {
|
|||
},
|
||||
"From UNIX Timestamp": {
|
||||
module: "Default",
|
||||
description: "Converts a UNIX timestamp to a datetime string.<br><br>e.g. <code>978346800</code> becomes <code>Mon 1 January 2001 11:00:00 UTC</code><br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).<br><br>Note that this operation supports various date formats including the US 'MM/DD/YYYY' format, but not the international 'DD/MM/YYYY' format. For dates in this format, use the 'Translate DateTime format' operation instead.",
|
||||
description: "Converts a UNIX timestamp to a datetime string.<br><br>e.g. <code>978346800</code> becomes <code>Mon 1 January 2001 11:00:00 UTC</code><br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).",
|
||||
inputType: "number",
|
||||
outputType: "string",
|
||||
args: [
|
||||
|
@ -2432,7 +2460,7 @@ const OperationConfig = {
|
|||
module: "Default",
|
||||
description: "Parses a datetime string in UTC and returns the corresponding UNIX timestamp.<br><br>e.g. <code>Mon 1 January 2001 11:00:00</code> becomes <code>978346800</code><br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).",
|
||||
inputType: "string",
|
||||
outputType: "number",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Units",
|
||||
|
@ -2443,6 +2471,11 @@ const OperationConfig = {
|
|||
name: "Treat as UTC",
|
||||
type: "boolean",
|
||||
value: DateTime.TREAT_AS_UTC
|
||||
},
|
||||
{
|
||||
name: "Show parsed datetime",
|
||||
type: "boolean",
|
||||
value: true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -3554,14 +3587,40 @@ const OperationConfig = {
|
|||
},
|
||||
"Escape string": {
|
||||
module: "Default",
|
||||
description: "Escapes special characters in a string so that they do not cause conflicts. For example, <code>Don't stop me now</code> becomes <code>Don\\'t stop me now</code>.<br><br>Supports the following escape sequences:<ul><li><code>\\n</code> (Line feed/newline)</li><li><code>\\r</code> (Carriage return)</li><li><code>\\t</code> (Horizontal tab)</li><li><code>\\b</code> (Backspace)</li><li><code>\\f</code> (Form feed)</li><li><code>\\xnn</code> (Hex, where n is 0-f)</li><li><code>\\\\</code> (Backslash)</li><li><code>\\'</code> (Single quote)</li><li><code>\\"</code> (Double quote)</li></ul>",
|
||||
description: "Escapes special characters in a string so that they do not cause conflicts. For example, <code>Don't stop me now</code> becomes <code>Don\\'t stop me now</code>.<br><br>Supports the following escape sequences:<ul><li><code>\\n</code> (Line feed/newline)</li><li><code>\\r</code> (Carriage return)</li><li><code>\\t</code> (Horizontal tab)</li><li><code>\\b</code> (Backspace)</li><li><code>\\f</code> (Form feed)</li><li><code>\\xnn</code> (Hex, where n is 0-f)</li><li><code>\\\\</code> (Backslash)</li><li><code>\\'</code> (Single quote)</li><li><code>\\"</code> (Double quote)</li><li><code>\\unnnn</code> (Unicode character)</li><li><code>\\u{nnnnnn}</code> (Unicode code point)</li></ul>",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: []
|
||||
args: [
|
||||
{
|
||||
name: "Escape level",
|
||||
type: "option",
|
||||
value: StrUtils.ESCAPE_LEVEL
|
||||
},
|
||||
{
|
||||
name: "Escape quote",
|
||||
type: "option",
|
||||
value: StrUtils.QUOTE_TYPES
|
||||
},
|
||||
{
|
||||
name: "JSON compatible",
|
||||
type: "boolean",
|
||||
value: false
|
||||
},
|
||||
{
|
||||
name: "ES6 compatible",
|
||||
type: "boolean",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: "Uppercase hex",
|
||||
type: "boolean",
|
||||
value: false
|
||||
}
|
||||
]
|
||||
},
|
||||
"Unescape string": {
|
||||
module: "Default",
|
||||
description: "Unescapes characters in a string that have been escaped. For example, <code>Don\\'t stop me now</code> becomes <code>Don't stop me now</code>.<br><br>Supports the following escape sequences:<ul><li><code>\\n</code> (Line feed/newline)</li><li><code>\\r</code> (Carriage return)</li><li><code>\\t</code> (Horizontal tab)</li><li><code>\\b</code> (Backspace)</li><li><code>\\f</code> (Form feed)</li><li><code>\\xnn</code> (Hex, where n is 0-f)</li><li><code>\\\\</code> (Backslash)</li><li><code>\\'</code> (Single quote)</li><li><code>\\"</code> (Double quote)</li></ul>",
|
||||
description: "Unescapes characters in a string that have been escaped. For example, <code>Don\\'t stop me now</code> becomes <code>Don't stop me now</code>.<br><br>Supports the following escape sequences:<ul><li><code>\\n</code> (Line feed/newline)</li><li><code>\\r</code> (Carriage return)</li><li><code>\\t</code> (Horizontal tab)</li><li><code>\\b</code> (Backspace)</li><li><code>\\f</code> (Form feed)</li><li><code>\\xnn</code> (Hex, where n is 0-f)</li><li><code>\\\\</code> (Backslash)</li><li><code>\\'</code> (Single quote)</li><li><code>\\"</code> (Double quote)</li><li><code>\\unnnn</code> (Unicode character)</li><li><code>\\u{nnnnnn}</code> (Unicode code point)</li></ul>",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: []
|
||||
|
@ -4018,7 +4077,88 @@ const OperationConfig = {
|
|||
inputType: "string",
|
||||
outputType: "number",
|
||||
args: []
|
||||
}
|
||||
},
|
||||
"Bcrypt": {
|
||||
module: "Hashing",
|
||||
description: "bcrypt is a password hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher, and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count (rounds) can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.<br><br>Enter the password in the input to generate its hash.",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Rounds",
|
||||
type: "number",
|
||||
value: Hash.BCRYPT_ROUNDS
|
||||
}
|
||||
]
|
||||
},
|
||||
"Bcrypt compare": {
|
||||
module: "Hashing",
|
||||
description: "Tests whether the input matches the given bcrypt hash. To test multiple possible passwords, use the 'Fork' operation.",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Hash",
|
||||
type: "string",
|
||||
value: ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"Bcrypt parse": {
|
||||
module: "Hashing",
|
||||
description: "Parses a bcrypt hash to determine the number of rounds used, the salt, and the password hash.",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: []
|
||||
},
|
||||
"Scrypt": {
|
||||
module: "Hashing",
|
||||
description: "scrypt is a password-based key derivation function (PBKDF) created by Colin Percival. The algorithm was specifically designed to make it costly to perform large-scale custom hardware attacks by requiring large amounts of memory. In 2016, the scrypt algorithm was published by IETF as RFC 7914.<br><br>Enter the password in the input to generate its hash.",
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Salt",
|
||||
type: "toggleString",
|
||||
value: "",
|
||||
toggleValues: Hash.KEY_FORMAT
|
||||
},
|
||||
{
|
||||
name: "Iterations (N)",
|
||||
type: "number",
|
||||
value: Hash.SCRYPT_ITERATIONS
|
||||
},
|
||||
{
|
||||
name: "Memory factor (r)",
|
||||
type: "number",
|
||||
value: Hash.SCRYPT_MEM_FACTOR
|
||||
},
|
||||
{
|
||||
name: "Parallelization factor (p)",
|
||||
type: "number",
|
||||
value: Hash.SCRYPT_PARALLEL_FACTOR
|
||||
},
|
||||
{
|
||||
name: "Key length",
|
||||
type: "number",
|
||||
value: Hash.SCRYPT_KEY_LENGTH
|
||||
},
|
||||
]
|
||||
},
|
||||
"BSON serialise": {
|
||||
module: "BSON",
|
||||
description: "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.<br><br>Input data should be valid JSON.",
|
||||
inputType: "string",
|
||||
outputType: "ArrayBuffer",
|
||||
args: []
|
||||
},
|
||||
"BSON deserialise": {
|
||||
module: "BSON",
|
||||
description: "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.<br><br>Input data should be in a raw bytes format.",
|
||||
inputType: "ArrayBuffer",
|
||||
outputType: "string",
|
||||
args: []
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
|
22
src/core/config/modules/BSON.js
Normal file
22
src/core/config/modules/BSON.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import BSON from "../../operations/BSON.js";
|
||||
|
||||
|
||||
/**
|
||||
* BSON module.
|
||||
*
|
||||
* Libraries:
|
||||
* - bson
|
||||
* - buffer
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
|
||||
|
||||
OpModules.BSON = {
|
||||
"BSON serialise": BSON.runBSONSerialise,
|
||||
"BSON deserialise": BSON.runBSONDeserialise,
|
||||
};
|
||||
|
||||
export default OpModules;
|
|
@ -43,6 +43,7 @@ import XKCD from "../../operations/XKCD.js";
|
|||
* - otp
|
||||
* - crypto
|
||||
* - bignumber.js
|
||||
* - jsesc
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2017
|
||||
|
@ -81,6 +82,7 @@ OpModules.Default = {
|
|||
"Strip HTML tags": HTML.runStripTags,
|
||||
"Parse colour code": HTML.runParseColourCode,
|
||||
"Unescape Unicode Characters": Unicode.runUnescape,
|
||||
"Escape Unicode Characters": Unicode.runEscape,
|
||||
"To Quoted Printable": QuotedPrintable.runTo,
|
||||
"From Quoted Printable": QuotedPrintable.runFrom,
|
||||
"Swap endianness": Endian.runSwapEndianness,
|
||||
|
|
|
@ -39,6 +39,10 @@ OpModules.Hashing = {
|
|||
"Compare CTPH hashes": Hash.runCompareCTPH,
|
||||
"Compare SSDEEP hashes": Hash.runCompareSSDEEP,
|
||||
"HMAC": Hash.runHMAC,
|
||||
"Bcrypt": Hash.runBcrypt,
|
||||
"Bcrypt compare": Hash.runBcryptCompare,
|
||||
"Bcrypt parse": Hash.runBcryptParse,
|
||||
"Scrypt": Hash.runScrypt,
|
||||
"Fletcher-8 Checksum": Checksum.runFletcher8,
|
||||
"Fletcher-16 Checksum": Checksum.runFletcher16,
|
||||
"Fletcher-32 Checksum": Checksum.runFletcher32,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
import OpModules from "./Default.js";
|
||||
import BSONModule from "./BSON.js";
|
||||
import CharEncModule from "./CharEnc.js";
|
||||
import CipherModule from "./Ciphers.js";
|
||||
import CodeModule from "./Code.js";
|
||||
|
@ -24,6 +25,7 @@ import URLModule from "./URL.js";
|
|||
|
||||
Object.assign(
|
||||
OpModules,
|
||||
BSONModule,
|
||||
CharEncModule,
|
||||
CipherModule,
|
||||
CodeModule,
|
||||
|
|
59
src/core/operations/BSON.js
Normal file
59
src/core/operations/BSON.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import bsonjs from "bson";
|
||||
import {Buffer} from "buffer";
|
||||
|
||||
|
||||
/**
|
||||
* BSON operations.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
const BSON = {
|
||||
|
||||
/**
|
||||
* BSON serialise operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
runBSONSerialise(input, args) {
|
||||
if (!input) return new ArrayBuffer();
|
||||
|
||||
const bson = new bsonjs();
|
||||
|
||||
try {
|
||||
const data = JSON.parse(input);
|
||||
return bson.serialize(data).buffer;
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* BSON deserialise operation.
|
||||
*
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runBSONDeserialise(input, args) {
|
||||
if (!input.byteLength) return "";
|
||||
|
||||
const bson = new bsonjs();
|
||||
|
||||
try {
|
||||
const data = bson.deserialize(new Buffer(input));
|
||||
return JSON.stringify(data, null, 2);
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default BSON;
|
|
@ -148,6 +148,10 @@ const ByteRepr = {
|
|||
throw "Error: Base argument must be between 2 and 36";
|
||||
}
|
||||
|
||||
if (input.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (base !== 16 && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
|
||||
|
||||
// Split into groups of 2 if the whole string is concatenated and
|
||||
|
|
|
@ -483,12 +483,11 @@ const Code = {
|
|||
|
||||
|
||||
/**
|
||||
* Converts to snake_case.
|
||||
* To Snake Case operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToSnakeCase(input, args) {
|
||||
const smart = args[0];
|
||||
|
@ -502,12 +501,11 @@ const Code = {
|
|||
|
||||
|
||||
/**
|
||||
* Converts to camelCase.
|
||||
* To Camel Case operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToCamelCase(input, args) {
|
||||
const smart = args[0];
|
||||
|
@ -521,12 +519,11 @@ const Code = {
|
|||
|
||||
|
||||
/**
|
||||
* Converts to kebab-case.
|
||||
* To Kebab Case operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runToKebabCase(input, args) {
|
||||
const smart = args[0];
|
||||
|
@ -537,6 +534,7 @@ const Code = {
|
|||
return kebabCase(input);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default Code;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import moment from "moment-timezone";
|
||||
|
||||
|
||||
/**
|
||||
* Date and time operations.
|
||||
*
|
||||
|
@ -57,24 +60,29 @@ const DateTime = {
|
|||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {number}
|
||||
* @returns {string}
|
||||
*/
|
||||
runToUnixTimestamp: function(input, args) {
|
||||
let units = args[0],
|
||||
const units = args[0],
|
||||
treatAsUTC = args[1],
|
||||
showDateTime = args[2],
|
||||
d = treatAsUTC ? moment.utc(input) : moment(input);
|
||||
|
||||
let result = "";
|
||||
|
||||
if (units === "Seconds (s)") {
|
||||
return d.unix();
|
||||
result = d.unix();
|
||||
} else if (units === "Milliseconds (ms)") {
|
||||
return d.valueOf();
|
||||
result = d.valueOf();
|
||||
} else if (units === "Microseconds (μs)") {
|
||||
return d.valueOf() * 1000;
|
||||
result = d.valueOf() * 1000;
|
||||
} else if (units === "Nanoseconds (ns)") {
|
||||
return d.valueOf() * 1000000;
|
||||
result = d.valueOf() * 1000000;
|
||||
} else {
|
||||
throw "Unrecognised unit";
|
||||
}
|
||||
|
||||
return showDateTime ? `${result} (${d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss")} UTC)` : result.toString();
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import * as SHA3 from "js-sha3";
|
|||
import Checksum from "./Checksum.js";
|
||||
import ctph from "ctph.js";
|
||||
import ssdeep from "ssdeep.js";
|
||||
import bcrypt from "bcryptjs";
|
||||
import scrypt from "scryptsy";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -449,6 +451,127 @@ const Hash = {
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
BCRYPT_ROUNDS: 10,
|
||||
|
||||
/**
|
||||
* Bcrypt operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runBcrypt: async function (input, args) {
|
||||
const rounds = args[0];
|
||||
const salt = await bcrypt.genSalt(rounds);
|
||||
|
||||
return await bcrypt.hash(input, salt, null, p => {
|
||||
// Progress callback
|
||||
if (ENVIRONMENT_IS_WORKER())
|
||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Bcrypt compare operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runBcryptCompare: async function (input, args) {
|
||||
const hash = args[0];
|
||||
|
||||
const match = await bcrypt.compare(input, hash, null, p => {
|
||||
// Progress callback
|
||||
if (ENVIRONMENT_IS_WORKER())
|
||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||
});
|
||||
|
||||
return match ? "Match: " + input : "No match";
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Bcrypt parse operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runBcryptParse: async function (input, args) {
|
||||
try {
|
||||
return `Rounds: ${bcrypt.getRounds(input)}
|
||||
Salt: ${bcrypt.getSalt(input)}
|
||||
Password hash: ${input.split(bcrypt.getSalt(input))[1]}
|
||||
Full hash: ${input}`;
|
||||
} catch (err) {
|
||||
return "Error: " + err.toString();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
KEY_FORMAT: ["Hex", "Base64", "UTF8", "Latin1"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SCRYPT_ITERATIONS: 16384,
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SCRYPT_MEM_FACTOR: 8,
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SCRYPT_PARALLEL_FACTOR: 1,
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SCRYPT_KEY_LENGTH: 64,
|
||||
|
||||
/**
|
||||
* Scrypt operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runScrypt: function (input, args) {
|
||||
const salt = Utils.convertToByteString(args[0].string || "", args[0].option),
|
||||
iterations = args[1],
|
||||
memFactor = args[2],
|
||||
parallelFactor = args[3],
|
||||
keyLength = args[4];
|
||||
|
||||
try {
|
||||
const data = scrypt(
|
||||
input, salt, iterations, memFactor, parallelFactor, keyLength,
|
||||
p => {
|
||||
// Progress callback
|
||||
if (ENVIRONMENT_IS_WORKER())
|
||||
self.sendStatusMessage(`Progress: ${p.percent.toFixed(0)}%`);
|
||||
}
|
||||
);
|
||||
|
||||
return data.toString("hex");
|
||||
} catch (err) {
|
||||
return "Error: " + err.toString();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Generate all hashes operation.
|
||||
*
|
||||
|
|
|
@ -78,7 +78,7 @@ const Hexdump = {
|
|||
*/
|
||||
runFrom: function(input, args) {
|
||||
let output = [],
|
||||
regex = /^\s*(?:[\dA-F]{4,16}:?)?\s*((?:[\dA-F]{2}\s){1,8}(?:\s|[\dA-F]{2}-)(?:[\dA-F]{2}\s){1,8}|(?:[\dA-F]{2}\s|[\dA-F]{4}\s)+)/igm,
|
||||
regex = /^\s*(?:[\dA-F]{4,16}h?:?)?\s*((?:[\dA-F]{2}\s){1,8}(?:\s|[\dA-F]{2}-)(?:[\dA-F]{2}\s){1,8}|(?:[\dA-F]{2}\s|[\dA-F]{4}\s)+)/igm,
|
||||
block, line;
|
||||
|
||||
while ((block = regex.exec(input))) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Utils from "../Utils.js";
|
||||
import jsesc from "jsesc";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -219,35 +220,45 @@ const StrUtils = {
|
|||
* @constant
|
||||
* @default
|
||||
*/
|
||||
ESCAPE_REPLACEMENTS: [
|
||||
{"escaped": "\\\\", "unescaped": "\\"}, // Must be first
|
||||
{"escaped": "\\'", "unescaped": "'"},
|
||||
{"escaped": "\\\"", "unescaped": "\""},
|
||||
{"escaped": "\\n", "unescaped": "\n"},
|
||||
{"escaped": "\\r", "unescaped": "\r"},
|
||||
{"escaped": "\\t", "unescaped": "\t"},
|
||||
{"escaped": "\\b", "unescaped": "\b"},
|
||||
{"escaped": "\\f", "unescaped": "\f"},
|
||||
],
|
||||
QUOTE_TYPES: ["Single", "Double", "Backtick"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
ESCAPE_LEVEL: ["Special chars", "Everything", "Minimal"],
|
||||
|
||||
/**
|
||||
* Escape string operation.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* StrUtils.runUnescape("Don't do that", [])
|
||||
* StrUtils.runEscape("Don't do that", [])
|
||||
* > "Don\'t do that"
|
||||
* StrUtils.runUnescape(`Hello
|
||||
* StrUtils.runEscape(`Hello
|
||||
* World`, [])
|
||||
* > "Hello\nWorld"
|
||||
*/
|
||||
runEscape: function(input, args) {
|
||||
return StrUtils._replaceByKeys(input, "unescaped", "escaped");
|
||||
const level = args[0],
|
||||
quotes = args[1],
|
||||
jsonCompat = args[2],
|
||||
es6Compat = args[3],
|
||||
lowercaseHex = !args[4];
|
||||
|
||||
return jsesc(input, {
|
||||
quotes: quotes.toLowerCase(),
|
||||
es6: es6Compat,
|
||||
escapeEverything: level === "Everything",
|
||||
minimal: level === "Minimal",
|
||||
json: jsonCompat,
|
||||
lowercaseHex: lowercaseHex,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
@ -255,6 +266,7 @@ const StrUtils = {
|
|||
* Unescape string operation.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
|
@ -268,32 +280,7 @@ const StrUtils = {
|
|||
* World`
|
||||
*/
|
||||
runUnescape: function(input, args) {
|
||||
return StrUtils._replaceByKeys(input, "escaped", "unescaped");
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Replaces all matching tokens in ESCAPE_REPLACEMENTS with the correction. The
|
||||
* ordering is determined by the patternKey and the replacementKey.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
* @author Matt C [matt@artemisbot.uk]
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {string} pattern_key
|
||||
* @param {string} replacement_key
|
||||
* @returns {string}
|
||||
*/
|
||||
_replaceByKeys: function(input, patternKey, replacementKey) {
|
||||
let output = input;
|
||||
|
||||
// Catch the \\x encoded characters
|
||||
if (patternKey === "escaped") output = Utils.parseEscapedChars(input);
|
||||
|
||||
StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => {
|
||||
output = output.split(replacement[patternKey]).join(replacement[replacementKey]);
|
||||
});
|
||||
return output;
|
||||
return Utils.parseEscapedChars(input);
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,40 @@ const Unicode = {
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* Escape Unicode Characters operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runEscape: function(input, args) {
|
||||
const regexWhitelist = /[ -~]/i,
|
||||
prefix = args[0],
|
||||
encodeAll = args[1],
|
||||
padding = args[2],
|
||||
uppercaseHex = args[3];
|
||||
|
||||
let output = "",
|
||||
character = "";
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
character = input[i];
|
||||
if (!encodeAll && regexWhitelist.test(character)) {
|
||||
// It’s a printable ASCII character so don’t escape it.
|
||||
output += character;
|
||||
continue;
|
||||
}
|
||||
|
||||
let cp = character.codePointAt(0).toString(16);
|
||||
if (uppercaseHex) cp = cp.toUpperCase();
|
||||
output += prefix + cp.padStart(padding, "0");
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Lookup table to add prefixes to unicode delimiters so that they can be used in a regex.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue