diff --git a/go.mod b/go.mod index e0e986f..6ed93d8 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/gaukas/godicttls v0.0.4 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/pgzip v1.2.5 // indirect @@ -113,6 +114,7 @@ require ( github.com/projectdiscovery/hmap v0.0.41 github.com/projectdiscovery/retryablehttp-go v1.0.53 github.com/weppos/publicsuffix-go v0.30.1-0.20230422193905-8fecedd899db // indirect + github.com/zcalusic/sysinfo v1.0.2 github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/mod v0.12.0 // indirect diff --git a/go.sum b/go.sum index f074c12..19cc8e3 100644 --- a/go.sum +++ b/go.sum @@ -97,6 +97,8 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/hashicorp/golang-lru/v2 v2.0.6 h1:3xi/Cafd1NaoEnS/yDssIiuVeDVywU0QdFGl3aQaQHM= @@ -292,6 +294,8 @@ github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGj github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/zcalusic/sysinfo v1.0.2 h1:nwTTo2a+WQ0NXwo0BGRojOJvJ/5XKvQih+2RrtWqfxc= +github.com/zcalusic/sysinfo v1.0.2/go.mod h1:kluzTYflRWo6/tXVMJPdEjShsbPpsFRyy+p1mBQPC30= github.com/zmap/rc2 v0.0.0-20131011165748-24b9757f5521/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE= github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 h1:Nzukz5fNOBIHOsnP+6I79kPx3QhLv8nBy2mfFhBRq30= github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE= diff --git a/update/types.go b/update/types.go index 9f14e3a..855d0c1 100644 --- a/update/types.go +++ b/update/types.go @@ -1,13 +1,17 @@ package updateutils import ( + "encoding/base64" "fmt" "os" + "runtime" "strings" "github.com/Masterminds/semver/v3" "github.com/logrusorgru/aurora" + osutils "github.com/projectdiscovery/utils/os" "github.com/projectdiscovery/utils/process" + "github.com/zcalusic/sysinfo" ) type AssetFormat uint @@ -149,5 +153,31 @@ func getUtmSource() string { return val } } + if value == "unknown" || value == "" { + return getPlatformMetadata() + } return value } + +// Get OS Vendor returns the linux distribution vendor +// if not linux then returns runtime.GOOS +func GetOSVendor() string { + if !osutils.IsLinux() { + return runtime.GOOS + } + var si sysinfo.SysInfo + si.GetSysInfo() + return si.OS.Vendor +} + +// returns platform metadata +func getPlatformMetadata() string { + var si sysinfo.SysInfo + si.GetSysInfo() + tmp := strings.ReplaceAll(si.Board.Vendor, " ", "_") + "|" + strings.ReplaceAll(si.Board.Name, " ", "_") + if tmp == "|" { + // instead of just empty string return os for more context + tmp = runtime.GOOS + "|" + runtime.GOARCH + } + return strings.TrimSuffix(base64.StdEncoding.EncodeToString([]byte(tmp)), "==") +} diff --git a/update/update.go b/update/update.go index 286703d..b210664 100644 --- a/update/update.go +++ b/update/update.go @@ -149,7 +149,12 @@ func GetToolVersionCallback(toolName, version string) func() (string, error) { // GetpdtmParams returns encoded query parameters sent to update check endpoint func GetpdtmParams(version string) string { params := &url.Values{} - params.Add("os", runtime.GOOS) + os := runtime.GOOS + if runtime.GOOS == "linux" { + // be more specific + os = GetOSVendor() + } + params.Add("os", os) params.Add("arch", runtime.GOARCH) params.Add("go_version", runtime.Version()) params.Add("v", version)