Skip to content

Commit c35557a

Browse files
committed
Merge branch 'master' of https://github.com/gchq/CyberChef
2 parents b5959c6 + 2000938 commit c35557a

File tree

8 files changed

+785
-1
lines changed

8 files changed

+785
-1
lines changed

src/core/config/Categories.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@
179179
"RSA Verify",
180180
"RSA Encrypt",
181181
"RSA Decrypt",
182-
"Parse SSH Host Key"
182+
"Parse SSH Host Key",
183+
"Parse CSR"
183184
]
184185
},
185186
{
@@ -321,6 +322,7 @@
321322
"To UNIX Timestamp",
322323
"Windows Filetime to UNIX Timestamp",
323324
"UNIX Timestamp to Windows Filetime",
325+
"DateTime Delta",
324326
"Extract dates",
325327
"Get Time",
326328
"Sleep"
@@ -337,6 +339,7 @@
337339
"Extract domains",
338340
"Extract file paths",
339341
"Extract dates",
342+
"Extract hashes",
340343
"Regular expression",
341344
"XPath expression",
342345
"JPath expression",

src/core/operations/DateTimeDelta.mjs

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @author tomgond [[email protected]]
3+
* @copyright Crown Copyright 2024
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import moment from "moment-timezone";
9+
import {DATETIME_FORMATS, FORMAT_EXAMPLES} from "../lib/DateTime.mjs";
10+
11+
/**
12+
* DateTime Delta operation
13+
*/
14+
class DateTimeDelta extends Operation {
15+
16+
/**
17+
* DateTimeDelta constructor
18+
*/
19+
constructor() {
20+
super();
21+
22+
this.name = "DateTime Delta";
23+
this.module = "Default";
24+
this.description = "Calculates a new DateTime value given an input DateTime value and a time difference (delta) from the input DateTime value.";
25+
this.infoURL = "";
26+
this.inputType = "string";
27+
this.outputType = "html";
28+
this.args = [
29+
{
30+
"name": "Built in formats",
31+
"type": "populateOption",
32+
"value": DATETIME_FORMATS,
33+
"target": 1
34+
},
35+
{
36+
"name": "Input format string",
37+
"type": "binaryString",
38+
"value": "DD/MM/YYYY HH:mm:ss"
39+
},
40+
{
41+
"name": "Time Operation",
42+
"type": "option",
43+
"value": ["Add", "Subtract"]
44+
},
45+
{
46+
"name": "Days",
47+
"type": "number",
48+
"value": 0
49+
},
50+
{
51+
"name": "Hours",
52+
"type": "number",
53+
"value": 0
54+
},
55+
{
56+
"name": "Minutes",
57+
"type": "number",
58+
"value": 0
59+
},
60+
{
61+
"name": "Seconds",
62+
"type": "number",
63+
"value": 0
64+
}
65+
66+
];
67+
}
68+
69+
70+
/**
71+
* @param {string} input
72+
* @param {Object[]} args
73+
* @returns {string}
74+
*/
75+
run(input, args) {
76+
const inputTimezone = "UTC";
77+
const inputFormat = args[1];
78+
const operationType = args[2];
79+
const daysDelta = args[3];
80+
const hoursDelta = args[4];
81+
const minutesDelta = args[5];
82+
const secondsDelta = args[6];
83+
let date = "";
84+
85+
try {
86+
date = moment.tz(input, inputFormat, inputTimezone);
87+
if (!date || date.format() === "Invalid date") throw Error;
88+
} catch (err) {
89+
return `Invalid format.\n\n${FORMAT_EXAMPLES}`;
90+
}
91+
let newDate;
92+
if (operationType === "Add") {
93+
newDate = date.add(daysDelta, "days")
94+
.add(hoursDelta, "hours")
95+
.add(minutesDelta, "minutes")
96+
.add(secondsDelta, "seconds");
97+
98+
} else {
99+
newDate = date.add(-daysDelta, "days")
100+
.add(-hoursDelta, "hours")
101+
.add(-minutesDelta, "minutes")
102+
.add(-secondsDelta, "seconds");
103+
}
104+
return newDate.tz(inputTimezone).format(inputFormat.replace(/[<>]/g, ""));
105+
}
106+
}
107+
108+
export default DateTimeDelta;

src/core/operations/ExtractHashes.mjs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @author mshwed [[email protected]]
3+
* @copyright Crown Copyright 2019
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import { search } from "../lib/Extract.mjs";
9+
10+
/**
11+
* Extract Hash Values operation
12+
*/
13+
class ExtractHashes extends Operation {
14+
15+
/**
16+
* ExtractHashValues constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "Extract hashes";
22+
this.module = "Regex";
23+
this.description = "Extracts potential hashes based on hash character length";
24+
this.infoURL = "https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions";
25+
this.inputType = "string";
26+
this.outputType = "string";
27+
this.args = [
28+
{
29+
name: "Hash character length",
30+
type: "number",
31+
value: 40
32+
},
33+
{
34+
name: "All hashes",
35+
type: "boolean",
36+
value: false
37+
},
38+
{
39+
name: "Display Total",
40+
type: "boolean",
41+
value: false
42+
}
43+
];
44+
}
45+
46+
/**
47+
* @param {string} input
48+
* @param {Object[]} args
49+
* @returns {string}
50+
*/
51+
run(input, args) {
52+
const results = [];
53+
let hashCount = 0;
54+
55+
const [hashLength, searchAllHashes, showDisplayTotal] = args;
56+
57+
// Convert character length to bit length
58+
let hashBitLengths = [(hashLength / 2) * 8];
59+
60+
if (searchAllHashes) hashBitLengths = [4, 8, 16, 32, 64, 128, 160, 192, 224, 256, 320, 384, 512, 1024];
61+
62+
for (const hashBitLength of hashBitLengths) {
63+
// Convert bit length to character length
64+
const hashCharacterLength = (hashBitLength / 8) * 2;
65+
66+
const regex = new RegExp(`(\\b|^)[a-f0-9]{${hashCharacterLength}}(\\b|$)`, "g");
67+
const searchResults = search(input, regex, null, false);
68+
69+
hashCount += searchResults.length;
70+
results.push(...searchResults);
71+
}
72+
73+
let output = "";
74+
if (showDisplayTotal) {
75+
output = `Total Results: ${hashCount}\n\n`;
76+
}
77+
78+
output = output + results.join("\n");
79+
return output;
80+
}
81+
82+
}
83+
84+
export default ExtractHashes;

0 commit comments

Comments
 (0)