|
| 1 | +--- |
| 2 | +title: "Discover Public Assets with Steampipe and Nuclei" |
| 3 | +description: "How to use steampipe and nuclei to discover public assets." |
| 4 | +date: 2024-02-02T12:07:14-0600 |
| 5 | +lastmod: 2024-02-02T12:07:14-0600 |
| 6 | +draft: false |
| 7 | +weight: 10 |
| 8 | +categories: ["scanning"] |
| 9 | +tags: ["nuclei", "steampipe", "exposure", "sql"] |
| 10 | +contributors: ["Jonathan Walker"] |
| 11 | +pinned: false |
| 12 | +homepage: false |
| 13 | +--- |
| 14 | + |
| 15 | +There are no shortage of publicly known breaches due to accidentally exposed assets within cloud environments. Few exposures ever make it to the news cycle and occur frequently within the industry due to improper training, lack of infrastructure as code reviews, and misuse of priviledges. |
| 16 | + |
| 17 | +- [Amazon Prime Video Elasticsearch Exposure](https://techcrunch.com/2022/10/27/amazon-prime-video-server-exposed/) |
| 18 | +- [Adobe left 7.5 million Creative Cloud user records exposed online](https://www.zdnet.com/article/adobe-left-7-5-million-creative-cloud-user-records-exposed-online/) |
| 19 | +- [Exposed Jenkins instance leads to exposure of No-Fly list](https://maia.crimew.gay/posts/how-to-hack-an-airline/) |
| 20 | + |
| 21 | +When was the last time you assessed your attack surface? Do you get alerted? How often are those alerts triaged to their full extent? While CSPM tool offerings provide attack surface capabilities, one should never shy away from manual assessments on a regular cadence. Here is a quick guide on how to perform a quick attack surface assessment of AWS EC2 using [steampipe](https://steampipe.io/) and [nuclei](https://github.com/projectdiscovery/nuclei). |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +In order to get started, you need to first install steampipe and nuclei. This should help you retrieve a list of public facing assets and scan them. |
| 26 | + |
| 27 | +### Steampipe |
| 28 | + |
| 29 | +Steampipe is a tool that allows you to query your cloud resources through SQL. We are going to be using steampipe to get a list of assets to scan. Feel free to go to [Steampipe's installation guide](https://steampipe.io/downloads) for more information. |
| 30 | + |
| 31 | +{{< tabs "create-new-site" >}} |
| 32 | +{{< tab "macOS" >}} |
| 33 | + |
| 34 | +```bash |
| 35 | +brew install turbot/tap/steampipe |
| 36 | +``` |
| 37 | + |
| 38 | +{{< /tab >}} |
| 39 | +{{< tab "Linux" >}} |
| 40 | + |
| 41 | +```bash |
| 42 | +sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)" |
| 43 | +``` |
| 44 | + |
| 45 | +{{< /tab >}} |
| 46 | +{{< tab "Windows" >}} |
| 47 | + |
| 48 | +```bash |
| 49 | +# WSL Shell |
| 50 | +sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)" |
| 51 | +``` |
| 52 | + |
| 53 | +{{< /tab >}} |
| 54 | +{{< /tabs >}} |
| 55 | + |
| 56 | +#### Plugins |
| 57 | + |
| 58 | +Steampipe relies on plugins in order to perform SQL queries against your providers. Steampipe supports a wide variety of services such as AWS, GCP, Azure, Kubernetes, and so much more. We will just be covering the basics here but do not shy away from the documentation. |
| 59 | + |
| 60 | +```bash |
| 61 | +# AWS |
| 62 | +steampipe plugin install aws |
| 63 | + |
| 64 | +# GCP |
| 65 | +steampipe plugin install gcp |
| 66 | + |
| 67 | +#Azure |
| 68 | +steampipe plugin install azure |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +### Nuclei |
| 73 | + |
| 74 | +{{< tabs "create-new-site" >}} |
| 75 | +{{< tab "Go" >}} |
| 76 | + |
| 77 | +```bash |
| 78 | +go install -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latest |
| 79 | +``` |
| 80 | + |
| 81 | +{{< /tab >}} |
| 82 | +{{< tab "macOS" >}} |
| 83 | + |
| 84 | +```bash |
| 85 | +brew install nuclei |
| 86 | +``` |
| 87 | + |
| 88 | +{{< /tab >}} |
| 89 | +{{< tab "Docker" >}} |
| 90 | + |
| 91 | +```bash |
| 92 | +docker pull projectdiscovery/nuclei:latest |
| 93 | +``` |
| 94 | + |
| 95 | +{{< /tab >}} |
| 96 | +{{< /tabs >}} |
| 97 | + |
| 98 | + |
| 99 | +## Obtaining Public Compute Infrastructure |
| 100 | + |
| 101 | +```sql |
| 102 | +select |
| 103 | + instance_id, |
| 104 | + public_ip_address |
| 105 | +from |
| 106 | + aws_ec2_instance |
| 107 | +where |
| 108 | + public_ip_address is not null; |
| 109 | +``` |
| 110 | + |
| 111 | +```sql |
| 112 | +select |
| 113 | + name, |
| 114 | + dns_name, |
| 115 | + type |
| 116 | +from |
| 117 | + aws_elbv2_load_balancer |
| 118 | +where |
| 119 | + scheme = 'internet-facing'; |
| 120 | +``` |
| 121 | + |
| 122 | +```sql |
| 123 | +select |
| 124 | + load_balancer_name, |
| 125 | + dns_name |
| 126 | +from |
| 127 | + aws_elb_load_balancer |
| 128 | +where |
| 129 | + scheme = 'internet-facing'; |
| 130 | +``` |
| 131 | + |
| 132 | + |
| 133 | +```bash |
| 134 | +# Query to get EC2 instance public IPs |
| 135 | +steampipe query "select instance_id as id, public_ip_address as address from aws_ec2_instance where public_ip_address is not null;" --output csv > ec2_ips.csv |
| 136 | + |
| 137 | +# Query to get Load Balancer DNS names |
| 138 | +steampipe query "select name as id, dns_name as address from aws_elbv2_load_balancer where scheme = 'internet-facing' UNION select load_balancer_name as id, dns_name as address from aws_elb_load_balancer where scheme = 'internet-facing';" --output csv > elb_dns.csv |
| 139 | + |
| 140 | +# Combine the outputs |
| 141 | +echo "id,address" > combined_public_resources.csv |
| 142 | +tail -n +2 -q ec2_ips.csv elb_dns.csv >> combined_public_resources.csv |
| 143 | + |
| 144 | +# Cleanup |
| 145 | +rm ec2_ips.csv elb_dns.csv |
| 146 | + |
| 147 | +# Display the result |
| 148 | +cat combined_public_resources.csv |
| 149 | +``` |
| 150 | + |
| 151 | +## Conclusion |
| 152 | + |
| 153 | +[multi-region connections](https://hub.steampipe.io/plugins/turbot/aws#multi-region-connections) and [multi-account connections](https://hub.steampipe.io/plugins/turbot/aws#multi-account-connections) |
| 154 | + |
| 155 | +```bash |
| 156 | +nuclei -u $TARGET -t network/detection |
| 157 | +``` |
| 158 | + |
| 159 | +## Ports |
| 160 | + |
| 161 | + |
| 162 | +``` |
| 163 | +httpx -p 80,443,8080,8443,8000,8008,8081,81,8888,8001,8082,7080,8444,8983,9999 -l targets.txt -title |
| 164 | +
|
| 165 | + __ __ __ _ __ |
| 166 | + / /_ / /_/ /_____ | |/ / |
| 167 | + / __ \/ __/ __/ __ \| / |
| 168 | + / / / / /_/ /_/ /_/ / | |
| 169 | +/_/ /_/\__/\__/ .___/_/|_| |
| 170 | + /_/ |
| 171 | +
|
| 172 | + projectdiscovery.io |
| 173 | +
|
| 174 | +[INF] Current httpx version v1.3.9 (latest) |
| 175 | +http://44.201.243.167:8080 [Dashboard [Jenkins]] |
| 176 | +``` |
0 commit comments