Skip to content

Commit

Permalink
add support for <DOT> refanging
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewarren committed Nov 21, 2019
1 parent 58edc35 commit 6e0757f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions refang.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ func Refang(input interface{}) (string, error) {
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)
output = strings.Replace(output, "(dot)", ".", -1)
output = strings.Replace(output, "[dot]", ".", -1)
output = strings.Replace(output, "<dot>", ".", -1)

dotRE := regexp.MustCompile(`(?i)[\[<(]dot[\]>)]`)
output = dotRE.ReplaceAllString(output, ".")

output = strings.Replace(output, "[//]", "//", -1)
output = strings.Replace(output, "<//>", "//", -1)

Expand Down
1 change: 1 addition & 0 deletions refang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestRefang(t *testing.T) {
{"dots word in angle brackets", args{"hxxps://google<dot>com"}, "https://google.com", false},
{"dots in angle brackets", args{"hxxps://google<.>com"}, "https://google.com", false},
{"slashes brackets", args{"hxxps:[//]google<.>com"}, "https://google.com", false},
{"url with <DOT>", args{"HXXPS://www.nist<DOT>gov/news-events/news/2019/11/nist-seeking-input-updates-nice-cybersecurity-workforce-framework"}, "https://www.nist.gov/news-events/news/2019/11/nist-seeking-input-updates-nice-cybersecurity-workforce-framework", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 6e0757f

Please sign in to comment.