/
FireEyeISIGHT.js
334 lines (293 loc) · 10 KB
/
FireEyeISIGHT.js
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
var baseUrl = 'https://api.isightpartners.com'; // iSight base url
var publicKey = params.publicKey;
var privateKey = params.credentials_private_key? params.credentials_private_key.password : params.privateKey;
var acceptVersion = params.version;
var insecure = params.insecure;
var proxy = params.proxy;
var VENDOR_NAME = 'FireEye iSIGHT';
// we use this to map record-type to dbot-score
var intelligenceTypeToScore = {
'overview': 1,
'vulnerability': 2,
'malware': 3,
'threat': 3
};
// we use this to determine the order of reputation sevirity of the types
var intelligenceTypeOrder = ['overview', 'vulnerability', 'malware', 'threat'];
var epoch2DateStr = function(epochStr) {
return new Date(parseInt(epochStr) * 1000).toString();
}
var createTableEntry = function (name, contents, table, context) {
return {
// type
Type: entryTypes.note,
// contents
ContentsFormat: formats.json,
Contents: contents,
// human-readable
ReadableContentsFormat: formats.markdown,
HumanReadable: tableToMarkdown(name, table),
// context
EntryContext: context
};
}
var getHeaders = function(query) {
var timestamp = new Date().toUTCString();
if (timestamp.indexOf('+') > 0) {
timestamp = timestamp.substring(0,timestamp.indexOf('+'));
} else if (timestamp.indexOf('-') > 0) {
timestamp = timestamp.substring(0,timestamp.indexOf('-'));
}
if (!privateKey){
throw('Private Key must be provided.')
}
message = query + acceptVersion + 'application/json' + timestamp;
hashed = HMAC_SHA256_MAC(privateKey, message);
return {
'Accept': ['application/json'],
'Accept-Version': [acceptVersion],
'X-Auth': [publicKey],
'X-Auth-Hash': [hashed],
'Date': [timestamp]
}
}
var sendRequest = function(query) {
var headers = getHeaders(query);
var requestUrl = baseUrl + query;
var res = http(
requestUrl,
{
Method: 'GET',
Headers: headers,
Body: ''
},
insecure,
proxy
);
if (res.StatusCode < 200 || res.StatusCode >= 300) {
throw 'Request Failed.\nUrl: ' + requestUrl + '\nStatus code: ' + res.StatusCode + '.\nResult: ' + JSON.stringify(res);
}
if (res.StatusCode === 204) {
return [];
}
var body = JSON.parse(res.Body);
if (!body || !body.success) {
throw 'Request Failed.\nResonse body: ' + body;
}
return body;
};
var basicSearch = function(key, value) {
var basicSearchQuery = '/search/basic?' + key + '=' + encodeURIComponent(value);
var res = sendRequest(basicSearchQuery);
return res.message;
}
var createContextReportsAndScore = function(records) {
var dbotScore = 0;
var highetsRecordType = 'None';
var reports = [];
// 1. set dbotScore to to the highest record-type among all records
// 2. create report context-object for each record
records && records.forEach(function(record) {
var recordType = record['intelligenceType'];
var recordScore = intelligenceTypeToScore[recordType] || 0;
if (dbotScore < recordScore) {
dbotScore = recordScore;
}
if(intelligenceTypeOrder.indexOf(highetsRecordType) < intelligenceTypeOrder.indexOf(recordType)) {
highetsRecordType = recordType;
}
var reportUrl = record['reportLink'];
reports.push({
ID: record['reportId'],
title: record['title'],
publishDate: epoch2DateStr(record['publishDate']),
intelligenceType: recordType
});
});
return {
dbotScore: dbotScore,
reports: reports,
highetsRecordType: highetsRecordType
}
}
var basicSearchIP = function(ip) {
var records = basicSearch('ip', ip);
if (!records) {
return {
Type: entryTypes.note,
Contents: "No items match your search",
ContentsFormat: formats.text,
EntryContext: {
DBotScore: {
Indicator: ip,
Type: 'IP',
Vendor: VENDOR_NAME,
Score: 0,
Reliability: params.integrationReliability
}
}
};
}
var res = createContextReportsAndScore(records);
var context = {
DBotScore: {Indicator: ip, Type: 'IP', Vendor: VENDOR_NAME, Score: res.dbotScore},
'Report(val.ID && val.ID == obj.ID)': res.reports,
'IP.Address': ip
};
if (res.dbotScore > 2) {
addMalicious(context, outputPaths.ip,{
Address: ip,
Malicious: {Vendor: VENDOR_NAME, Description: 'IP was identified as ' + res.highetsRecordType}
});
}
return createTableEntry("Results:", records, records, context);
}
var basicSearchDomain = function(domain) {
var records = basicSearch('domain', domain);
if (!records) {
return {
Type: entryTypes.note,
Contents: "No items match your search",
ContentsFormat: formats.text,
EntryContext: {
DBotScore: {
Indicator: domain,
Type: 'domain',
Vendor: VENDOR_NAME,
Score: 0,
Reliability: params.integrationReliability
}
}
};
}
var res = createContextReportsAndScore(records);
var context = {
DBotScore: {Indicator: domain, Type: 'domain', Vendor: VENDOR_NAME, Score: res.dbotScore},
'Report(val.ID && val.ID == obj.ID)': res.reports,
'Domain.Name': domain
};
if (res.dbotScore > 2) {
addMalicious(context, outputPaths.domain,{
Name: domain,
Malicious: {Vendor: VENDOR_NAME, Description: 'domain was identified as ' + res.highetsRecordType}
});
}
return createTableEntry("Results:", records, records, context);
}
var basicSearchfile = function(key, value) {
var records = basicSearch(key, value);
if (!records) {
return {
Type: entryTypes.note,
Contents: "No items match your search",
ContentsFormat: formats.text,
EntryContext: {
DBotScore: {
Indicator: value,
Type: 'file',
Vendor: VENDOR_NAME,
Score: 0,
Reliability: params.integrationReliability
}
}
};
}
var res = createContextReportsAndScore(records);
var context = {
DBotScore: {Indicator: value, Type: 'file', Vendor: VENDOR_NAME, Score: res.dbotScore},
'Report(val.ID && val.ID == obj.ID)': res.reports
};
if (res.dbotScore > 2) {
var malicuousObj = {
Malicious: {
Vendor: VENDOR_NAME,
Description: 'file was identified as ' + res.highetsRecordType
}
};
malicuousObj[key.toUpperCase()] = value;
addMalicious(context, outputPaths.file, malicuousObj);
}
return createTableEntry("Results:", records, records, context);
}
var getReport = function(reportID) {
var reportQuery = '/report/'+ encodeURIComponent(reportID);
var res = sendRequest(reportQuery);
var report = res.message.report;
var context = {
'Report(val.ID && val.ID == obj.ID)' : {
ID: report.reportId,
title: report.title,
intelligenceType: report.intelligenceType,
audience: report.audience,
publishDate: report.publishDate,
ThreatScape: report.ThreatScape.product,
operatingSystems: report.operatingSystems,
riskRating: report.riskRating,
version: report.version,
tagSection: report.tagSection
}
}
var table = [{
ID: report.reportId,
title: report.title,
intelligenceType: report.intelligenceType,
audience: report.audience.join(),
publishDate: report.publishDate,
ThreatScape: report.ThreatScape.product.join(),
operatingSystems: report.operatingSystems,
riskRating: report.riskRating,
version: report.version
}];
return createTableEntry("Report - " + reportID, res, table, context);
}
var submitFile = function(entryID, description, type) {
var query = '/submit/data';
var requestUrl = baseUrl + query;
var headers = getHeaders(query);
var res = httpMultipart(
requestUrl, // URL
entryID, // Optional - FilePath / EntryID
{ // HTTP Request Headers
Method: 'POST',
Headers: headers
},
{ // Multipart Contents
type: type,
description: description
},
insecure,
proxy
);
var statusCode = res && res.StatusCode;
switch (statusCode) {
case 200:
return "The file was submitted sucessfully";
case 403:
throw "\nGot 403 error\nQuery valid but the response was refused because the user has exceeded their daily quota of submission requests";
default:
throw '\nSubmit File Failed.\nUrl: ' + requestUrl + '\nStatus code: ' + statusCode + '.\nResult: ' + JSON.stringify(res, null, 2);
}
}
switch (command) {
case 'test-module':
basicSearch('ip', '66.34.253.56');
return 'ok';
case 'ip':
return basicSearchIP(args.ip);
case 'domain':
return basicSearchDomain(args.domain);
case 'file':
var hash = args.file;
var hashLength = hash && hash.length
if(hashLength === 32) {
return basicSearchfile('md5', hash);
} else if(hashLength === 40) {
return basicSearchfile('sha1', hash);
} else {
throw 'file argument must be md5(32 charecters) or sha1(40 charecters) ';
}
case 'isight-get-report':
return getReport(args.reportID);
case 'isight-submit-file':
return submitFile(args.entryID, args.description, args.type);
}