1
0
mirror of synced 2024-11-30 17:34:27 +01:00

Operation: Added extract hash feature

This commit is contained in:
mshwed 2019-03-11 09:32:44 -04:00 committed by mshwed
parent 866c9a94ae
commit 1b16c26699
2 changed files with 82 additions and 0 deletions

View File

@ -337,6 +337,7 @@
"Extract domains",
"Extract file paths",
"Extract dates",
"Extract Hashes",
"Regular expression",
"XPath expression",
"JPath expression",

View File

@ -0,0 +1,81 @@
/**
* @author mshwed [m@ttshwed.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation";
import { search } from "../lib/Extract";
/**
* Extract Hash Values operation
*/
class ExtractHashes extends Operation {
/**
* ExtractHashValues constructor
*/
constructor() {
super();
this.name = "Extract Hashes";
this.module = "Default";
this.description = "Extracts hash values based on hash byte length";
this.infoURL = "https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Hash length",
type: "number",
value: 32
},
{
name: "All hashes",
type: "boolean",
value: false
},
{
name: "Display Total",
type: "boolean",
value: false
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
let results = [];
let hashCount = 0;
const hashLength = args[0];
const searchAllHashes = args[1];
const showDisplayTotal = args[2];
let hashLengths = [hashLength];
if (searchAllHashes) hashLengths = [4, 8, 16, 32, 64, 128, 160, 192, 224, 256, 320, 384, 512, 1024];
for (let hashLength of hashLengths) {
const regex = new RegExp(`(\\b|^)[a-f0-9]{${hashLength}}(\\b|$)`, "g");
const searchResults = search(input, regex, null, false);
hashCount += searchResults.split("\n").length - 1;
results.push(searchResults);
}
let output = "";
if (showDisplayTotal) {
output = `Total Results: ${hashCount}\n\n`;
}
output = output + results.join("");
return output;
}
}
export default ExtractHashes;