-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample.go
166 lines (151 loc) · 5.25 KB
/
sample.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package umbrella
import (
"fmt"
"net/url"
)
// Behavior describes a single indicator associated with a sample.
type Behavior struct {
Name string `json:"name"`
Title string `json:"title"`
Hits int `json:"hits"`
Confidence int `json:"confidence"`
Severity int `json:"severity"`
Tags []string `json:"tags"`
Threat int `json:"threat"`
Category []string `json:"category"`
}
// Artifact represents a single artifact, typically associated with a sample
type Artifact struct {
SHA256 string `json:"sha256"`
SHA1 string `json:"sha1"`
MD5 string `json:"md5"`
MagicType string `json:"magicType"`
Size int `json:"size"`
FirstSeen int `json:"firstSeen"`
LastSeen int `json:"lastSeen"`
Visible bool `json:"visible"`
AVResults []struct {
Signature string `json:"signature"`
Product string `json:"product"`
} `json:"avresults"`
Behaviors []Behavior `json:"behaviors"`
}
// Sample represents a single sample, returned by either /sample or /samples.
type Sample struct {
Artifact
ThreatScore int `json:"threatScore"`
}
// Connection contains information about a single network connection made
// by a sample.
type Connection struct {
Name string `json:"name"`
FirstSeen int `json:"firstSeen"`
LastSeen int `json:"lastSeen"`
SecurityCategories []string `json:"securityCategories"`
Attacks []string `json:"attacks"`
ThreatTypes []string `json:"threatTypes"`
Type string `json:"type"`
IPs []string `json:"ips"`
URLs []string `json:"urls"`
}
// SampleFull hold all information about a single sample, including its artifacts
// and network connections.
type SampleFull struct {
Sample
Artifacts struct {
Pagignation
Artifacts []Artifact `json:"artifacts"`
} `json:"artifacts"`
Samples struct {
Pagignation
Samples []Sample `json:"samples"`
} `json:"samples"`
Connections struct {
Pagignation
Connections []Connection `json:"connections"`
} `json:"connections"`
}
// SampleList holds a list of samples matching a query by domain, URL, or IP
type SampleList struct {
Pagignation
Query string `json:"query"`
Samples []Sample `json:"samples"`
}
// ArtifactList is returned when querying artifacts related to a sample, includes
// pagignation.
type ArtifactList struct {
Pagignation
Artifacts []Artifact `json:"artifacts"`
}
// ConnectionList holds a list of network connections make by a samples, including
// pagination.
type ConnectionList struct {
Pagignation
Connections []Connection `json:"connections"`
}
// Pagignation is used in several query responses to show if there are
// additional records available as well as show the limit and current position.
type Pagignation struct {
TotalResults int `json:"totalResults"`
MoreDataAvailable bool `json:"moreDataAvailable"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
// GetSamples returns all samples associated with an IP, a domain or a URL.
// Available options are 'limit', 'offset', and 'sortby'.
func (c Investigate) GetSamples(term string, opts QueryOptions) (SampleList, error) {
fmt.Printf("samples/%s", url.QueryEscape(term))
u := &url.URL{
Path: fmt.Sprintf("samples/%s", term),
RawPath: fmt.Sprintf("samples/%s", url.QueryEscape(term)),
RawQuery: url.Values(opts).Encode(),
}
var out SampleList
err := c.Get(c.BaseURL.ResolveReference(u).String(), &out)
return out, err
}
// GetSample returns complete information about a single sample, identified by its hash.
// Hash can be either a SHA256, SHA1, or MD5. Supports 'limit' and 'offset' options.
func (c Investigate) GetSample(hash string, opts QueryOptions) (SampleFull, error) {
u := &url.URL{
Path: fmt.Sprintf("sample/%s", hash),
RawQuery: url.Values(opts).Encode(),
}
var out SampleFull
err := c.Get(c.BaseURL.ResolveReference(u).String(), &out)
return out, err
}
// GetSampleArtifacts returns artifacts associated with a sample, identified by
// its hash. Hash can be either a SHA256, SHA1, or MD5. Supports 'limit' and
// 'offset' options.
func (c Investigate) GetSampleArtifacts(hash string, opts QueryOptions) (ArtifactList, error) {
u := &url.URL{
Path: fmt.Sprintf("sample/%s/artifacts", hash),
RawQuery: url.Values(opts).Encode(),
}
var out ArtifactList
err := c.Get(c.BaseURL.ResolveReference(u).String(), &out)
return out, err
}
// GetSampleConnections returns connections associated with a sample, identified by
// its hash. Hash can be either a SHA256, SHA1, or MD5. Supports 'limit' and
// 'offset' options.
func (c Investigate) GetSampleConnections(hash string, opts QueryOptions) (ConnectionList, error) {
u := &url.URL{
Path: fmt.Sprintf("sample/%s/connections", hash),
RawQuery: url.Values(opts).Encode(),
}
var out ConnectionList
err := c.Get(c.BaseURL.ResolveReference(u).String(), &out)
return out, err
}
// GetSampleBehaviors returns indicators associated with a sample, identified by
// its hash. Hash can be either a SHA256, SHA1, or MD5.
func (c Investigate) GetSampleBehaviors(hash string) ([]Behavior, error) {
u := &url.URL{
Path: fmt.Sprintf("sample/%s/behaviors", hash),
}
var out []Behavior
err := c.Get(c.BaseURL.ResolveReference(u).String(), &out)
return out, err
}