Open security groups: SSH, RDP, and databases reachable from anywhere

Firewall rules that allow 0.0.0.0/0 to management or database ports expose servers to constant scanning. How to find them across AWS, Azure, and GCP, and replace them with private access.

Lesson 19 of 29 · 9 min read · practice only with authorization

Diagram

Finding wide-open rules

Follow the path. One example at a time.

Step 1 of 4

Query

List rules open to the internet on sensitive ports.

Illustration: Query
$ aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values=0.0.0.0/0 \
    --query "SecurityGroups[].{id:GroupId,ports:IpPermissions[].FromPort}"
[{"id":"sg-0a1b","ports":[22,5432]}]

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Management ports

    What fails
    SSH (22) and RDP (3389) open to the internet see constant password guessing.
    Who is affected
    The server and anything it can reach.
    What you would notice
    Rules with 0.0.0.0/0 on 22 or 3389.
    What you change
    Use session manager, bastion, or identity-aware proxy access.
  2. Database ports

    What fails
    Databases reachable from the internet rely only on their passwords.
    Who is affected
    All stored data.
    What you would notice
    Rules opening 3306, 5432, 1433, 6379, 9200, or 27017 publicly.
    What you change
    Keep databases on private subnets.
  3. Temporary rules

    What fails
    Rules added for a quick test stay forever.
    Who is affected
    Whatever the rule exposes.
    What you would notice
    Rules with no description or owner.
    What you change
    Require descriptions and expire rules automatically.

Azure and GCP

The same query exists on each platform.

$ az network nsg list --query "[].securityRules[?sourceAddressPrefix=='*' && access=='Allow'].{name:name,port:destinationPortRange}" -o table
$ gcloud compute firewall-rules list --filter="sourceRanges:0.0.0.0/0" --format="table(name,allowed[].ports)"

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Which replacement removes the need for public SSH on AWS?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapCloud command lines: reading identity, not touring productionThe AWS, Azure, and Google Cloud CLIs are how you ask a cloud account what it believes.
  1. 01Cloud security fundamentals: shared responsibility, identity, and the audit trailWhat the provider secures and what you do, why identity is the cloud perimeter, and the first read-only commands to understand an AWS, Azure, or Google Cloud account you are responsible for.
  2. 02Cloud accounts and container environmentsCloud failure is usually identity and exposure.
  3. 03Workload identity instead of static keysA long-lived access key on a laptop or in a repository is a session that does not expire.
  4. 04Public object storage: finding and closing open buckets and containersBuckets made public by mistake remain one of the most common cloud leaks.
  5. 05Disabled metadata protections: IMDSv2 and why it blunts SSRFCloud instance metadata services hand out credentials to code on the machine.

Practice

  1. LabTenant deskTwo companies, one API. See what changes when the server checks ownership.

Glossary

  1. CardOpen security groupsA management port reachable from the internet is an invitation, whatever password sits on it.