CyberChef/src/core/operations/FangURL.mjs

79 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-10-02 15:58:28 +02:00
/**
* @author arnydo [github@arnydo.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* FangURL operation
*/
class FangURL extends Operation {
/**
* FangURL constructor
*/
constructor() {
super();
this.name = "Fang URL";
this.module = "Default";
this.description = "Takes a 'Defanged' Universal Resource Locator (URL) and 'Fangs' it. Meaning, it removes the alterations (defanged) that render it useless so that it can be used again.";
2024-04-05 19:10:57 +02:00
this.infoURL = "https://isc.sans.edu/forums/diary/Defang+all+the+things/22744/";
2019-10-02 15:58:28 +02:00
this.inputType = "string";
this.outputType = "string";
this.args = [
{
2024-03-30 15:20:28 +01:00
name: "Restore [.]",
2019-10-02 15:58:28 +02:00
type: "boolean",
value: true
},
{
2024-03-30 15:20:28 +01:00
name: "Restore hxxp",
2019-10-02 15:58:28 +02:00
type: "boolean",
value: true
},
{
2024-03-30 15:20:28 +01:00
name: "Restore ://",
2019-10-02 15:58:28 +02:00
type: "boolean",
value: true
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [dots, http, slashes] = args;
input = fangURL(input, dots, http, slashes);
return input;
}
}
/**
* Defangs a given URL
*
* @param {string} url
* @param {boolean} dots
* @param {boolean} http
* @param {boolean} slashes
* @returns {string}
*/
function fangURL(url, dots, http, slashes) {
if (dots) url = url.replace(/\[\.\]/g, ".");
if (http) url = url.replace(/hxxp/g, "http");
2024-03-30 15:20:28 +01:00
if (slashes) url = url.replace(/\[:\/\/\]/g, "://");
2019-10-02 15:58:28 +02:00
return url;
}
export default FangURL;