Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter uagents #171

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/update-useragent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"log"
"net/http"
"os"
"regexp"

"github.com/projectdiscovery/useragent"
sliceutil "github.com/projectdiscovery/utils/slice"
stringsutil "github.com/projectdiscovery/utils/strings"
)

var (
Expand Down Expand Up @@ -70,6 +72,17 @@ func getUserAgents() []*useragent.UserAgent {
continue
}
for _, userAgent := range whatismybrowserResponse.SearchResults.UserAgents {
if stringsutil.ContainsAnyI(userAgent.UserAgent,
"sleep", "timeout", "get-help", "start", "system",
"Functionize", "Edg/", "assetnote", "gzip", "norton",
"avast", "ccleaner", "avg", "xtpt", "promptmanager", "SznProhlizec",
"(0-0)", "unknown", "ddg", "opx", "RDDocuments", "Reeder",
"Topee", "TulipSAT", "Opendium", "DingTalk", "Gear",
"GoodAccess", "uacq") ||
hasUidSuffix(userAgent.UserAgent) {
continue
}

tags := buildTags(userAgent)
userAgent := &useragent.UserAgent{
Raw: userAgent.UserAgent,
Expand All @@ -81,6 +94,11 @@ func getUserAgents() []*useragent.UserAgent {
return userAgents
}

func hasUidSuffix(s string) bool {
var guidPattern = regexp.MustCompile(`\(?[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\)?$`)
return guidPattern.MatchString(s)
}

func buildTags(userAgent UserAgents) []string {
var tags []string
tags = append(tags, userAgent.Parse.SimpleSoftwareString)
Expand Down
2 changes: 1 addition & 1 deletion useragent_data.json

Large diffs are not rendered by default.

Loading