// determine api version for api calls var VERSION = (params.VERSION ? "v2" : "v1"); var SERVER = params.url; if (SERVER[SERVER.length - 1] !== '/') { SERVER += '/'; } var THRESHOLD = params.threshold; if (!THRESHOLD){ THRESHOLD = 'high'; } if (['low', 'medium', 'high'].indexOf(THRESHOLD) < 0) { throw('Threshold parameter must be one of: high, medium, low'); } var MALICIOUS_DICTIONARY = { 'low': 1, 'medium':2, 'high': 3 }; var MALICOUS_THRESHOLD = MALICIOUS_DICTIONARY[THRESHOLD]; function doReq(method, path, query, body) { var result = http( SERVER + path + encodeToURLQuery(query), { Headers: { 'X-CSIX-CUSTID': [params.id], 'X-CSIX-CUSTKEY': [params.key], 'Content-Type': ['application/json'], 'Accept': ['application/json'], 'X-INTEGRATION' : ['Demisto_demisto_3.6'] }, Method: method, Body: body ? JSON.stringify(body) : '' }, params.insecure, params.useproxy ); if (result.StatusCode < 200 || result.StatusCode > 299) { throw 'Failed to perform request ' + path + ', request status code: ' + result.StatusCode + ', body: ' + result.Body; } if (result.Body === '') { throw 'No content received.'; } var obj; try { obj = JSON.parse(result.Body); } catch (ex) { throw 'Error parsing reply - ' + result.Body + ' - ' + ex; } if (obj.errors && obj.errors.length > 0) { throw JSON.stringify(obj.errors); } return { body: result.Body, obj: obj, statusCode: result.StatusCode }; } function dateToEpoch(d) { if (d) { var epoch = String(new Date(d).getTime()); var trimmedEpoch = epoch.substring(0, epoch.length - 3); return trimmedEpoch; } else { return null; } } function add(a, k, ok, f) { if (args[k]) { var parts = args[k].split(','); for (var i=0; i 1 ? parts : args[k]; } } function simpleValue(o, t) { return o ? '- ' + t + ': ' + o.map(function(curr) {return curr.value;}).join(', ') + '\n' : ''; } // Not passing the arguments because there are a lot of them function doActors() { var a = {}; add(a, 'q'); add(a, 'name'); add(a, 'desc'); add(a, 'origins'); add(a, 'targetContries', 'target_countries'); add(a, 'targetIndustries', 'target_industries'); add(a, 'motivations'); add(a, 'slug'); add(a, 'offset'); add(a, 'limit'); add(a, 'sort'); add(a, 'minLastModifiedDate', 'min_last_modified_date', dateToEpoch); add(a, 'maxLastModifiedDate', 'max_last_modified_date', dateToEpoch); add(a, 'minLastActivityDate', 'min_last_activity_date', dateToEpoch); add(a, 'maxLastActivityDate', 'max_last_activity_date', dateToEpoch); var res = doReq('GET', 'actors/queries/actors/v1', a); var md = '## Falcon Intel Actor search\n'; if (res.obj.resources) { // Now need to retrieve the full data for each id var fullArgs = {ids: res.obj.resources, fields: '__full__'}; var resFull = doReq('GET', 'actors/entities/actors/v1', fullArgs); // Restore original pagination resFull.obj.meta.pagination = res.obj.meta.pagination; res = resFull; if (res.obj.resources) { var o = res.obj.resources; for (var i=0; i 0) { n.Reports = v.reports; } if (v.actors && v.actors.length > 0) { n.Actors = v.actors; } if (v.malware_families && v.malware_families.length > 0) { n.MalwareFamilies = v.malware_families; } if (v.kill_chains && v.kill_chains.length > 0) { n.KillChains = v.kill_chains; } if (score === 3) { n.Malicious = {Vendor: 'FalconIntel', Description: 'High confidence'}; } if (!ec[path]) { ec[path] = []; } ec[path].push(n); } // Not passing the arguments because there are a lot of them function doIndicators() { var a = {}; a[args.filter] = args.value; add(a, 'page'); add(a, 'pageSize'); if (args.sort) { var parts = args.sort.split('.'); a.sort = parts[0]; if (parts.length > 1) { a.order = parts[1]; } } var res = doReq('GET', 'indicator/'+ VERSION +'/search/' + args.parameter, a); var md = '## Falcon Intel Indicator Search for: ' + args.value + '\n'; var found = false; var ec = {}; if (res.obj) { for (var i=0; i 0) { // Now need to retrieve the full data for each id var resFull = doReq('GET', '/reports/entities/reports/v1', {ids: res.obj.resources}); // Restore original pagination resFull.obj.meta.pagination = res.obj.meta.pagination; res = resFull; if (res.obj.resources) { var o = res.obj.resources; for (var i=0; i 299) { throw 'Failed to retrieve PDF, status code: ' + result.StatusCode + ', body: ' + result.Body; } // Try to extract the filename var disposition = result.Headers['Content-Disposition']; var filename = 'report-' + args.id + '.pdf'; if (disposition) { disposition = disposition[0]; if (disposition) { var parts = disposition.split(';'); if (parts && parts.length > 1) { var name = parts[1].split('='); if (name && name.length > 1) { filename = name[1].trim(); } } } } return { Type: entryTypes.entryInfoFile, FileID: result.Path, File: filename, Contents: filename }; } switch (command) { case 'test-module': if(VERSION === 'v2') { doReq('GET', 'indicator/'+ VERSION +'/search/indicator', {equal: '4.4.4.4'}); return true; } else { doReq('GET', 'actors/queries/actors/v1', {q: 'panda'}); return true; } break; case 'file': return doFile(args.file); case 'ip': return doIP(args.ip); case 'url': return doURL(args.url); case 'domain': return doDomain(args.domain); case 'cs-actors': return doActors(); case 'cs-indicators': return doIndicators(); case 'cs-reports': return doReports(); case 'cs-report-pdf': return doReport(); default: throw 'Unknown command - ' + command; }