( parsed: ParsedPowerShellCommand, )
| 232 | } |
| 233 | |
| 234 | function 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 |
nothing calls this directly
no test coverage detected