Build Your Own Cloud LOLBin Scanner: Hunt Risky Commands Before Attackers Do
In the cloud-native world of 2025, CLI tools like az, aws, gcloud, and kubectl are omnipresent—pre-installed on VMs, CI/CD agents, and developer laptops. But as we've seen with traditional LOLBins, these tools harbor "dangerous" subcommands ripe for abuse: exfiltrating data, executing remote code, dumping secrets, and more.
This article walks you through building a Python scanner that:
Runs tool --help for each CLI.
Parses the output to extract subcommands.
Flags those matching known risky patterns (e.g., upload, exec, run-command).
Outputs a prioritized list for hunting or testing.
Why Build This?
Red Team: Discover fresh abuse vectors in new CLI versions.
Blue Team: Integrate into SIEM/SOAR for behavioral monitoring.
DevSecOps: Scan CI/CD pipelines for risky invocations.
We'll use Python's subprocess for CLI execution and regex for parsing. No external deps needed beyond standard libs. Test in a lab—ensure CLIs are installed and authenticated if required.
Prerequisites
Python 3.8+.
Installed CLIs: az, aws, gcloud, kubectl (e.g., via brew on macOS or chocolatey on Windows).
For AWS/GCP/Azure: Authenticate minimally (e.g., aws configure with test creds) to avoid auth errors in help output.
Risky Command Patterns (2025 Edition)
Based on real-world abuse from sources like MITRE ATT&CK, Stratus Red Team, and recent CVEs (e.g., Azure CLI credential leaks), here are flagged keywords:
CLI
Risky Keywords/Subcommands
Abuse Example (MITRE)
az
storage blob upload, vm run-command, keyvault secret set, keyvault secret list
T1567 (Exfil), T1059 (Exec)
aws
s3 cp/sync, ssm send-command, lambda invoke, iam list-users/create-policy
T1071 (AppData), T1059.006 (Script)
gcloud
compute instances start/ssh, storage cp, secrets versions access, run deploy