mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added various options to the 'Defang URL' operation.
This commit is contained in:
parent
253346a201
commit
53c500eb1b
6 changed files with 100 additions and 28 deletions
|
@ -1,10 +1,12 @@
|
|||
/**
|
||||
* @author arnydo [arnydo@protonmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import {URL_REGEX, DOMAIN_REGEX} from "../lib/Extract";
|
||||
|
||||
/**
|
||||
* DefangURL operation
|
||||
|
@ -18,12 +20,33 @@ class DefangURL extends Operation {
|
|||
super();
|
||||
|
||||
this.name = "Defang URL";
|
||||
this.module = "URL";
|
||||
this.description = "Takes a Universal Resource Locator (URL) and 'Defangs' it; meaning, the URL becomes invalid and neutralizes the risk of accidentally clicking on a malicious link.<br><br>This is often used when dealing with malicious links or IOCs.<br><br>Works well when combined with the 'Extract URLs' operation.";
|
||||
this.infoURL = "";
|
||||
this.module = "Default";
|
||||
this.description = "Takes a Universal Resource Locator (URL) and 'Defangs' it; meaning the URL becomes invalid, neutralising the risk of accidentally clicking on a malicious link.<br><br>This is often used when dealing with malicious links or IOCs.<br><br>Works well when combined with the 'Extract URLs' operation.";
|
||||
this.infoURL = "https://isc.sans.edu/forums/diary/Defang+all+the+things/22744/";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
name: "Escape dots",
|
||||
type: "boolean",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: "Escape http",
|
||||
type: "boolean",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: "Escape ://",
|
||||
type: "boolean",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: "Process",
|
||||
type: "option",
|
||||
value: ["Valid domains and full URLs", "Only full URLs", "Everything"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,12 +55,48 @@ class DefangURL extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let defang = input.replace(/http/gi, "hxxp");
|
||||
defang = defang.replace(/\./g, "[.]");
|
||||
defang = defang.replace(/:\/\//g, "[://]");
|
||||
return defang;
|
||||
const [dots, http, slashes, process] = args;
|
||||
|
||||
switch (process) {
|
||||
case "Valid domains and full URLs":
|
||||
input = input.replace(URL_REGEX, x => {
|
||||
return defangURL(x, dots, http, slashes);
|
||||
});
|
||||
input = input.replace(DOMAIN_REGEX, x => {
|
||||
return defangURL(x, dots, http, slashes);
|
||||
});
|
||||
break;
|
||||
case "Only full URLs":
|
||||
input = input.replace(URL_REGEX, x => {
|
||||
return defangURL(x, dots, http, slashes);
|
||||
});
|
||||
break;
|
||||
case "Everything":
|
||||
input = defangURL(input, dots, http, slashes);
|
||||
break;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defangs a given URL
|
||||
*
|
||||
* @param {string} url
|
||||
* @param {boolean} dots
|
||||
* @param {boolean} http
|
||||
* @param {boolean} slashes
|
||||
* @returns {string}
|
||||
*/
|
||||
function defangURL(url, dots, http, slashes) {
|
||||
if (dots) url = url.replace(/\./g, "[.]");
|
||||
if (http) url = url.replace(/http/gi, "hxxp");
|
||||
if (slashes) url = url.replace(/:\/\//g, "[://]");
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
export default DefangURL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue