Last active
October 20, 2022 08:59
-
-
Save etiennetremel/b532864cbf0328e3d90681ac0edda1f3 to your computer and use it in GitHub Desktop.
Detect Text4Shell in Kubernetes cluster using Trivy - CVE-2022-42889
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Detect Text4Shell in Kubernetes cluster using Trivy. | |
# This script retrieve all running images from a Kubernetes cluster | |
# and run a Trivy scan against them in order to quickly detect the | |
# Text4Shell vulnerability (CVE-2022-42889) | |
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-42889 | |
# You will need Kubectl and the Trivy CLI installed on your machine | |
# before running this script. | |
VULNERABILITY_ID="CVE-2022-42889" | |
for image in $(kubectl get pods -A -o jsonpath='{range .items[*].spec.containers[*]}{.image}{"\n"}{end}' | sort | uniq) | |
do | |
echo "Scanning $image..." | |
trivy image --security-checks vuln --format json -s CRITICAL $image --output /tmp/report.json | |
found_vulnerabilities=$(jq -r '[.Results[].Vulnerabilities[]? | select(.VulnerabilityID == "'"$VULNERABILITY_ID"'")]? | length' /tmp/report.json 2> /dev/null) | |
if [[ "$found_vulnerabilities" -gt 0 ]] | |
then | |
echo "Found $VULNERABILITY_ID in $image:" | |
jq -r '.Results[].Vulnerabilities[]? | select(.VulnerabilityID == "'"$VULNERABILITY_ID"'") | { Image: "'"$image"'", PkgPath: .PkgPath, PkgName: .PkgName, InstalledVersion: .InstalledVersion}' /tmp/report.json | |
fi | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment