1
0
mirror of synced 2024-11-24 15:00:17 +01:00

ESM: Fixed OperationError detection and tidied up ops.

This commit is contained in:
n1474335 2018-05-16 10:17:49 +01:00
parent acb8a342a7
commit b760c2f1a0
17 changed files with 2134 additions and 2122 deletions

View File

@ -22,7 +22,7 @@ module.exports = function (grunt) {
// Tasks // Tasks
grunt.registerTask("dev", grunt.registerTask("dev",
"A persistent task which creates a development build whenever source files are modified.", "A persistent task which creates a development build whenever source files are modified.",
["clean:dev", "concurrent:dev"]); ["clean:dev", "exec:generateConfig", "concurrent:dev"]);
grunt.registerTask("node", grunt.registerTask("node",
"Compiles CyberChef into a single NodeJS module.", "Compiles CyberChef into a single NodeJS module.",

4137
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,6 @@
"webpack": "^4.6.0", "webpack": "^4.6.0",
"webpack-dev-server": "^3.1.3", "webpack-dev-server": "^3.1.3",
"webpack-node-externals": "^1.7.2", "webpack-node-externals": "^1.7.2",
"webpack-synchronizable-shell-plugin": "0.0.7",
"worker-loader": "^1.1.1" "worker-loader": "^1.1.1"
}, },
"dependencies": { "dependencies": {

View File

@ -177,7 +177,10 @@ class Recipe {
} }
} catch (err) { } catch (err) {
// Return expected errors as output // Return expected errors as output
if (err instanceof OperationError) { if (err instanceof OperationError ||
(err.type && err.type === "OperationError")) {
// Cannot rely on `err instanceof OperationError` here as extending
// native types is not fully supported yet.
dish.set(err.message, "string"); dish.set(err.message, "string");
return i; return i;
} else { } else {

View File

@ -15,6 +15,8 @@ class OperationError extends Error {
constructor(...args) { constructor(...args) {
super(...args); super(...args);
this.type = "OperationError";
if (Error.captureStackTrace) { if (Error.captureStackTrace) {
Error.captureStackTrace(this, OperationError); Error.captureStackTrace(this, OperationError);
} }

View File

@ -13,9 +13,9 @@
import kbpgp from "kbpgp"; import kbpgp from "kbpgp";
import promisifyDefault from "es6-promisify"; import promisifyDefault from "es6-promisify";
const promisify = promisifyDefault.promisify; const promisify = promisifyDefault.promisify;
/** /**
* Progress callback * Progress callback
*
*/ */
export const ASP = kbpgp.ASP({ export const ASP = kbpgp.ASP({
"progress_hook": info => { "progress_hook": info => {

View File

@ -74,12 +74,14 @@ class DisassembleX86 extends Operation {
* @throws {OperationError} if invalid mode value * @throws {OperationError} if invalid mode value
*/ */
run(input, args) { run(input, args) {
const mode = args[0], const [
compatibility = args[1], mode,
codeSegment = args[2], compatibility,
offset = args[3], codeSegment,
showInstructionHex = args[4], offset,
showInstructionPos = args[5]; showInstructionHex,
showInstructionPos
] = args;
switch (mode) { switch (mode) {
case "64": case "64":

View File

@ -6,6 +6,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
import { search } from "../lib/Extract"; import { search } from "../lib/Extract";
/** /**
* Extract file paths operation * Extract file paths operation
*/ */
@ -47,9 +48,7 @@ class ExtractFilePaths extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const includeWinPath = args[0], const [includeWinPath, includeUnixPath, displayTotal] = args,
includeUnixPath = args[1],
displayTotal = args[2],
winDrive = "[A-Z]:\\\\", winDrive = "[A-Z]:\\\\",
winName = "[A-Z\\d][A-Z\\d\\- '_\\(\\)~]{0,61}", winName = "[A-Z\\d][A-Z\\d\\- '_\\(\\)~]{0,61}",
winExt = "[A-Z\\d]{1,6}", winExt = "[A-Z\\d]{1,6}",

View File

@ -53,10 +53,7 @@ class ExtractIPAddresses extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const includeIpv4 = args[0], const [includeIpv4, includeIpv6, removeLocal, displayTotal] = args,
includeIpv6 = args[1],
removeLocal = args[2],
displayTotal = args[3],
ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?", ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?",
ipv6 = "((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})((([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})"; ipv6 = "((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})((([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})";
let ips = ""; let ips = "";

View File

@ -11,6 +11,7 @@ import kbpgp from "kbpgp";
import { getSubkeySize, ASP } from "../lib/PGP"; import { getSubkeySize, ASP } from "../lib/PGP";
import promisifyDefault from "es6-promisify"; import promisifyDefault from "es6-promisify";
const promisify = promisifyDefault.promisify; const promisify = promisifyDefault.promisify;
/** /**
* Generate PGP Key Pair operation * Generate PGP Key Pair operation
*/ */

View File

@ -11,7 +11,6 @@ import OperationError from "../errors/OperationError";
import promisifyDefault from "es6-promisify"; import promisifyDefault from "es6-promisify";
const promisify = promisifyDefault.promisify; const promisify = promisifyDefault.promisify;
/** /**
* PGP Decrypt operation * PGP Decrypt operation
*/ */
@ -25,7 +24,16 @@ class PGPDecrypt extends Operation {
this.name = "PGP Decrypt"; this.name = "PGP Decrypt";
this.module = "PGP"; this.module = "PGP";
this.description = "Input: the ASCII-armoured PGP message you want to decrypt.\n<br><br>\nArguments: the ASCII-armoured PGP private key of the recipient, \n(and the private key password if necessary).\n<br><br>\nPretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.\n<br><br>\nThis function uses the Keybase implementation of PGP."; this.description = [
"Input: the ASCII-armoured PGP message you want to decrypt.",
"<br><br>",
"Arguments: the ASCII-armoured PGP private key of the recipient, ",
"(and the private key password if necessary).",
"<br><br>",
"Pretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.",
"<br><br>",
"This function uses the Keybase implementation of PGP.",
].join("\n");
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
@ -51,8 +59,7 @@ class PGPDecrypt extends Operation {
*/ */
async run(input, args) { async run(input, args) {
const encryptedMessage = input, const encryptedMessage = input,
privateKey = args[0], [privateKey, passphrase] = args,
passphrase = args[1],
keyring = new kbpgp.keyring.KeyRing(); keyring = new kbpgp.keyring.KeyRing();
let plaintextMessage; let plaintextMessage;

View File

@ -24,7 +24,18 @@ class PGPDecryptAndVerify extends Operation {
this.name = "PGP Decrypt and Verify"; this.name = "PGP Decrypt and Verify";
this.module = "PGP"; this.module = "PGP";
this.description = "Input: the ASCII-armoured encrypted PGP message you want to verify.\n<br><br>\nArguments: the ASCII-armoured PGP public key of the signer, \nthe ASCII-armoured private key of the recipient (and the private key password if necessary).\n<br><br>\nThis operation uses PGP to decrypt and verify an encrypted digital signature.\n<br><br>\nPretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.\n<br><br>\nThis function uses the Keybase implementation of PGP."; this.description = [
"Input: the ASCII-armoured encrypted PGP message you want to verify.",
"<br><br>",
"Arguments: the ASCII-armoured PGP public key of the signer, ",
"the ASCII-armoured private key of the recipient (and the private key password if necessary).",
"<br><br>",
"This operation uses PGP to decrypt and verify an encrypted digital signature.",
"<br><br>",
"Pretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.",
"<br><br>",
"This function uses the Keybase implementation of PGP.",
].join("\n");
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
@ -53,9 +64,7 @@ class PGPDecryptAndVerify extends Operation {
*/ */
async run(input, args) { async run(input, args) {
const signedMessage = input, const signedMessage = input,
publicKey = args[0], [publicKey, privateKey, passphrase] = args,
privateKey = args[1],
passphrase = args[2],
keyring = new kbpgp.keyring.KeyRing(); keyring = new kbpgp.keyring.KeyRing();
let unboxedLiterals; let unboxedLiterals;

View File

@ -24,7 +24,15 @@ class PGPEncrypt extends Operation {
this.name = "PGP Encrypt"; this.name = "PGP Encrypt";
this.module = "PGP"; this.module = "PGP";
this.description = "Input: the message you want to encrypt.\n<br><br>\nArguments: the ASCII-armoured PGP public key of the recipient.\n<br><br>\nPretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.\n<br><br>\nThis function uses the Keybase implementation of PGP."; this.description = [
"Input: the message you want to encrypt.",
"<br><br>",
"Arguments: the ASCII-armoured PGP public key of the recipient.",
"<br><br>",
"Pretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.",
"<br><br>",
"This function uses the Keybase implementation of PGP.",
].join("\n");
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [

View File

@ -24,7 +24,18 @@ class PGPEncryptAndSign extends Operation {
this.name = "PGP Encrypt and Sign"; this.name = "PGP Encrypt and Sign";
this.module = "PGP"; this.module = "PGP";
this.description = "Input: the cleartext you want to sign.\n<br><br>\nArguments: the ASCII-armoured private key of the signer (plus the private key password if necessary)\nand the ASCII-armoured PGP public key of the recipient.\n<br><br>\nThis operation uses PGP to produce an encrypted digital signature.\n<br><br>\nPretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.\n<br><br>\nThis function uses the Keybase implementation of PGP."; this.description = [
"Input: the cleartext you want to sign.",
"<br><br>",
"Arguments: the ASCII-armoured private key of the signer (plus the private key password if necessary)",
"and the ASCII-armoured PGP public key of the recipient.",
"<br><br>",
"This operation uses PGP to produce an encrypted digital signature.",
"<br><br>",
"Pretty Good Privacy is an encryption standard (OpenPGP) used for encrypting, decrypting, and signing messages.",
"<br><br>",
"This function uses the Keybase implementation of PGP.",
].join("\n");
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
@ -55,9 +66,7 @@ class PGPEncryptAndSign extends Operation {
*/ */
async run(input, args) { async run(input, args) {
const message = input, const message = input,
privateKey = args[0], [privateKey, passphrase, publicKey] = args;
passphrase = args[1],
publicKey = args[2];
let signedMessage; let signedMessage;
if (!privateKey) throw new OperationError("Enter the private key of the signer."); if (!privateKey) throw new OperationError("Enter the private key of the signer.");

View File

@ -7,6 +7,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
import XRegExp from "xregexp"; import XRegExp from "xregexp";
import { search } from "../lib/Extract"; import { search } from "../lib/Extract";
/** /**
* Strings operation * Strings operation
*/ */
@ -56,10 +57,7 @@ class Strings extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const encoding = args[0], const [encoding, minLen, matchType, displayTotal] = args,
minLen = args[1],
matchType = args[2],
displayTotal = args[3],
alphanumeric = "A-Z\\d", alphanumeric = "A-Z\\d",
punctuation = "/\\-:.,_$%'\"()<>= !\\[\\]{}@", punctuation = "/\\-:.,_$%'\"()<>= !\\[\\]{}@",
printable = "\x20-\x7e", printable = "\x20-\x7e",

View File

@ -48,7 +48,7 @@ class URLEncode extends Operation {
* @returns {string} * @returns {string}
*/ */
encodeAllChars (str) { encodeAllChars (str) {
//TODO Do this programatically // TODO Do this programatically
return encodeURIComponent(str) return encodeURIComponent(str)
.replace(/!/g, "%21") .replace(/!/g, "%21")
.replace(/#/g, "%23") .replace(/#/g, "%23")

View File

@ -1,6 +1,5 @@
const webpack = require("webpack"); const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin"); const ExtractTextPlugin = require("extract-text-webpack-plugin");
const WebpackSyncShellPlugin = require("webpack-synchronizable-shell-plugin");
/** /**
* Webpack configuration details for use with Grunt. * Webpack configuration details for use with Grunt.
@ -43,19 +42,7 @@ module.exports = {
raw: true, raw: true,
entryOnly: true entryOnly: true
}), }),
new ExtractTextPlugin("styles.css"), new ExtractTextPlugin("styles.css")
new WebpackSyncShellPlugin({
onBuildStart: {
scripts: [
"echo \n--- Generating config files. ---",
"node --experimental-modules src/core/config/scripts/generateOpsIndex.mjs",
"node --experimental-modules src/core/config/scripts/generateConfig.mjs",
"echo --- Config scripts finished. ---\n"
],
blocking: true,
parallel: false
}
})
], ],
resolve: { resolve: {
alias: { alias: {