#!/bin/bash # Usage: ./aws_enumerate_metadata.sh host:port if [ $# -ne 1 ]; then echo "Usage: $0 host:port" exit 1 fi HOSTPORT="$1" BASE_URL="http://${HOSTPORT}/latest" # Recursively enumerate endpoints enumerate() { local path="$1" local url="${BASE_URL}${path}" local result result=$(curl -s "$url") # If the result contains lines ending with '/', it's a directory if [[ "$result" == *"/"* ]]; then # For each line ending with '/', recurse while IFS= read -r line; do if [[ "$line" == */ ]]; then enumerate "${path}/${line%/}" else # Print the URL and its output for files value=$(curl -s "${url}/${line}") echo "${url}/${line} $value" fi done <<< "$(echo "$result")" else # Print the URL and its output for leaf nodes echo "$url $result" fi } # Get top-level categories (e.g., meta-data, user-data, dynamic) top_level=$(curl -s "${BASE_URL}/" | grep -E '^[a-zA-Z0-9._-]+/?$') for category in $top_level; do # Remove trailing slash if present category="${category%/}" enumerate "/${category}" done