Skip to content

Commit

Permalink
Update UA version update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
j-baines committed Oct 7, 2024
1 parent c245a25 commit 79c8a4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
37 changes: 5 additions & 32 deletions _uaupdate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package main
import (
"os"
"regexp"
"strconv"

"github.com/buger/jsonparser"
"github.com/vulncheck-oss/go-exploit/output"
"github.com/vulncheck-oss/go-exploit/protocol"
)

func main() {
uri := "https://raw.githubusercontent.com/projectdiscovery/useragent/main/useragent_data.json"
uri := "https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome"
resp, body, ok := protocol.HTTPSendAndRecv("GET", uri, "")
if !ok {
return
Expand All @@ -23,34 +21,9 @@ func main() {
return
}

// looking in tags for the latest Chrome on Windows whatever
chromePattern := regexp.MustCompile(`^Chrome (\d+) on Windows \d+$`)

// pattern to find the Safari string so we can drop everything after
safariPattern := regexp.MustCompile(`^.*Chrome/\d+.\d+.\d+.\d+ Safari/[\d\.]+`)

// store the newest version as we loop through the data
latestChromeUA := ""
latestChromeVer := 0

_, _ = jsonparser.ArrayEach([]byte(body), func(entry []byte, _ jsonparser.ValueType, _ int, _ error) {
_, _ = jsonparser.ArrayEach(entry, func(tag []byte, _ jsonparser.ValueType, _ int, _ error) {
matches := chromePattern.FindStringSubmatch(string(tag))
if len(matches) == 2 {
version, _ := strconv.Atoi(matches[1])
if version > latestChromeVer {
ua, _ := jsonparser.GetString(entry, "Raw")
cleanedUA := safariPattern.FindString(ua)
if cleanedUA != "" {
latestChromeUA = cleanedUA
latestChromeVer = version
}
}
}
}, "Tags")
})

if len(latestChromeUA) != 0 {
_ = os.WriteFile("../protocol/http-user-agent.txt", []byte(latestChromeUA), 0o644)
// looking in the body for the latest Chrome on Windows whatever
matches := regexp.MustCompile(`<li><span class="code">(Mozilla/\d+.\d+ \(Windows NT [^<]+)</span></li>`).FindStringSubmatch(body)
if len(matches) != 0 {
_ = os.WriteFile("../protocol/http-user-agent.txt", []byte(matches[1]), 0o644)
}
}
2 changes: 1 addition & 1 deletion protocol/http-user-agent.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

0 comments on commit 79c8a4c

Please sign in to comment.