Discover internet-wide misconfigurations while drinking coffee

Overview

License: MIT PRs Welcome

netz 🌐 πŸ¦…

The purpose of this project is to discover an internet-wide misconfiguration of network components like web-servers/databases/cache-services and more. The basic use-case for such misconfiguration - a service that is publicly exposed to the world without a credentials Β―\_(ツ)_/Β―

You probably familiar with tools like Shodan, Censys, ZoomEye to query such wide internet components,
but here we are going to do it in a fun way :: by hands :D

The tools we are going to use are masscan, and zgrab2 from ZMap project. For the first phase of port scanning, we will use masscan, then for the second phase, we will run zgrab2 to check applicative access for those ports.

ZMap is also internet-wide scanner, so why masscan and not ZMap..? because we want to go wild and use kernel module PF_RING ZC (Zero Copy) to get blazing fast packets-per-second to scan the entire internet in minutes, and ZMap basically does support it in the past, but now ZMap doesn't compatible with the latest PF_RING ZC (Zero Copy).

Note that PF_RING ZC (Zero Copy) requires a license per MAC/NIC (you can run 5 minutes in demo before it will kill the flow), and you need a special NIC from Intel (don't worry, the public cloud has such) so you can go without this module, and pay on time to wait for results.

There are few options to run this project:

  1. Use netz cloud runner tool - this tool automate the full pipeline, including infrastructure on top of AWS
  2. Run by yourself using docker
  3. For PF_RING ZC (Zero Copy) run by yourself the infrastructure and using pf_ring setup

If you want to read more about it, you can found it here: Scan the whole internet while drinking coffee

TL;DR

In discover.sh you will find a test for Elasticsearch.
The flow is:

  • run masscan on the entire internet for port 9200 (Elasticsearch port)
  • pipe ip list from step 1 into zgrab2 (you can change with ZGRAB2_ENDPOINT environment variable for any Elasticsearch API Endpoint, for instance: /_cat/indices
  • extract with jq just those ip's that return HTTP 200 OK and include lucene_version

This flow result is ips' that has internet access to Elasticsearch without credentials.

This test flow demonstrates Elasticsearch scan. You can run such scans on any port (service port) you wish and on any supported protocol by zgrab2 modules. Environment variables can modify more control:
PORT_TO_SCAN
SUBNET_TO_SCAN
ZGRAB2_ENDPOINT

In case you wish to add a missing protocol, you can extend zgrab2 by adding new protocols

We will go through a setup to be faster and faster (decreasing the time to wait).

Let's Go πŸš€

1. netz cloud runner tool

This is the easiest option as it automates everything in AWS on top of Elastic Container Service (ECS).
What it does:

  • Create IAM role for the pipeline
  • Put IAM Policy
  • Create Instance Profile
  • Associate IAM role to Instance Profile
  • Create Temporary ECS Cluster
  • Create EC2 instance (instance type based on user input --instance-type)
  • Create a number of Network Interfaces (number based on user input --number-of-nic)
  • Create Public Elastic IP (number based on user input --number-of-nic)
  • Associate Elastic IP with Network Interface (for each user input --number-of-nic)
  • Run ECS task with the scanning pipeline
  • Create CloudWatch log group and stream the pipeline docker output into the user terminal
  • Destroying all AWS resources
  • Done

How to run

Configure AWS credentials, you can do it by ~/.aws/credentials,
or by settings environment variables:
AWS_REGION
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

Install Golang 1.14 +

$ go build github.com/SpectralOps/netz
$ netz
NAME:
   netz - netz cloud runner

USAGE:
   netz [options]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug                        Show debugging information (default: false)
   --file value                   Task definition file in JSON or YAML
   --cluster value                ECS cluster name (default: "netz")
   --log-group value              Cloudwatch Log Group Name to write logs to (default: "netz-runner")
   --security-group value         Security groups to launch task. Can be specified multiple times
   --subnet value                 Subnet to launch task.
   --region value                 AWS Region
   --number-of-nic value          Number of network interfaces to create and attach to instance. (default: 0)
   --instance-type value          Instance type.
   --instance-key-name value      Instance key name to for ssh.
   --role-name value              Role name for netz. (default: "netzRole")
   --role-policy-name value       Role policy name for netz. (default: "netzPolicy")
   --instance-profile-name value  Instance profile name to attach to instance. (default: "netzInstanceProfile")
   --task-timeout value           Task timeout (in minutes), stop everything after that. (default: 120)
   --skip-destroy                 Skip destroy of cloud resources when done. (default: false)
   --help, -h                     show help (default: false)
Required flags "file, security-group, subnet, region, number-of-nic, instance-type, instance-key-name"

Example

$ netz --file taskdefinition.json --security-group sg-XXXXXXXXXXXXXXXXXX --subnet subnet-XXXXXXXX --region us-west-1 --debug --number-of-nic 5 --instance-type c4.8xlarge --instance-key-name XXXXXXXXX

⚠️
Because masscan meltdown the network, SSH mostly will not be available, also CloudWatch logs will be deferred, so the tailed logs in user terminal will take some time.

Note that taskdefinition.json is related to running with the automated way with AWS ECS.
In that file, you will be able to change the subnet & port to scan, also the application endpoint.
In this file, you can also control the CPU & RAM you allocate to the task. This test assumed c4.8xlarge, so the config is 60 x cpu and 36 GB RAM.

Result

On AWS with c4.8xlarge with 6 x NIC ~ 2.9M ~ 3.5M PPS => took 25 minutes

2. Run by yourself using docker

2.1 Basic

Run with Docker on basic computer/NIC

Steps
$ git clone https://github.com/SpectralOps/netz
$ cd netz
$ docker build -t netz .
$ docker run -e PORT_TO_SCAN='9200' -e SUBNET_TO_SCAN='0.0.0.0/0' -e ZGRAB2_ENDPOINT='/' -e TASK_DEFINITION='docker' -v /tmp/:/opt/out --network=host -it netz

⚠️
The time to scrape the entire internet with simple hardware and simple internet backbone could take days

3. Faster ⚑

Run with Docker on Cloud with one 10gbps NIC

Run instance with one 10gbps NIC (e.g. in AWS c4.8xlarge [already configured with])

Steps are the same as 2.1 Basic.

Result

On AWS with c4.8xlarge ~ 700k ~ 950k PPS => took 2.5 hours.

4. Faster++ ⚑ πŸ’«

Run with Docker on Cloud with multiple 10gbps NIC (e.g. in AWS c4.8xlarge 10gbps NIC )

  • Run in AWS c4.8xlarge Ubuntu 18.04 and connect multiple NIC (ENI's)
  • For each NIC you need to configure the OS to see those new NIC's.

Edit the netplan file: vim /etc/netplan/50-cloud-init.yaml

Now it has one NIC:

network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: 06:XX:XX:XX:XX:XX
            set-name: ens3

You need to add the second, the third and so on...

network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: 03:XX:XX:XX:XX:XX
            set-name: ens3
        ens4:
            dhcp4: true
            match:
                macaddress: 04:XX:XX:XX:XX:XX
            set-name: ens4
        ens5:
            dhcp4: true
            match:
                macaddress: 05:XX:XX:XX:XX:XX
            set-name: ens5
        ens6:
            dhcp4: true
            match:
                macaddress: 06:XX:XX:XX:XX:XX
            set-name: ens6
        ens7:
            dhcp4: true
            match:
                macaddress: 07:XX:XX:XX:XX:XX
            set-name: ens7

Apply network configuration: sudo netplan --debug apply

Steps are the same as 2.1 Basic.

Note that now with multiple NICs, the masscan configuration that will be created in docker run will contain all NICs:

e.g masscan.conf:

adapter[0] = ens3
router-mac[0] = 06:XX:XX:XX:XX:XX
adapter-ip[0] = 172.31.8.167
adapter-mac[0] = 06:YY:YY:YY:YY:YY
adapter[1] = ens4
router-mac[1] = 06:XX:XX:XX:XX:XX
adapter-ip[1] = 172.31.8.76
adapter-mac[1] = 06:YY:YY:YY:YY:YY
adapter[2] = ens5
router-mac[2] = 06:XX:XX:XX:XX:XX
adapter-ip[2] = 172.31.1.233
adapter-mac[2] = 06:YY:YY:YY:YY:YY

Result

On AWS with c4.8xlarge with 6 x NIC ~ 2.9M ~ 3.5M PPS => took 35 minutes

5. Faster++++ ⚑ πŸ’« πŸŒͺ️

Run on Cloud with 10gbps NIC with PF_RING ZC (Zero Copy)

In case you want to scrape the internet in a few minutes with PF_RING ZC (Zero Copy), you will need to run a machine that supports the kernel device drivers and a machine that has 10gbps NIC.

Notes:

  • Because PF_RING ZC (Zero Copy) bypasses the TCP stack, so in case you have just one NIC ens3 and you will open it with zc:enc3, you will lose SSH access. If you still want SSH access, you will need another NIC, e.g. ens4, then open ens4 with zc, so it will be zc:ens4, so ens3 will continue as management NIC for SSH.
  • If you run a machine with 1gbps NIC, it will still be fast, but it will take x10 more time you could Β―\_(ツ)_/Β―
  • You don't have to run such a machine like c4.8xlarge, you can run each machine that supports the ixgbevf
    from: enhanced networking with the Intel 82599 VF interface

Steps

$ git clone https://github.com/SpectralOps/netz
$ cd netz

Edit masscan.conf -- important look that now the adapter prefix is zc::

adapter[0] = zc:ens4
router-mac[0] = 06:XX:XX:XX:XX:XX
adapter-ip[0] = 172.31.8.167
adapter-mac[0] = 06:YY:YY:YY:YY:YY

The adapter-ip and adapter-mac you can get from the command: ifconfig
The adapter-mac you can get from the command: arp -a

Run configure_pf_ring.sh

Before the kernel module kicked in - this should be the state:

$ sudo pf_ringcfg --list-interfaces
Name: ens3                 Driver: ixgbevf    [Supported by ZC]
Name: docker0              Driver: bridge
Name: ens6                 Driver: ixgbevf    [Supported by ZC]
Name: ens5                 Driver: ixgbevf    [Supported by ZC]
Name: ens4                 Driver: ixgbevf    [Supported by ZC]

After the kernel module kicked in - this should be the state:

$ sudo pf_ringcfg --list-interfaces
Name: ens3                 Driver: ixgbevf    [Running ZC]
Name: docker0              Driver: bridge
Name: ens6                 Driver: ixgbevf    [Running ZC]
Name: ens5                 Driver: ixgbevf    [Running ZC]
Name: ens4                 Driver: ixgbevf    [Running ZC]

Run scan:

PORT_TO_SCAN='9200' SUBNET_TO_SCAN='0.0.0.0/0' ZGRAB2_ENDPOINT='/' TASK_DEFINITION='docker' bash -x discover.sh

Result

On AWS with c4.8xlarge with 4 x NIC ~ 10.5M ~ 12M PPS => took 10 minutes

Disclaimer

Our main drive in life is to make the world a better and safer place. If you would like to use this information to harm someone, you are doing the opposite, and at your own risk.

Copyright

Copyright (c) 2020 Uri Shamay @cmpxchg16. See LICENSE for further details.

You might also like...
kitex running in kubernetes cluster and discover each other in kubernetes Service way

Using kitex in kubernetes Kitex [kaΙͺt'eks] is a high-performance and strong-extensibility Golang RPC framework. This go module helps you to build mult

Whichip: discover (IoT) device's IP in local network
Whichip: discover (IoT) device's IP in local network

whichip: discover (IoT) device's IP in local network Install On (IoT) Device wget -O install.sh

Tackle Add-on to discover information from a source repository

Tackle Add-ons - Discovery - Languages This add-on explores the source code repository and finds the languages using GitHub Linguist. It's common that

Discover and remediate Log4Shell vulnerability [CVE-2021-45105]

sakuraji_log4j This tool is used to discover and remedidate the Log4Shell vulnerability [CVE-2021-45105] by removing the 'JndiLookup.class' file from

Reduce debugging time while programming Go. Use static and stack-trace analysis to determine which func call causes the error.
Reduce debugging time while programming Go. Use static and stack-trace analysis to determine which func call causes the error.

Errlog: reduce debugging time while programming Introduction Use errlog to improve error logging and speed up debugging while you create amazing code

espnwrapper to track real time scores for your fav match... in a terminal while working.
espnwrapper to track real time scores for your fav match... in a terminal while working.

An espncricinfo wrapper written in go to track scores in real time and in the cmd/cli you can find the Command Line Interface wrapped over this wrapper.

Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Search for vulnerabilities and exposures while filtering based on age, keywords, and other parameters.
Search for vulnerabilities and exposures while filtering based on age, keywords, and other parameters.

FAV/E FAV/E (Find A Vulnerability/Exposure) utilizes the NIST CVE database search API to search for vulnerabilities and exposures while filtering base

Type to unmarshal JSON objects while keeping the order of the keys.

orderedjson import "github.com/aybabtme/orderedjson" Sometimes you decode a JSON object in Go, and despite the JSON spec technically requiring that ke

This is my first golang project. The main reason for its existence is the need for practice. I will be studying golang while writing this project

My first GoLang project Project Aim The goal of this project is to develop the most simple golang bot to learn how to work with this programming langu

Count Dracula is a fast metrics server that counts entries while automatically expiring old ones

In-Memory Expirable Key Counter This is a fast metrics server, ideal for tracking throttling. Put values to the server, and then count them. Values ex

Hot-swap Kubernetes clusters while keeping your microservices up and running.

Okra Okra is a Kubernetes controller and a set of CRDs which provide advanced multi-cluster appilcation rollout capabilities, such as canary deploymen

How fast could I write tic tac toe in Go, while not knowing Go, but with the aid of GitHub Copilot?

tictactoe-go-with-copilot How fast could I write tic tac toe in Go, while not knowing Go, but with the aid of GitHub Copilot? This took me about 30 mi

A webservice made while learning Go following the Pluralsight course "Go: Getting Started"

go-webservice A webservice made while learning Go following the Pluralsight course "Go: Getting Started" Steps to get the webservice up and running (s

This repository is where I'm learning to write a CLI using Go, while learning Go, and experimenting with Docker containers and APIs.

CLI Project This repository contains a CLI project that I've been working on for a while. It's a simple project that I've been utilizing to learn Go,

Setgroups hanging bug while using golang

Setgroups hanging bug while using golang 1.16+ 1. How to reproduce 1.1 Build docker image build the test image docker build --build-arg=GOPROXY=$GOPRO

A telegram bot to help remember tips about cards in your hand while playing Hanabi
A telegram bot to help remember tips about cards in your hand while playing Hanabi

πŸŽ† Hanabi Assistant Bot πŸ€– Hanabi Assistant is a telegram bot to help remember tips about cards in your hand while playing Hanabi. Before Run: Generat

Practice codes developed while practicing Go

Getting started with Go Programming Language - Oreilly Course Practice codes developed while practicing Go. This is my first encounter with Go Program

For productivity addicts who enjoys coding while listening to Spotify
For productivity addicts who enjoys coding while listening to Spotify

🎡 nvim-spotify For productivity addicts who enjoys coding while listening to Sp

Comments
  • Can't find `zgrab2` output file

    Can't find `zgrab2` output file

    Hi, I'm running the tool locally using docker. I run the tool using the command:

    docker run -e PORT_TO_SCAN='80' -e SUBNET_TO_SCAN='<Random Range>' -e ZGRAB2_ENDPOINT='/' -e TASK_DEFINITION='docker' -v /tmp/:/opt/out --network=host netz
    

    This generates an output file for masscan as /tmp/masscan-docker.out However, I can't seem to find any output/result file for zgrab2. Am I doing something wrong here or does the tool simply not generate a zgrab2 output file? How can I get the zgrab2 output file too?

    opened by alt-glitch 5
  • Scanning Costs

    Scanning Costs

    Hello

    Please, any estimate on the cost of a single port scan on aws? I have never run a full scan because halfway through the scan I get abused by aws alerts.

    thank you

    opened by allwithfly 3
  • Non-existant AMI - cannot run netz

    Non-existant AMI - cannot run netz

    Hi all,

    Getting this error when attempting to run netz on AWS:

    [2022-08-08 02:14:47] DEBUG aws going to create ec2 instance
    [2022-08-08 02:14:47] ERROR InvalidAMIID.NotFound: The image id '[ami-02649d71054b25d22]' does not exist
    	status code: 400, request id: 207603a5-b3e6-439f-9724-6a350a5034ff
    

    Any advice? Thanks!

    opened by cyn8 6
Owner
Automated Code Security for Modern Teams
null
Prevent Kubernetes misconfigurations from ever making it (again 😀) to production! The CLI integration provides policy enforcement solution to run automatic checks for rule violations. Docs: https://hub.datree.io

What is Datree? Datree helps to prevent Kubernetes misconfigurations from ever making it to production. The CLI integration can be used locally or in

datree.io 6.1k Jan 1, 2023
Being played at The Coffee House and try to find and play it on Spotify

The Coffee House Muzik Follow the music that is being played at The Coffee House and try to find and play it on Spotify. Installation Clone this proje

SangND 4 May 25, 2022
Static analysis for CloudFormation templates to identify common misconfigurations

cfsec What is it? cfsec scans your yaml or json CloudFormation configuration files for common security misconfigurations. Installation Home Brew - Mac

Aqua Security 56 Nov 7, 2022
Resolved the issue that Windows cannot detect the Internet even if it does have an Internet connection.

win-connect δΈ­ζ–‡ζ–‡ζ‘£ Background This program is built to resolved the issue that Windows cannot detect the Internet even if it does have an Internet conne

null 0 Dec 19, 2021
Network-wide ads & trackers blocking DNS server

Privacy protection center for you and your devices Free and open source, powerful network-wide ads & trackers blocking DNS server. AdGuard.com | Wiki

AdGuard 15.3k Dec 31, 2022
SPIRE is a toolchain of APIs for establishing trust between software systems across a wide variety of hosting platforms

SPIRE (the SPIFFE Runtime Environment) is a toolchain of APIs for establishing trust between software systems across a wide variety of hosting platforms

SPIFFE 1.3k Jan 2, 2023
Free and open source, powerful network-wide ads & trackers blocking DNS server

Privacy protection center for you and your devices Free and open source, powerful network-wide ads & trackers blocking DNS server. AdGuard.com | Wiki

Lupael 1 Nov 20, 2021
keep track of things you learn / discover everyday!

?? Personal Archive Personal-Archive keeps track of things you learn / discover everyday! ?? Why I face tons of articles every day. Via googling or RS

Lee Jaeyong 31 May 23, 2022
Discover expired TLS certificates in the services of a kubernetes cluster

About verify-k8s-certs is a daemon (prometheus exporter) to discover expired TLS certificates in a kubernetes cluster. It exposes the informations as

Angelo Poerio 7 Feb 1, 2022
This map is totally blank for me. Let's discover it until we find the treasure!

Go Playground Yet another playground project. This time to learn a bit of Go! Know the business details about this project looking at the docs folder.

Willian Antunes 4 Sep 15, 2021