Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4470ed

Browse files
authored
Merge pull request#51 from yvesago/master
add Spur check
2 parents445eec7 +e75a80e commita4470ed

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed

‎check/check.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Funcs = []Func{
3333
Ping,
3434
SansISC,
3535
Shodan,
36+
Spur,
3637
Tls,
3738
UrlScan,
3839
VirusTotal,

‎check/spur.go‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package check
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net"
7+
"strings"
8+
)
9+
10+
typespurstruct {
11+
Asstruct {
12+
Numberint`json:"number"`
13+
Organizationstring`json:"organization"`
14+
}`json:"as"`
15+
Clientstruct {
16+
Behaviors []string`json:"behaviors"`
17+
Countint`json:"count"`
18+
Proxies []string`json:"proxies"`
19+
Types []string`json:"types"`
20+
}`json:"client"`
21+
Infrastructurestring`json:"infrastructure"`
22+
IPstring`json:"ip"`
23+
Locationstruct {
24+
Citystring`json:"city"`
25+
Countrystring`json:"country"`
26+
Statestring`json:"state"`
27+
}`json:"location"`
28+
Organizationstring`json:"organization"`
29+
Risks []string`json:"risks"`
30+
Services []string`json:"services"`
31+
Tunnels []struct {
32+
Anonymousbool`json:"anonymous"`
33+
Entries []string`json:"entries"`
34+
Operatorstring`json:"operator"`
35+
Typestring`json:"type"`
36+
}`json:"tunnels"`
37+
}
38+
39+
varspurUrl="https://api.spur.us/v2/context"
40+
41+
// Spur gets generic information from api.spur.io.
42+
funcSpur(ipaddr net.IP) (Check,error) {
43+
result:=Check{
44+
Description:"spur.io",
45+
Type:InfoAndIsMalicious,
46+
}
47+
48+
apiKey,err:=getConfigValue("SPUR_API_KEY")
49+
iferr!=nil {
50+
returnresult,newCheckError(err)
51+
}
52+
ifapiKey=="" {
53+
result.MissingCredentials="SPUR_API_KEY"
54+
returnresult,nil
55+
}
56+
57+
headers:=map[string]string{
58+
"Token":apiKey,
59+
"Accept":"application/json",
60+
"Content-Type":"application/json",
61+
}
62+
63+
varspurspur
64+
apiURL:=fmt.Sprintf("%s/%s",spurUrl,ipaddr)
65+
iferr:=defaultHttpClient.GetJson(apiURL,headers,map[string]string{},&spur);err!=nil {
66+
returnresult,newCheckError(err)
67+
}
68+
result.IpAddrInfo=spur
69+
for_,t:=rangespur.Tunnels {
70+
ift.Anonymous==true {
71+
result.IpAddrIsMalicious=true
72+
}
73+
}
74+
75+
returnresult,nil
76+
}
77+
78+
// Info returns interesting information from the check.
79+
func (sspur)Summary()string {
80+
varoperators []string
81+
varstype []string
82+
for_,t:=ranges.Tunnels {
83+
ift.Anonymous==true {
84+
stype=append(stype,t.Type)
85+
}
86+
ift.Operator!="" {
87+
operators=append(operators,t.Operator)
88+
}
89+
}
90+
iflen(s.Tunnels)==0 {
91+
stype=append(stype,"Residential")
92+
operators=s.Risks
93+
}
94+
95+
returnfmt.Sprintf("%s: %s",strings.Join(stype,", "),strings.Join(operators,", "))
96+
}
97+
98+
func (sspur)Json() ([]byte,error) {
99+
returnjson.Marshal(s)
100+
}

‎check/spur_test.go‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package check
2+
3+
import (
4+
"net"
5+
"net/http"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
funcTestSpur(t*testing.T) {
13+
apiKey,err:=getConfigValue("SPUR_API_KEY")
14+
iferr!=nil||apiKey=="" {
15+
return
16+
}
17+
18+
t.Run("given valid response then result and no error is returned",func(t*testing.T) {
19+
handlerFn:=http.HandlerFunc(func(rw http.ResponseWriter,req*http.Request) {
20+
rw.WriteHeader(http.StatusOK)
21+
rw.Write(loadResponse(t,"spur_response.json"))
22+
})
23+
24+
testUrl:=setMockHttpClient(t,handlerFn)
25+
setSpurUrl(t,testUrl)
26+
27+
result,err:=Spur(net.ParseIP("148.72.164.177"))
28+
require.NoError(t,err)
29+
assert.Equal(t,"spur.io",result.Description)
30+
assert.Equal(t,InfoAndIsMalicious,result.Type)
31+
assert.Equal(t,true,result.IpAddrIsMalicious)
32+
assert.Equal(t,"VPN: NORD_VPN",result.IpAddrInfo.Summary())
33+
})
34+
35+
t.Run("given non 2xx response then error is returned",func(t*testing.T) {
36+
handlerFn:=http.HandlerFunc(func(rw http.ResponseWriter,req*http.Request) {
37+
rw.WriteHeader(http.StatusInternalServerError)
38+
})
39+
40+
testUrl:=setMockHttpClient(t,handlerFn)
41+
setSpurUrl(t,testUrl)
42+
43+
_,err:=Spur(net.ParseIP("148.72.164.177"))
44+
require.Error(t,err)
45+
})
46+
}
47+
48+
// --- test helpers ---
49+
50+
funcsetSpurUrl(t*testing.T,testUrlstring) {
51+
url:=spurUrl
52+
spurUrl=testUrl
53+
t.Cleanup(func() {
54+
spurUrl=url
55+
})
56+
}

‎check/testdata/spur_response.json‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"as": {
3+
"number":30083,
4+
"organization":"AS-30083-GO-DADDY-COM-LLC"
5+
},
6+
"client": {
7+
"behaviors": ["TOR_PROXY_USER"],
8+
"concentration": {
9+
"city":"Weldon Spring",
10+
"country":"US",
11+
"density":0.202,
12+
"geohash":"9yz",
13+
"skew":45,
14+
"state":"Missouri"
15+
},
16+
"count":14,
17+
"countries":1,
18+
"proxies": ["LUMINATI_PROXY","SHIFTER_PROXY"],
19+
"spread":4941431,
20+
"types": ["MOBILE","DESKTOP"]
21+
},
22+
"infrastructure":"DATACENTER",
23+
"ip":"148.72.164.186",
24+
"location": {
25+
"city":"St Louis",
26+
"country":"US",
27+
"state":"Missouri"
28+
},
29+
"risks": ["WEB_SCRAPING","TUNNEL"],
30+
"services": ["IPSEC","OPENVPN"],
31+
"tunnels": [
32+
{
33+
"anonymous":true,
34+
"entries": ["148.72.164.179"],
35+
"exits": ["148.72.164.177"],
36+
"operator":"NORD_VPN",
37+
"type":"VPN"
38+
}
39+
]
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp