mirror of
https://github.com/gchq/CyberChef.git
synced 2026-02-21 17:21:44 +01:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be231f3a91 | ||
|
|
39f36c9184 | ||
|
|
7e7da26f29 | ||
|
|
4375a151dd | ||
|
|
0f02fb5d05 | ||
|
|
05edc1f9c4 | ||
|
|
2c0f0d9a20 | ||
|
|
d081ff745d | ||
|
|
dea214bd2e | ||
|
|
07bb095e73 | ||
|
|
e409029bb3 | ||
|
|
6201176852 | ||
|
|
7d958cc20e | ||
|
|
68e855e3d2 | ||
|
|
bf91352fce | ||
|
|
a840504b3d | ||
|
|
8d9c114acd | ||
|
|
bce0950498 | ||
|
|
dcac64fb9a |
@@ -1,5 +1,7 @@
|
||||
# CyberChef
|
||||
|
||||
[](https://travis-ci.org/gchq/CyberChef)
|
||||
|
||||
#### *The Cyber Swiss Army Knife*
|
||||
|
||||
CyberChef is a simple, intuitive web app for carrying out all manner of "cyber" operations within a web browser. These operations include creating hexdumps, simple encoding like XOR or Base64, more complex encryption like AES, DES and Blowfish, data compression and decompression, calculating hashes and checksums, IPv6 and X.509 parsing, and much more.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"templates": {
|
||||
"systemName": "CyberChef",
|
||||
"footer": "",
|
||||
"copyright": "© Crown Copyright 2016",
|
||||
"copyright": "© Crown Copyright 2017",
|
||||
"navType": "inline",
|
||||
"theme": "cerulean",
|
||||
"linenums": true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cyberchef",
|
||||
"version": "5.1.3",
|
||||
"version": "5.2.2",
|
||||
"description": "CyberChef is a simple, intuitive web app for analysing and decoding data within a web browser.",
|
||||
"author": "n1474335 <n1474335@gmail.com>",
|
||||
"homepage": "https://gchq.github.io/CyberChef",
|
||||
|
||||
@@ -162,6 +162,8 @@ const Categories = [
|
||||
"Unique",
|
||||
"Split",
|
||||
"Filter",
|
||||
"Head",
|
||||
"Tail",
|
||||
"Count occurrences",
|
||||
"Expand alphabet range",
|
||||
"Parse escaped string",
|
||||
|
||||
@@ -3196,7 +3196,59 @@ const OperationConfig = {
|
||||
outputType: "html",
|
||||
args: [
|
||||
]
|
||||
}
|
||||
},
|
||||
"Head": {
|
||||
description: [
|
||||
"Like the UNIX head utility.",
|
||||
"<br>",
|
||||
"Gets the first n lines.",
|
||||
"<br>",
|
||||
"You can select all but the last n lines by entering a negative value for n.",
|
||||
"<br>",
|
||||
"The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.",
|
||||
].join("\n"),
|
||||
run: StrUtils.runHead,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: StrUtils.DELIMITER_OPTIONS
|
||||
},
|
||||
{
|
||||
name: "Number",
|
||||
type: "number",
|
||||
value: 10,
|
||||
},
|
||||
]
|
||||
},
|
||||
"Tail": {
|
||||
description: [
|
||||
"Like the UNIX tail utility.",
|
||||
"<br>",
|
||||
"Gets the last n lines.",
|
||||
"<br>",
|
||||
"Optionally you can select all lines after line n by entering a negative value for n.",
|
||||
"<br>",
|
||||
"The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.",
|
||||
].join("\n"),
|
||||
run: StrUtils.runTail,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: StrUtils.DELIMITER_OPTIONS
|
||||
},
|
||||
{
|
||||
name: "Number",
|
||||
type: "number",
|
||||
value: 10,
|
||||
},
|
||||
]
|
||||
},
|
||||
};
|
||||
|
||||
export default OperationConfig;
|
||||
|
||||
@@ -225,25 +225,20 @@ const Code = {
|
||||
regexes.lastIndex = m.index;
|
||||
}
|
||||
|
||||
// Create newlines after ;
|
||||
code = code.replace(/;/g, ";\n");
|
||||
|
||||
// Create newlines after { and around }
|
||||
code = code.replace(/{/g, "{\n");
|
||||
code = code.replace(/}/g, "\n}\n");
|
||||
|
||||
// Remove carriage returns
|
||||
code = code.replace(/\r/g, "");
|
||||
|
||||
// Remove all indentation
|
||||
code = code.replace(/^\s+/g, "");
|
||||
code = code.replace(/\n\s+/g, "\n");
|
||||
|
||||
// Remove trailing spaces
|
||||
code = code.replace(/\s*$/g, "");
|
||||
|
||||
// Remove newlines before {
|
||||
code = code.replace(/\n{/g, "{");
|
||||
code = code
|
||||
// Create newlines after ;
|
||||
.replace(/;/g, ";\n")
|
||||
// Create newlines after { and around }
|
||||
.replace(/{/g, "{\n")
|
||||
.replace(/}/g, "\n}\n")
|
||||
// Remove carriage returns
|
||||
.replace(/\r/g, "")
|
||||
// Remove all indentation
|
||||
.replace(/^\s+/g, "")
|
||||
.replace(/\n\s+/g, "\n")
|
||||
// Remove trailing spaces
|
||||
.replace(/\s*$/g, "")
|
||||
.replace(/\n{/g, "{");
|
||||
|
||||
// Indent
|
||||
var i = 0,
|
||||
@@ -266,30 +261,28 @@ const Code = {
|
||||
i++;
|
||||
}
|
||||
|
||||
// Add strategic spaces
|
||||
code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ");
|
||||
code = code.replace(/\s*<([=]?)\s*/g, " <$1 ");
|
||||
code = code.replace(/\s*>([=]?)\s*/g, " >$1 ");
|
||||
code = code.replace(/([^+])\+([^+=])/g, "$1 + $2");
|
||||
code = code.replace(/([^-])-([^-=])/g, "$1 - $2");
|
||||
code = code.replace(/([^*])\*([^*=])/g, "$1 * $2");
|
||||
code = code.replace(/([^/])\/([^/=])/g, "$1 / $2");
|
||||
code = code.replace(/\s*,\s*/g, ", ");
|
||||
code = code.replace(/\s*{/g, " {");
|
||||
code = code.replace(/}\n/g, "}\n\n");
|
||||
|
||||
// Just... don't look at this
|
||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3");
|
||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3");
|
||||
code = code.replace(/else\s*\n([^{])/gim, "else\n $1");
|
||||
code = code.replace(/else\s+([^{])/gim, "else $1");
|
||||
|
||||
// Remove strategic spaces
|
||||
code = code.replace(/\s+;/g, ";");
|
||||
code = code.replace(/\{\s+\}/g, "{}");
|
||||
code = code.replace(/\[\s+\]/g, "[]");
|
||||
code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
|
||||
|
||||
code = code
|
||||
// Add strategic spaces
|
||||
.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ")
|
||||
.replace(/\s*<([=]?)\s*/g, " <$1 ")
|
||||
.replace(/\s*>([=]?)\s*/g, " >$1 ")
|
||||
.replace(/([^+])\+([^+=])/g, "$1 + $2")
|
||||
.replace(/([^-])-([^-=])/g, "$1 - $2")
|
||||
.replace(/([^*])\*([^*=])/g, "$1 * $2")
|
||||
.replace(/([^/])\/([^/=])/g, "$1 / $2")
|
||||
.replace(/\s*,\s*/g, ", ")
|
||||
.replace(/\s*{/g, " {")
|
||||
.replace(/}\n/g, "}\n\n")
|
||||
// Hacky horribleness
|
||||
.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3")
|
||||
.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3")
|
||||
.replace(/else\s*\n([^{])/gim, "else\n $1")
|
||||
.replace(/else\s+([^{])/gim, "else $1")
|
||||
// Remove strategic spaces
|
||||
.replace(/\s+;/g, ";")
|
||||
.replace(/\{\s+\}/g, "{}")
|
||||
.replace(/\[\s+\]/g, "[]")
|
||||
.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
|
||||
|
||||
// Replace preserved tokens
|
||||
var ptokens = /###preservedToken(\d+)###/g;
|
||||
|
||||
@@ -460,6 +460,62 @@ const StrUtils = {
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Head lines operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runHead: function(input, args) {
|
||||
let delimiter = args[0],
|
||||
number = args[1];
|
||||
|
||||
delimiter = Utils.charRep[delimiter];
|
||||
let splitInput = input.split(delimiter);
|
||||
|
||||
return splitInput
|
||||
.filter((line, lineIndex) => {
|
||||
lineIndex += 1;
|
||||
|
||||
if (number < 0) {
|
||||
return lineIndex <= splitInput.length + number;
|
||||
} else {
|
||||
return lineIndex <= number;
|
||||
}
|
||||
})
|
||||
.join(delimiter);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Tail lines operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runTail: function(input, args) {
|
||||
let delimiter = args[0],
|
||||
number = args[1];
|
||||
|
||||
delimiter = Utils.charRep[delimiter];
|
||||
let splitInput = input.split(delimiter);
|
||||
|
||||
return splitInput
|
||||
.filter((line, lineIndex) => {
|
||||
lineIndex += 1;
|
||||
|
||||
if (number < 0) {
|
||||
return lineIndex > -number;
|
||||
} else {
|
||||
return lineIndex > splitInput.length - number;
|
||||
}
|
||||
})
|
||||
.join(delimiter);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Adds HTML highlights to matches within a string.
|
||||
*
|
||||
|
||||
@@ -244,7 +244,7 @@ ControlsWaiter.prototype.loadClick = function() {
|
||||
* Saves the recipe specified in the save textarea to local storage.
|
||||
*/
|
||||
ControlsWaiter.prototype.saveButtonClick = function() {
|
||||
var recipeName = document.getElementById("save-name").value,
|
||||
var recipeName = Utils.escapeHtml(document.getElementById("save-name").value),
|
||||
recipeStr = document.getElementById("save-text").value;
|
||||
|
||||
if (!recipeName) {
|
||||
@@ -288,7 +288,8 @@ ControlsWaiter.prototype.populateLoadRecipesList = function() {
|
||||
for (i = 0; i < savedRecipes.length; i++) {
|
||||
var opt = document.createElement("option");
|
||||
opt.value = savedRecipes[i].id;
|
||||
opt.innerHTML = savedRecipes[i].name;
|
||||
// Unescape then re-escape in case localStorage has been corrupted
|
||||
opt.innerHTML = Utils.escapeHtml(Utils.unescapeHtml(savedRecipes[i].name));
|
||||
|
||||
loadNameEl.appendChild(opt);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ var RecipeWaiter = function(app, manager) {
|
||||
RecipeWaiter.prototype.initialiseOperationDragNDrop = function() {
|
||||
var recList = document.getElementById("rec-list");
|
||||
|
||||
|
||||
// Recipe list
|
||||
Sortable.create(recList, {
|
||||
group: "recipe",
|
||||
@@ -45,7 +44,9 @@ RecipeWaiter.prototype.initialiseOperationDragNDrop = function() {
|
||||
}
|
||||
}.bind(this),
|
||||
onSort: function(evt) {
|
||||
document.dispatchEvent(this.manager.statechange);
|
||||
if (evt.from.id === "rec-list") {
|
||||
document.dispatchEvent(this.manager.statechange);
|
||||
}
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
|
||||
@@ -34,4 +34,202 @@ TestRegister.addTests([
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head 0",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head 1",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", 1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head 2",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", 2]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head 6",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", 6]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head big",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", 100]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head all but 1",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4, 5].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", -1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head all but 2",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", -2]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head all but 6",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", -6]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Head all but big",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Head",
|
||||
"args": ["Line feed", -100]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail 0",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail 1",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", 1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail 2",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", 2]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail 6",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", 6]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail big",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", 100]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail all but 1",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [2, 3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", -1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail all but 2",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [3, 4, 5, 6].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", -2]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail all but 6",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", -6]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Tail all but big",
|
||||
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
||||
expectedOutput: [].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Tail",
|
||||
"args": ["Line feed", -100]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user