|
| 1 | +# GCP IP List |
| 2 | + |
| 3 | +[](https://godoc.org/github.com/mark-adams/gcp-ip-list) [](https://raw.githubusercontent.com/mark-adams/gcp-ip-list/main/LICENSE) [](https://github.com/mark-adams/gcp-ip-list/actions/workflows/test.yml) |
| 4 | + |
| 5 | + |
| 6 | +`gcp-ip-list` is a CLI tool (and library) written in Go to simplify the process of retrieving IP addresses from infrastructure hosted on Google Cloud Platform (GCP). |
| 7 | + |
| 8 | +Most enumeration tooling today uses the normal CRUD REST APIs provided by Google to retrieve GCP assets and their IP address information. This is less than ideal because it typically involves interacting with several different Google APIs and puts additional load on the very same APIs that are used as the control plane for GCP customers. In addition, it is quite slow especially if you have a large number of projects. |
| 9 | + |
| 10 | +This tool takes a different approach and queries information about assets from Google's [Cloud Asset Inventory API](https://cloud.google.com/asset-inventory/docs/overview) instead. This allows us to use a single API to pull down all the data about assets that could potentially have public IP addresses assigned to them which allows us to download data for organizations of any size much more efficiently. |
| 11 | + |
| 12 | +# Installation |
| 13 | + |
| 14 | +<table> |
| 15 | + <tr> |
| 16 | + <td>Homebrew (macOS or Linux)</td> |
| 17 | + <td> |
| 18 | + <code>brew tap mark-adams/gcp-ip-list && brew install gcp-ip-list</code> |
| 19 | + </td> |
| 20 | + </tr> |
| 21 | +</table> |
| 22 | + |
| 23 | +Pre-built binaries are also avalable from the [Releases page](https://github.com/mark-adams/gcp-ip-list/releases) |
| 24 | + |
| 25 | +If your system has a [supported version of Go](https://go.dev/dl/), you can build from source. |
| 26 | + |
| 27 | +``` |
| 28 | +go install github.com/mark-adams/gcp-ip-list/cmd/gcp-ip-list@latest |
| 29 | +``` |
| 30 | + |
| 31 | +# Running the tool |
| 32 | + |
| 33 | +Since this tool uses the [Google Cloud Client Libraries for Go](https://github.com/googleapis/google-cloud-go), the application will authenticate with Google using [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials). |
| 34 | + |
| 35 | +## Usage |
| 36 | +``` |
| 37 | +$ gcp-ip-list -h |
| 38 | +Usage of gcp-ip-list: |
| 39 | + -format string |
| 40 | + The output format (csv, json, table, list) (default "table") |
| 41 | + -private |
| 42 | + Include private IPs only |
| 43 | + -public |
| 44 | + Include public IPs only |
| 45 | + -scope string |
| 46 | + The scope (organization, folder, or project) to search (i.e. projects/abc-123 or organizations/123456) |
| 47 | + -version |
| 48 | + Display the current version |
| 49 | +``` |
| 50 | + |
| 51 | +### Use as a library |
| 52 | +Core functionality of the CLI is exposed via Go APIs as well in the `github.com/mark-adams/gcp-ip-list/pkg/go` package via the `GetAllAddressesFromAssetInventory()` and `GetAddressesFromAssetInventory()` functions in case you want to incoporate this functionality into your own application. |
| 53 | + |
| 54 | +## Examples |
| 55 | + |
| 56 | +### Table output |
| 57 | +``` |
| 58 | +$ gcp-ip-list --scope=projects/sample-project -public |
| 59 | ++----------------+--------------+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------+ |
| 60 | +| ADDRESS | ADDRESS TYPE | RESOURCE TYPE | RESOURCE NAME | |
| 61 | ++----------------+--------------+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------+ |
| 62 | +| 35.244.150.176 | public | compute.googleapis.com/ForwardingRule | //compute.googleapis.com/projects/sample-project/global/forwardingRules/ip-list-test-forwarding-rule-external | |
| 63 | +| 34.54.75.78 | public | compute.googleapis.com/ForwardingRule | //compute.googleapis.com/projects/sample-project/global/forwardingRules/ip-list-test-forwarding-rule-external-static | |
| 64 | +| 34.83.163.216 | public | compute.googleapis.com/Instance | //compute.googleapis.com/projects/sample-project/zones/us-west1-a/instances/ip-list-test-vm | |
| 65 | +| 34.105.8.244 | public | compute.googleapis.com/Router | //compute.googleapis.com/projects/sample-project/regions/us-west1/routers/ip-list-test-router | |
| 66 | +| 34.19.43.198 | public | container.googleapis.com/Cluster | //container.googleapis.com/projects/sample-project/locations/us-west1/clusters/ip-list-test-cluster | |
| 67 | +| 34.127.47.18 | public | sqladmin.googleapis.com/Instance | //cloudsql.googleapis.com/projects/sample-project/instances/ip-list-test-db | |
| 68 | ++----------------+--------------+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------+ |
| 69 | +``` |
| 70 | + |
| 71 | +### List output |
| 72 | + |
| 73 | +``` |
| 74 | +$ gcp-ip-list --scope=projects/sample-project -public -format=list |
| 75 | +35.244.150.176 |
| 76 | +34.54.75.78 |
| 77 | +34.83.163.216 |
| 78 | +34.105.8.244 |
| 79 | +34.19.43.198 |
| 80 | +34.127.47.18 |
| 81 | +``` |
| 82 | + |
| 83 | +This mode is handy for piping to your favorite port scanning tool like `nmap` or `naabu`: |
| 84 | +``` |
| 85 | +gcp-ip-list --scope=projects/sample-project -public -format=list | nmap -iL - |
| 86 | +``` |
| 87 | + |
| 88 | +### CSV & JSON output |
| 89 | + |
| 90 | +You can get the same output as the default table format but in CSV or JSON as well: |
| 91 | + |
| 92 | +``` |
| 93 | +gcp-ip-list --scope=projects/sample-project -public -format=csv |
| 94 | +``` |
| 95 | + |
| 96 | +``` |
| 97 | +gcp-ip-list --scope=projects/sample-project -public -format=json |
| 98 | +``` |
| 99 | + |
| 100 | +# Contributing |
| 101 | +See our [Contribution guidelines](CONTRIBUTING.md) |
| 102 | + |
| 103 | +## Terraform resources |
| 104 | +The `terraform` directory contains sample resources that are handy when doing local development on `gcp-ip-list`. |
| 105 | +If you add support for a new resource type, please add the appropriate Terraform resources in the same PR. |
| 106 | + |
| 107 | +# Releases |
| 108 | +New releases can be found on the [Releases](page). |
| 109 | + |
| 110 | +## Verifying signatures |
| 111 | +Binaries built by this project are signed using Sigstore. |
| 112 | + |
| 113 | +To verify the signature for a given binary, you can use [cosign](https://github.com/sigstore/cosign): |
| 114 | + |
| 115 | +``` |
| 116 | +$ cosign verify-blob gcp-ip-list_Darwin_x86_64/gcp-ip-list \ |
| 117 | + --bundle gcp-ip-list_Darwin_x86_64.cosign.bundle \ |
| 118 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 119 | + --certificate-identity=https://github.com/mark-adams/gcp-ip-list/.github/workflows/release.yml@refs/tags/<version> |
| 120 | +Verified OK |
| 121 | +``` |
| 122 | + |
| 123 | +# Troubleshooting |
| 124 | + |
| 125 | +## Could not find default credentials |
| 126 | + |
| 127 | +``` |
| 128 | +error getting public addresses: error setting up client: credentials: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information |
| 129 | +``` |
| 130 | + |
| 131 | +This means that you're likely running the tool locally from your workstation without having application default credentials set up. You can follow the link in the message or run `gcloud auth application-default login` to authenticate with GCP and obtain the proper credentials. |
| 132 | + |
| 133 | +## Cloud Asset API has not been used in project X before |
| 134 | + |
| 135 | +This tool depends on the Cloud Asset Inventory API being enabled. Luckily, the error message points you in the right direction. Look for "Enable it by visiting https://..." in the error message and visit that page to enable the API. |
0 commit comments