KHAGAN AYDIN

OWASP 2017 A6: Security Misconfiguration

One wrong permission, and a whole dataset is a public download.

· 11 min read

Security Misconfiguration is a security vulnerability created by settings, not code: a server, storage bucket, database or console left open or on unsafe defaults. It is number six on the OWASP Top 10 2017. It was number five in 2013. In the new edition, XML External Entities entered at four and the merged Broken Access Control item took five, so misconfiguration moved down one place. Its rank barely changed. What it covers changed a great deal.

Many of the most reported data exposures of 2017 involved no exploit at all. Nobody guessed a password or found an injection. Someone found a storage bucket, a database or an admin console that answered anyone who asked, and took what was there.

What changed from 2013

The 2013 version of this item, which I covered in the 2013 essay, was mostly about servers: default accounts, debug modes left on, stack traces in error pages, admin consoles on the public interface. Those still happen and the old advice still holds.

The 2017 text adds a new layer. It names wrongly set cloud service permissions as misconfiguration, lists containers, prebuilt virtual machine images and storage among the places it occurs, and one of its four example attacks is a cloud storage service whose sharing settings expose files to the internet. Its prevention advice now says to review cloud storage permissions, such as buckets on Amazon Simple Storage Service (S3), during patch management.

The reason is simple. In 2013, a server usually sat on a network someone else had put a firewall in front of. By 2017, a developer could create a database, a storage bucket and a public address from a web console in a minute, with no ticket and no network engineer. The firewall became a setting on a form. When the setting is wrong, nothing else stands behind it.

Why one click publishes everything

A storage bucket is not a folder on a server. It is one permission boundary that can hold millions of files, with its own address on the internet. On Amazon S3 the bucket name is part of the hostname, acme-call-logs.s3.amazonaws.com, and names are guessable: company name plus backup, logs or prod. They also leak through page source and mobile apps.

So one setting decides everything. If the bucket allows anonymous listing, one request returns every file name and a short script downloads the lot. There is no login page to slow anyone down and nothing in your application logs, because your application was never involved. A database with a public address and no password is the same: it answers whoever connects.

Four cases from 2017 and early 2018

Verizon customer records, via a vendor, July 2017. A researcher at the security firm UpGuard found an S3 bucket controlled by NICE Systems, an Israel-based company that ran call center services for Verizon. It held logs of customer service calls from the first half of 2017: names, addresses, phone numbers and, for some customers, the account PIN used to verify callers on the phone. UpGuard estimated up to 14 million records; Verizon said about 6 million unique customers. UpGuard reported it on June 13, and the bucket was not locked until June 22. Root cause: a bucket set to allow public access, holding live customer data, run by a third party.

Accenture, October 2017. UpGuard found four S3 buckets belonging to the consulting firm, set so anyone with the address could download their contents. They held private signing keys, virtual private network keys, credentials for other cloud accounts, a database backup with about 40,000 plain text passwords, and, in a plain text file, the master access key for the company’s Amazon Web Services (AWS) Key Management Service account. Accenture locked the buckets the day after it was told. Root cause: a public bucket used as a place to keep the secrets that protect everything else.

MongoDB ransom wave, January 2017. Attackers scanned the internet for MongoDB databases that accepted connections without a password, copied the data, deleted it, and left a note asking for a bitcoin ransom. The count of hit databases passed 27,000 within days. The following week the same crews turned to Elasticsearch search clusters, deleting every index and leaving one named warning that held the ransom note. Root cause: databases on public addresses with no authentication. For years MongoDB’s default install listened on every network interface, not only the local machine, and many operators never added a password.

Tesla, reported February 2018. The cloud security firm RedLock found a Kubernetes console (Kubernetes is a system that runs and manages software containers across many machines) belonging to Tesla with no password. One of the containers it managed held credentials for Tesla’s AWS account. Attackers had used the console to run cryptocurrency mining software, kept quiet with low processor use and an unusual port. Tesla said it fixed the problem within hours and that the impact appeared limited to internally used engineering test cars. RedLock had found the same open consoles at the insurer Aviva and the SIM card maker Gemalto in October 2017. Root cause: an admin console on the internet with no login, holding keys to the wider cloud account.

In November 2017 UpGuard also reported a public bucket of the US Army’s Intelligence and Security Command holding files marked Top Secret. Misconfiguration does not care how sensitive the data is.

Buckets: the policy that publishes, and the one that does not

There are two ways to make an S3 bucket public: its access control list (ACL) and its bucket policy, a JSON document that grants or denies actions. This policy is the kind written when a vendor “just needs to download the files”:

