diff --git a/check/shodan.go b/check/shodan.go index fdd9ce0..76baa9b 100644 --- a/check/shodan.go +++ b/check/shodan.go @@ -15,6 +15,7 @@ type shodan struct { Data shodanData `json:"data"` OS string `json:"os"` Ports []int `json:"ports"` + Vulns []string `json:"vulns"` } type shodanData []struct { @@ -30,7 +31,7 @@ var shodanUrl = "https://api.shodan.io" func Shodan(ipaddr net.IP) (checkip.Result, error) { result := checkip.Result{ Name: "shodan.io", - Type: checkip.TypeInfo, + Type: checkip.TypeInfoSec, } apiKey, err := getConfigValue("SHODAN_API_KEY") @@ -48,6 +49,10 @@ func Shodan(ipaddr net.IP) (checkip.Result, error) { } result.Info = shodan + if len(shodan.Vulns) > 0 { + result.Malicious = true + } + return result, nil } @@ -80,14 +85,7 @@ func (s shodan) Summary() string { } } - portStr := "port" - if len(portInfo) != 1 { - portStr += "s" - } - if len(portInfo) > 0 { - portStr += ":" - } - return fmt.Sprintf("OS: %s, %d open %s %s", na(s.OS), len(portInfo), portStr, strings.Join(portInfo, ", ")) + return fmt.Sprintf("OS: %s, open: %s, vulns: %s", na(s.OS), strings.Join(portInfo, ", "), na(strings.Join(s.Vulns, ", "))) } func (s shodan) Json() ([]byte, error) { diff --git a/check/shodan_test.go b/check/shodan_test.go index cf04b03..348ecd5 100644 --- a/check/shodan_test.go +++ b/check/shodan_test.go @@ -23,8 +23,8 @@ func TestShodan(t *testing.T) { result, err := Shodan(net.ParseIP("118.25.6.39")) require.NoError(t, err) assert.Equal(t, "shodan.io", result.Name) - assert.Equal(t, checkip.TypeInfo, result.Type) - assert.Equal(t, false, result.Malicious) + assert.Equal(t, checkip.TypeInfoSec, result.Type) + assert.Equal(t, true, result.Malicious) }) t.Run("given non 2xx response then error is returned", func(t *testing.T) {