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
grunt.registerTask("dev",
"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",
"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-dev-server": "^3.1.3",
"webpack-node-externals": "^1.7.2",
"webpack-synchronizable-shell-plugin": "0.0.7",
"worker-loader": "^1.1.1"
},
"dependencies": {

View File

@ -177,7 +177,10 @@ class Recipe {
}
} catch (err) {
// 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");
return i;
} else {

View File

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

View File

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

View File

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

View File

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

View File

@ -53,10 +53,7 @@ class ExtractIPAddresses extends Operation {
* @returns {string}
*/
run(input, args) {
const includeIpv4 = args[0],
includeIpv6 = args[1],
removeLocal = args[2],
displayTotal = args[3],
const [includeIpv4, includeIpv6, removeLocal, displayTotal] = args,
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})";
let ips = "";

View File

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

View File

@ -11,7 +11,6 @@ import OperationError from "../errors/OperationError";
import promisifyDefault from "es6-promisify";
const promisify = promisifyDefault.promisify;
/**
* PGP Decrypt operation
*/
@ -25,7 +24,16 @@ class PGPDecrypt extends Operation {
this.name = "PGP Decrypt";
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.outputType = "string";
this.args = [
@ -51,8 +59,7 @@ class PGPDecrypt extends Operation {
*/
async run(input, args) {
const encryptedMessage = input,
privateKey = args[0],
passphrase = args[1],
[privateKey, passphrase] = args,
keyring = new kbpgp.keyring.KeyRing();
let plaintextMessage;

View File

@ -24,7 +24,18 @@ class PGPDecryptAndVerify extends Operation {
this.name = "PGP Decrypt and Verify";
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.outputType = "string";
this.args = [
@ -53,9 +64,7 @@ class PGPDecryptAndVerify extends Operation {
*/
async run(input, args) {
const signedMessage = input,
publicKey = args[0],
privateKey = args[1],
passphrase = args[2],
[publicKey, privateKey, passphrase] = args,
keyring = new kbpgp.keyring.KeyRing();
let unboxedLiterals;

View File

@ -24,7 +24,15 @@ class PGPEncrypt extends Operation {
this.name = "PGP Encrypt";
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.outputType = "string";
this.args = [

View File

@ -24,7 +24,18 @@ class PGPEncryptAndSign extends Operation {
this.name = "PGP Encrypt and Sign";
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.outputType = "string";
this.args = [
@ -55,9 +66,7 @@ class PGPEncryptAndSign extends Operation {
*/
async run(input, args) {
const message = input,
privateKey = args[0],
passphrase = args[1],
publicKey = args[2];
[privateKey, passphrase, publicKey] = args;
let signedMessage;
if (!privateKey) throw new OperationError("Enter the private key of the signer.");

View File

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

View File

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

View File

@ -1,6 +1,5 @@
const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const WebpackSyncShellPlugin = require("webpack-synchronizable-shell-plugin");
/**
* Webpack configuration details for use with Grunt.
@ -43,19 +42,7 @@ module.exports = {
raw: true,
entryOnly: true
}),
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
}
})
new ExtractTextPlugin("styles.css")
],
resolve: {
alias: {