-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from vulncheck-oss/ua-update
#154 Initial version of UA fetch, sorting, cleaning, and embedding
- Loading branch information
Showing
7 changed files
with
116 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: User-Agent Update | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup golang | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
- name: Fetch and Sort UA Data | ||
run: | | ||
go get github.com/buger/jsonparser | ||
go run . | ||
working-directory: _uaupdate | ||
|
||
- name: Create local changes | ||
run: | | ||
git add protocol/http-user-agent.txt | ||
- name: Commit files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git commit --allow-empty -m "HTTP User Agent update" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
branch: ${{ github.ref }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Updating the go-exploit HTTP User Agent | ||
|
||
This main.go fetches user agents from the Project Discovery [useragent](https://github.com/projectdiscovery/useragent) package (using the [MIT license](https://github.com/projectdiscovery/useragent/blob/main/LICENSE)), and filters them down to the most recent Windows Chrome User-Agent. The output is written to `./protocol/http-user-agent.txt`. | ||
|
||
Usage example: | ||
|
||
```console | ||
albinolobster@mournland:~/go-exploit/_uaupdate$ go run . | ||
albinolobster@mournland:~/go-exploit/_uaupdate$ cat ../protocol/http-user-agent.txt | ||
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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" | ||
resp, body, ok := protocol.HTTPSendAndRecv("GET", uri, "") | ||
if !ok { | ||
return | ||
} | ||
|
||
if resp.StatusCode != 200 { | ||
output.PrintfError("Unexpected status code: %d %s", resp.StatusCode, body) | ||
|
||
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(`^.*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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
module github.com/vulncheck-oss/go-exploit | ||
|
||
go 1.21 | ||
go 1.22.2 | ||
|
||
require ( | ||
github.com/lor00x/goldap v0.0.0-20240304151906-8d785c64d1c8 | ||
github.com/projectdiscovery/useragent v0.0.55 | ||
github.com/vjeantet/ldapserver v1.0.2-0.20240305064909-a417792e2906 | ||
golang.org/x/crypto v0.24.0 | ||
golang.org/x/net v0.26.0 | ||
golang.org/x/text v0.16.0 | ||
) | ||
|
||
require ( | ||
github.com/aymerick/douceur v0.2.0 // indirect | ||
github.com/gorilla/css v1.0.0 // indirect | ||
github.com/microcosm-cc/bluemonday v1.0.25 // indirect | ||
github.com/projectdiscovery/blackrock v0.0.1 // indirect | ||
github.com/projectdiscovery/utils v0.1.1 // indirect | ||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters