Something went wrong. Try again.
tiny bash script to go through every endpoint on an aws metadata server
Something went wrong. Try again.
1.2 kB · 45 lines · Created 1y ago
Shell
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/bin/bash
# Usage: ./aws_enumerate_metadata.sh host:port
if [ $# -ne 1 ]; then echo "Usage: $0 host:port" exit 1fi
HOSTPORT="$1"BASE_URL="http://${HOSTPORT}/latest"
# Recursively enumerate endpointsenumerate() { 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