MCPcopy Create free account
hub / github.com/ShipSecAI/studio / execute

Function execute

worker/src/components/security/virustotal.ts:112–242  ·  view source on GitHub ↗
({ inputs, params }, context)

Source from the content-addressed store, hash-verified

110 deprecated: false,
111 },
112 async execute({ inputs, params }, context) {
113 const { indicator, apiKey } = inputs;
114 const { type } = params;
115
116 if (!indicator) {
117 throw new ValidationError('Indicator is required', {
118 fieldErrors: { indicator: ['Indicator is required'] },
119 });
120 }
121 if (!apiKey) {
122 throw new ConfigurationError('VirusTotal API Key is required', {
123 configKey: 'apiKey',
124 });
125 }
126
127 let endpoint = '';
128
129 // API v3 Base URL
130 const baseUrl = 'https://www.virustotal.com/api/v3';
131
132 // Construct endpoint based on type
133 switch (type) {
134 case 'ip':
135 endpoint = `${baseUrl}/ip_addresses/${indicator}`;
136 break;
137 case 'domain':
138 endpoint = `${baseUrl}/domains/${indicator}`;
139 break;
140 case 'file':
141 endpoint = `${baseUrl}/files/${indicator}`;
142 break;
143 case 'url': {
144 // URL endpoints usually require the URL to be base64 encoded without padding
145 const b64Url = Buffer.from(indicator)
146 .toString('base64')
147 .replace(/=/g, '')
148 .replace(/\+/g, '-')
149 .replace(/\//g, '_');
150 endpoint = `${baseUrl}/urls/${b64Url}`;
151 break;
152 }
153 }
154
155 context.logger.info(`[VirusTotal] Checking ${type}: ${indicator}`);
156
157 // If type is URL, we might need to "scan" it first if it hasn't been seen,
158 // but typically "lookup" implies retrieving existing info.
159 // The GET endpoint retrieves the last analysis.
160
161 const response = await context.http.fetch(endpoint, {
162 method: 'GET',
163 headers: {
164 'x-apikey': apiKey,
165 Accept: 'application/json',
166 },
167 });
168
169 if (response.status === 404) {

Callers

nothing calls this directly

Calls 6

fromHttpResponseFunction · 0.90
generateFindingHashFunction · 0.90
fromMethod · 0.80
infoMethod · 0.80
fetchMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected