2019-05-11 21:24:39 +02:00
/ * *
* @ author h345983745
* @ copyright Crown Copyright 2019
* @ license Apache - 2.0
* /
2019-11-06 14:01:52 +01:00
import Operation from "../Operation.mjs" ;
2019-05-11 21:24:39 +02:00
/ * *
2019-08-13 15:23:41 +02:00
* Defang IP Addresses operation
2019-05-11 21:24:39 +02:00
* /
2019-08-13 15:23:41 +02:00
class DefangIPAddresses extends Operation {
2019-05-11 21:24:39 +02:00
/ * *
2019-08-13 15:23:41 +02:00
* DefangIPAddresses constructor
2019-05-11 21:24:39 +02:00
* /
constructor ( ) {
super ( ) ;
2019-08-13 15:23:41 +02:00
this . name = "Defang IP Addresses" ;
2019-05-11 21:24:39 +02:00
this . module = "Default" ;
2019-08-13 15:23:41 +02:00
this . description = "Takes a IPv4 or IPv6 address and 'Defangs' it, meaning the IP becomes invalid, removing the risk of accidentally utilising it as an IP address." ;
2019-05-11 21:24:39 +02:00
this . infoURL = "https://isc.sans.edu/forums/diary/Defang+all+the+things/22744/" ;
this . inputType = "string" ;
this . outputType = "string" ;
2019-06-29 02:12:50 +02:00
this . args = [ ] ;
2019-05-11 21:24:39 +02:00
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2019-06-29 02:12:50 +02:00
input = input . replace ( IPV4 _REGEX , x => {
return x . replace ( /\./g , "[.]" ) ;
} ) ;
input = input . replace ( IPV6 _REGEX , x => {
return x . replace ( /:/g , "[:]" ) ;
} ) ;
2019-05-11 21:24:39 +02:00
return input ;
}
}
2019-08-13 15:23:41 +02:00
export default DefangIPAddresses ;
2019-05-11 21:24:39 +02:00
/ * *
* IPV4 regular expression
* /
const IPV4 _REGEX = new RegExp ( "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?" , "g" ) ;
/ * *
* IPV6 regular expression
* /
const IPV6 _REGEX = new RegExp ( "((?=.*::)(?!.*::.+::)(::)?([\\dA-Fa-f]{1,4}:(:|\\b)|){5}|([\\dA-Fa-f]{1,4}:){6})((([\\dA-Fa-f]{1,4}((?!\\3)::|:\\b|(?![\\dA-Fa-f])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})" , "g" ) ;