Vulnerable bucket policy

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": ["s3:GetObject", "s3:ListBucket"],
    "Resource": ["arn:aws:s3:::acme-call-logs", "arn:aws:s3:::acme-call-logs/*"]
  }]
}

"Principal": "*" means everyone on the internet, signed in or not. s3:ListBucket hands them the index.

Fixed bucket policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {"AWS": "arn:aws:iam::111122223333:role/vendor-log-reader"},
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::acme-call-logs/exports/*"
    },
    {
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::acme-call-logs", "arn:aws:s3:::acme-call-logs/*"],
      "Condition": {"Bool": {"aws:SecureTransport": "false"}}
    }
  ]
}

One named role in the vendor’s account may read one prefix. No listing. Plain HTTP is refused for everyone.

Now the trap that catches careful people. One group the ACL editor offers is Authenticated Users. It sounds like your users. It means anyone with any AWS account, which is anyone with a credit card. That grant is how Dow Jones exposed at least 2.2 million customer records, as UpGuard reported in July 2017. Check your ACLs for it:

aws s3api get-bucket-acl --bucket acme-call-logs
{
  "Grantee": {
    "Type": "Group",
    "URI": "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
  },
  "Permission": "READ"
}

A grant to AllUsers is the anonymous version of the same mistake. Reset the bucket with aws s3api put-bucket-acl --bucket acme-call-logs --acl private, and remember that each object carries its own ACL: a private bucket can still hold public objects.

Databases and consoles: the network is the internet

A security group is the cloud firewall attached to a server. This is the rule that put tens of thousands of databases into the ransom wave:

Vulnerable rule

aws ec2 authorize-security-group-ingress --group-id sg-1a2b3c4d \
    --protocol tcp --port 27017 --cidr 0.0.0.0/0

0.0.0.0/0 is every address on the internet. The database should accept only the application servers that use it, and the cleanest way to say so is to name their security group:

Fixed rule

aws ec2 revoke-security-group-ingress --group-id sg-1a2b3c4d \
    --protocol tcp --port 27017 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id sg-1a2b3c4d \
    --protocol tcp --port 27017 --source-group sg-5e6f7a8b

Then close it again on the database, so one wrong firewall rule is not all that stands between your data and the internet. For MongoDB, in mongod.conf:

net:
  bindIp: 127.0.0.1,10.0.2.15
security:
  authorization: enabled

The first setting listens only on the local machine and one private address. The second requires a login. MongoDB 3.6, released in December 2017, finally binds to localhost by default, but any server installed earlier keeps whatever its config file says.

The same thinking applies to container consoles. A Kubernetes dashboard should have no public address at all. Reach it through kubectl proxy from a machine that already holds cluster credentials, and run it under an account that can view, not one that can administer the cluster.

Cloud keys: the misconfiguration that multiplies

In both the Accenture and Tesla cases, the first mistake exposed a key, and the key was worth far more than the files around it. Cloud access keys are often created with every permission because it makes the error messages go away:

Vulnerable key policy

{"Version": "2012-10-17",
 "Statement": [{"Effect": "Allow", "Action": "*", "Resource": "*"}]}

Fixed key policy

{"Version": "2012-10-17",
 "Statement": [{"Effect": "Allow",
   "Action": ["s3:GetObject", "s3:PutObject"],
   "Resource": "arn:aws:s3:::acme-uploads/incoming/*"}]}

Better still, create no long-lived keys for code running in AWS. Give the server or container a role in AWS Identity and Access Management (IAM), and the platform hands it short-lived credentials that rotate on their own. There is then no key to leave in a container, a bucket or a Git repository.

Configuration as code, with review and a check that fails the build

In every case above a setting was wrong and nothing caught it. Treat infrastructure like application code: write buckets, policies and security groups in templates (AWS CloudFormation or Terraform), keep them in version control, require a second person to approve changes, and deploy only from the template. Then run an automated check on every build and nightly against the live account, because people still click.

A small check that fails the build when anything is public:

import json
import sys
import boto3
from botocore.exceptions import ClientError

PUBLIC_GROUPS = ("http://acs.amazonaws.com/groups/global/AllUsers",
                 "http://acs.amazonaws.com/groups/global/AuthenticatedUsers")
OPEN_TO_WORLD_OK = {80, 443}

def bucket_problems(s3, name):
    found = []
    for grant in s3.get_bucket_acl(Bucket=name)["Grants"]:
        if grant["Grantee"].get("URI") in PUBLIC_GROUPS:
            found.append("ACL grants %s to %s" % (grant["Permission"], grant["Grantee"]["URI"]))
    try:
        policy = json.loads(s3.get_bucket_policy(Bucket=name)["Policy"])
    except ClientError:
        return found
    statements = policy["Statement"]
    if isinstance(statements, dict):
        statements = [statements]
    for st in statements:
        who = st.get("Principal")
        if isinstance(who, dict):
            who = who.get("AWS")
        if st.get("Effect") == "Allow" and who in ("*", ["*"]):
            found.append("policy allows everyone" + (" (with a condition)" if "Condition" in st else ""))
    return found

def group_problems(group):
    found = []
    for perm in group["IpPermissions"]:
        world4 = any(r.get("CidrIp") == "0.0.0.0/0" for r in perm.get("IpRanges", []))
        world6 = any(r.get("CidrIpv6") == "::/0" for r in perm.get("Ipv6Ranges", []))
        if not (world4 or world6):
            continue
        ports = set(range(perm.get("FromPort", 0), perm.get("ToPort", 65535) + 1))
        if perm["IpProtocol"] == "-1" or not ports <= OPEN_TO_WORLD_OK:
            found.append("open to the internet on %s" % perm.get("FromPort", "all ports"))
    return found

def main():
    s3, ec2 = boto3.client("s3"), boto3.client("ec2")
    problems = []
    for b in s3.list_buckets()["Buckets"]:
        problems += ["bucket %s: %s" % (b["Name"], p) for p in bucket_problems(s3, b["Name"])]
    for g in ec2.describe_security_groups()["SecurityGroups"]:
        problems += ["group %s: %s" % (g["GroupId"], p) for p in group_problems(g)]
    for p in problems:
        print(p)
    sys.exit(1 if problems else 0)

if __name__ == "__main__":
    main()

A bucket meant to be public, such as one serving website images, goes on an explicit allow list in the script and holds nothing else. AWS added two managed AWS Config rules in August 2017, s3-bucket-public-read-prohibited and s3-bucket-public-write-prohibited, and since November 2017 the S3 console marks public buckets. Use them, but a label in a console is not a control.

Why the usual fixes fail

“We reviewed the settings.” A review is a snapshot. The Verizon bucket belonged to a vendor, outside any review Verizon ran.

“Nobody knows the bucket name.” Names are guessable, appear in client code, and scanners try thousands of words an hour.

“Listing is off.” Then the attacker needs a file name, which an old log or a sequential naming scheme will supply.

“It’s only the test environment.” Test systems hold copies of production data and keys more often than anyone admits.

“We have a firewall.” A bucket or a cloud database with a public address never passes through the corporate firewall.

Default deny

The rule that ends this class of bug is the one that ends most access problems: nothing is reachable or readable unless a written, reviewed rule says so. Databases, caches and search clusters live on private subnets with no public address. 0.0.0.0/0 is allowed on ports 80 and 443 of the load balancer and nowhere else. Every exception lives in the template, with a comment saying who asked for it and why.

How to test your own

  1. List every bucket and run the check above, or the equivalent by hand with get-bucket-acl and get-bucket-policy.
  2. Test from outside, the way an attacker does. aws s3 ls s3://acme-call-logs --no-sign-request tests anonymous access. Then run the same command with a profile from a separate, unrelated AWS account. This is the step most teams skip, and it is the only one that catches the Authenticated Users grant.
  3. Pick a known object key and fetch it with curl and no credentials, even if listing failed.
  4. Scan your own public address ranges: nmap -Pn -p 2375,5601,6379,9200,10250,27017 <your ranges>. Those are the Docker API, Kibana, Redis, Elasticsearch, the Kubernetes node agent and MongoDB. None should answer from the internet.
  5. Search repositories and container images for access keys. AWS access key IDs begin with AKIA.
  6. List the users and roles with full administrator rights, and ask why each one has them.

Checklist

  • Cloud resources defined in templates, changed only by reviewed commits.
  • An automated check for public buckets, open security groups and overpowered keys, on every build and every night.
  • No "Principal": "*", AllUsers or AuthenticatedUsers grants outside documented public asset buckets.
  • Databases on private addresses with authentication on, even behind a firewall.
  • No admin console with a public address.
  • Roles instead of long-lived keys, scoped to what the code uses.
  • Vendors who hold your data held to the same rules, in the contract and in an audit.

Security misconfiguration used to mean a server someone forgot to harden. In the cloud it means a permission someone forgot to check, and the cost of forgetting went from one server to the whole dataset. You will not fix that by asking people to be more careful in a console. You fix it by making the safe setting the only one your templates can produce, and by checking the live account every day for the times someone went around them.