Skip to content

Commit a1f6960

Browse files
authored
Merge pull request #1761 from gchq/origin/add_fangurl
2 parents acce7ca + 2784978 commit a1f6960

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/core/config/Categories.json

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
"Encode NetBIOS Name",
243243
"Decode NetBIOS Name",
244244
"Defang URL",
245+
"Fang URL",
245246
"Defang IP Addresses"
246247
]
247248
},

src/core/operations/FangURL.mjs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @author arnydo [[email protected]]
3+
* @copyright Crown Copyright 2019
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
9+
/**
10+
* FangURL operation
11+
*/
12+
class FangURL extends Operation {
13+
14+
/**
15+
* FangURL constructor
16+
*/
17+
constructor() {
18+
super();
19+
20+
this.name = "Fang URL";
21+
this.module = "Default";
22+
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.";
23+
this.inputType = "string";
24+
this.outputType = "string";
25+
this.args = [
26+
{
27+
name: "Restore [.]",
28+
type: "boolean",
29+
value: true
30+
},
31+
{
32+
name: "Restore hxxp",
33+
type: "boolean",
34+
value: true
35+
},
36+
{
37+
name: "Restore ://",
38+
type: "boolean",
39+
value: true
40+
}
41+
];
42+
}
43+
44+
/**
45+
* @param {string} input
46+
* @param {Object[]} args
47+
* @returns {string}
48+
*/
49+
run(input, args) {
50+
const [dots, http, slashes] = args;
51+
52+
input = fangURL(input, dots, http, slashes);
53+
54+
return input;
55+
}
56+
57+
}
58+
59+
60+
/**
61+
* Defangs a given URL
62+
*
63+
* @param {string} url
64+
* @param {boolean} dots
65+
* @param {boolean} http
66+
* @param {boolean} slashes
67+
* @returns {string}
68+
*/
69+
function fangURL(url, dots, http, slashes) {
70+
if (dots) url = url.replace(/\[\.\]/g, ".");
71+
if (http) url = url.replace(/hxxp/g, "http");
72+
if (slashes) url = url.replace(/\[:\/\/\]/g, "://");
73+
74+
return url;
75+
}
76+
77+
export default FangURL;

0 commit comments

Comments
 (0)