Skip to content

Commit

Permalink
Merge pull request #380 from projectdiscovery/update-os-pdtm-param
Browse files Browse the repository at this point in the history
add os vendor support for linux
  • Loading branch information
tarunKoyalwar committed Apr 1, 2024
2 parents 0581372 + d5cc32b commit e67654f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions update/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/logrusorgru/aurora"

"github.com/projectdiscovery/utils/process"
)

Expand Down Expand Up @@ -149,5 +150,8 @@ func getUtmSource() string {
return val
}
}
if value == "unknown" || value == "" {
return getPlatformMetadata()
}
return value
}
7 changes: 6 additions & 1 deletion update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions update/utils_all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !linux
// +build !linux

package updateutils

import (
"encoding/base64"
"runtime"
"strings"
)

// Get OS Vendor returns the linux distribution vendor
// if not linux then returns runtime.GOOS
func GetOSVendor() string {
return runtime.GOOS
}

// returns platform metadata
func getPlatformMetadata() string {
tmp := runtime.GOOS + "|" + runtime.GOARCH
return strings.TrimSuffix(base64.StdEncoding.EncodeToString([]byte(tmp)), "==")
}
32 changes: 32 additions & 0 deletions update/utils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build linux
// +build linux

package updateutils

import (
"encoding/base64"
"runtime"
"strings"

"github.com/zcalusic/sysinfo"
)

// Get OS Vendor returns the linux distribution vendor
// if not linux then returns runtime.GOOS
func GetOSVendor() string {
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)), "==")
}

0 comments on commit e67654f

Please sign in to comment.