onaws
onaws is a simple tool to check if an IP/hostname belongs to the AWS IP space or not. It uses the AWS IP address ranges data published by AWS to perform the search.
The tool could be helpful in:
- Continuous recon of assets
- Gathering assets that use a specific service (e.g. EC2)
- Subdomain/DNS takeovers
- Finding region information for S3 buckets
- etc.
Install
pip install onaws
Upgrade
pip install -U onaws
Usage
Given an IP:
onaws 52.219.47.34
Given a hostname:
A domain or subdomain can be passed as input:
onaws example.com
You may also supply an S3 bucket hostname as input:
onaws dropbox.s3.amazonaws.com
Given an input list
WARNING: onaws resolves each hostname individually, so if you're going to supply many hostnames, it's significantly faster to resolve them first with a tool like MassDNS!
onaws accepts line-delimited hosts on STDIN. This is helpful if you want to pipe the output of other tools to onaws:
$ cat hosts.txt
uber.s3.amazonaws.com
aws.com
google.com
23.21.52.140
$ cat hosts.txt | onaws
{
"is_aws_ip": true,
"ip_address": "52.218.106.162",
"service": "S3",
"region": "eu-west-1",
"matched_subnet": "52.218.0.0/17",
"hostname": "uber.s3.amazonaws.com"
}
{
"is_aws_ip": true,
"ip_address": "143.204.225.9",
"service": "CLOUDFRONT",
"region": "GLOBAL",
"matched_subnet": "143.204.0.0/16",
"hostname": "aws.com"
}
{
"is_aws_ip": false,
"ip_address": "216.58.201.238",
"hostname": "google.com"
}
{
"is_aws_ip": true,
"ip_address": "23.21.52.140",
"service": "EC2",
"region": "us-east-1",
"matched_subnet": "23.20.0.0/14"
}
Output
If the IP/hostname falls in the AWS IP range, onaws will return the service, region and other details in the output:
{
"is_aws_ip": true,
"ip_address": "52.218.196.155",
"service": "S3",
"region": "us-west-2",
"matched_subnet": "52.218.128.0/17",
"hostname": "flaws.cloud"
}
For multiple inputs, the output format will be in JSONL:
{
"is_aws_ip": true,
"ip_address": "143.204.225.9",
"service": "CLOUDFRONT",
"region": "GLOBAL",
"matched_subnet": "143.204.0.0/16",
"hostname": "aws.com"
}
{
"is_aws_ip": false,
"ip_address": "216.58.201.238",
"hostname": "google.com"
}
{
"is_aws_ip": true,
"ip_address": "23.21.52.140",
"service": "EC2",
"region": "us-east-1",
"matched_subnet": "23.20.0.0/14"
}
If you want to save the output to a file, you can use Bash redirection or tee:
cat hosts | onaws | tee -a output.json
More examples
To get hosts that use EC2:
cat output.json | jq -scr '.[] | select(.service == "EC2") | .hostname'
Output:
groove.uber.com
photos.uber.com
photography.uber.com
...
To get a list of hosts that use AWS services:
cat output.json | jq -sc '.[] | select(.is_aws_ip == true ) | [.hostname, .ip_address, .service] | join (",")'
Output:
assets-share.uber.com,52.84.13.77,CLOUDFRONT
groove.uber.com,3.223.41.171,EC2
devbuilds.uber.com,52.84.13.29,CLOUDFRONT
photos.uber.com,54.237.133.81,EC2
...
Errors
If the input you provide is an invalid IP or is not resolvable, the output will indicate so:
$ onaws 'invalid.invalid'
{
"hostname": "invalid.invalid",
"resolvable": false
}
If, for some reason, the tool fails to fetch the AWS IP ranges, it will throw the following exception:
$ onaws
Failed to get AWS IP ranges
Contribution
I welcome contributions from the public. If you find something that could be improved, please file an Issue or send a PR :)
Credits
- Thanks to @TomNomNom for suggesting the name.
Metadata
Release files for onaws 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onaws-1.0.3.tar.gz | 5.5 kB | Without provenance | Details for onaws-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onaws-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for onaws-1.0.3-py3-none-any.whl |
Total release size: 11.9 kB
Release files / onaws-1.0.3.tar.gz
| Download URL | onaws-1.0.3.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afde5ae6f5caa46c5c032ec9c33df353098b3af3b16eb8337c647e9dcdae45fc
|
|
BLAKE2b-256 checksum How to use checksums |
c4aa8a247a81069718ac65cc23dc803dced37eeac291f3b085bac48b252582ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Release files / onaws-1.0.3-py3-none-any.whl
| Download URL | onaws-1.0.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
897901924e91e699eb55282bfd6926710dbdd535bef78a3a8921b172904e2e74
|
|
BLAKE2b-256 checksum How to use checksums |
715f783ba506d23efbc8049c988887726188482d559d2eff423dd3b9c143f91a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Security for onaws 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.