-
Notifications
You must be signed in to change notification settings - Fork 0
/
refang.go
46 lines (34 loc) · 987 Bytes
/
refang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package defang
import (
"net"
"net/url"
"regexp"
"strings"
"github.com/pkg/errors"
)
// Refang takes a defanged IOC and returns it to it's original form
func Refang(input interface{}) (string, error) {
var output string
switch i := input.(type) {
case string:
output = i
case net.IP:
output = i.String()
case url.URL:
output = i.String()
default:
return "", errors.New("unknown type")
}
output = strings.ToLower(output)
re := regexp.MustCompile(`(?i)^(?:hxxp|nsfw|evil|meow)`)
output = re.ReplaceAllString(output, "http")
output = strings.Replace(output, "[.]", ".", -1)
output = strings.Replace(output, "(.)", ".", -1)
output = strings.Replace(output, "<.>", ".", -1)
dotRE := regexp.MustCompile(`(?i)[\[<(]dot[\]>)]`)
output = dotRE.ReplaceAllString(output, ".")
output = strings.Replace(output, "[//]", "//", -1)
output = strings.Replace(output, "<//>", "//", -1)
output = strings.Replace(output, "httpx", "https", -1)
return output, nil
}