> For the complete documentation index, see [llms.txt](https://cookiez.gitbook.io/red-team/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cookiez.gitbook.io/red-team/cloud/general/enumeration/cloud-asset-discovery.md).

# Cloud Asset Discovery (IP Range Scanning)

Find a target's unlinked cloud hosts by scanning provider IP ranges and attributing them via TLS certificates.

**Goal:** map a target's external cloud footprint, including hosts nothing links to, by scanning the provider's published IP space and attributing each live host by its **TLS certificate**.

**Flow:** identify provider → pull provider IP ranges → Masscan the range → extract open hosts → pull certs (TLS-Scan) → grep for the target's domain → hand off.

{% hint style="danger" %}
Provider ranges are shared by **thousands of other customers**. Only scan broadly when the engagement scope and rules of engagement allow it; otherwise limit to IPs confirmed to belong to the target. This is in-scope authorized testing only.
{% endhint %}

## Step 1: Identify the cloud provider(s)

Orgs often use **several** providers (CDN/WAF + DNS + hosting), so record all of them.

* **BuiltWith** (`https://builtwith.com/<domain>`): *Web Hosting Providers* and *Name Server* sections list hosting, CDN/WAF and DNS.
* Page resources: CDN/storage URLs linked from the site (`*.cloudfront.net`, `*.blob.core.windows.net`, `storage.googleapis.com`).

```bash
# Name servers: awsdns-* = Route 53, azure-dns-* = Azure DNS, ns-cloud-* = Google Cloud DNS
dig +short NS target.com

# CNAME chain often exposes the provider (cloudfront.net, azurewebsites.net, elb.amazonaws.com)
dig +short www.target.com CNAME

# Resolve, then check who owns the IP (OrgName / NetName shows Amazon/Microsoft/Google)
dig +short www.target.com
whois 203.0.113.10 | grep -Ei 'OrgName|NetName|CIDR'
```

## Step 2: Pull the provider's published IP ranges

Providers publish their ranges as JSON. Parse out just the CIDRs with `jq`.

```bash
# AWS
wget -qO- https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes[] | .ip_prefix' -r

# Google Cloud
wget -qO- https://www.gstatic.com/ipranges/cloud.json | jq '.prefixes[] | .ipv4Prefix' -r

# Azure (download ServiceTags_Public_*.json first from Microsoft, then parse)
jq < ~/Downloads/ServiceTags_Public_*.json '.values | .[] | .properties.addressPrefixes | .[]' -r
```

### Narrow to one region

AWS tags each prefix with a region, so filter to the one the target deploys in to cut the scan size.

```bash
# Only us-east-1 prefixes, de-duplicated, saved for Masscan
wget -qO- https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes[] | if .region == "us-east-1" then .ip_prefix else empty end' -r | sort -u > us-east-1-range.txt
```

## Step 3: Scan the range with Masscan

Nmap is too slow for millions of hosts. **Masscan** splits SYN-send from ACK-receive (async, fire-and-forget), so it's far faster for finding open ports at scale.

```bash
# -iL read targets from file, -oL grepable log, -p port(s), --rate packets/sec
masscan -iL us-east-1-range.txt -oL us-east-1-range.masscan -p 443 --rate 100000
```

* `--rate` is the dial. Default is only 100 pps. \~50,000 pps ≈ 20 Mbps; at 20 Mbps, 10 ports across 16M hosts ≈ 1 hour.
* **Too fast = false negatives.** If the rate exceeds host/network capacity, open ports get missed. Dropping 100k→10k pps is \~10x slower but far more accurate. us-east-1 (\~32.7M IPs, one port) is \~5.5 h at 100k pps.
* Scan from a **well-connected box in the same region** (e.g. an EC2 VM in us-east-1) for throughput.

```bash
# Extract just the IPs that answered on 443 (field 4 of 'open' lines) for the next stage
awk '/open/ {print $4}' us-east-1-range.masscan > us-east-1-range.tlsopen
```

## Step 4: Attribute hosts via TLS certificates

Masscan gives IPs, not owners. A **TLS cert on 443** usually carries the owner's domain in the **Subject CN** (and SANs), so certs are how you tie an IP back to the target.

### One host (OpenSSL)

```bash
# Connect, decode the cert, pull the Subject line (C/ST/L/O/OU/CN)
openssl s_client -connect 18.207.73.1:443 2>/dev/null | openssl x509 -text | grep Subject:
# Subject: C = US, ST = Florida, L = Miami, O = "e-Builder, Inc", OU = Operations, CN = *.e-builder.net
```

### Many hosts (TLS-Scan)

OpenSSL does one host at a time. **TLS-Scan** reads a list, is fast/non-blocking, and writes JSON.

```bash
# Grab the CA bundle it needs (Slingshot: /opt/tls-scan/ca-bundle.crt already present)
wget https://raw.githubusercontent.com/prbinu/tls-scan/master/ca-bundle.crt

# Feed it the open-443 IP list; collect certs to JSON
cat us-east-1-range.tlsopen | tls-scan --port=443 --cacert=ca-bundle.crt -o us-east-1-range-tlsinfo.json
```

```bash
# Flatten IP + every cert-chain CN to CSV
cat us-east-1-range-tlsinfo.json | jq '[.ip, .certificateChain[].subjectCN] | join(",")' -r > us-east-1-range-tlsinfo.csv

# Pull out only the target's hosts (wildcards + full hostnames + the issuing CA)
grep '\.target\.com' us-east-1-range-tlsinfo.csv
```

* The cert chain is usually 2+ certs (server + CA). Grepping the target domain across all CNs surfaces **wildcards and specific subdomains** (`admin.dev.`, `firmware-release.dev.`, `*.qa.`) that were never linked anywhere, plus the CA in use.
* Author's helper for parsing: `extract-tlsscan-hostnames.py`.

## Step 5: Hand off

The attributed hostname/IP list feeds the rest of recon: resolve the new subdomains, port-scan the confirmed target hosts in depth with Nmap, screenshot with GoWitness/Aquatone, and run Nuclei. Provider-specific enumeration continues under [Azure](https://cookiez.gitbook.io/red-team/cloud/azure.md) / [AWS](https://cookiez.gitbook.io/red-team/cloud/aws.md).

## Tooling cheat sheet

| Tool                    | Role                             |
| ----------------------- | -------------------------------- |
| BuiltWith / dig / whois | Identify provider(s)             |
| wget + jq               | Pull & filter provider IP ranges |
| Masscan                 | Fast open-port sweep at scale    |
| awk                     | Extract open-host IPs            |
| OpenSSL `s_client`      | Cert for a single host           |
| TLS-Scan                | Cert collection at scale (JSON)  |
| jq / grep               | Attribute hosts by cert CN       |

***

*Source: SANS SEC504 — Hacker Tools, Techniques, and Incident Handling (Cloud Scanning module)*
