MCPcopy Create free account
hub / github.com/Noumena-Network/code / checkDownloadCradles

Function checkDownloadCradles

src/tools/PowerShellTool/powershellSecurity.ts:234–264  ·  view source on GitHub ↗
(
  parsed: ParsedPowerShellCommand,
)

Source from the content-addressed store, hash-verified

232}
233
234function checkDownloadCradles(
235 parsed: ParsedPowerShellCommand,
236): PowerShellSecurityResult {
237 // Per-statement: piped cradle (IWR ... | IEX)
238 for (const statement of parsed.statements) {
239 const cmds = statement.commands
240 if (cmds.length < 2) {
241 continue
242 }
243 const hasDownloader = cmds.some(cmd => isDownloader(cmd.name))
244 const hasIex = cmds.some(cmd => isIex(cmd.name))
245 if (hasDownloader && hasIex) {
246 return {
247 behavior: 'ask',
248 message: 'Command downloads and executes remote code',
249 }
250 }
251 }
252
253 // Cross-statement: split cradle ($r = IWR ...; IEX $r.Content).
254 // No new false positives: if IEX is present, checkInvokeExpression already asks.
255 const all = getAllCommands(parsed)
256 if (all.some(c => isDownloader(c.name)) && all.some(c => isIex(c.name))) {
257 return {
258 behavior: 'ask',
259 message: 'Command downloads and executes remote code',
260 }
261 }
262
263 return { behavior: 'passthrough' }
264}
265
266/**
267 * Checks for standalone download utilities — LOLBAS tools commonly used to

Callers

nothing calls this directly

Calls 3

isDownloaderFunction · 0.85
isIexFunction · 0.85
getAllCommandsFunction · 0.50

Tested by

no test coverage detected