Skip to content

Commit

Permalink
make shodan InfoSec check type
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed Apr 29, 2022
1 parent 5239e3f commit 9717c4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions check/shodan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions check/shodan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9717c4c

Please sign in to comment.