Skip to content
Leaked secrets Write-up Beginner

Finding hidden gems vol. 2: REAMDE.md, the story of a bit too helpful readme file

A README.md file left in production contained AWS access keys for a sandbox and production S3 bucket. The attacker used the production keys to upload a test file, confirming write access to the bucket.

Mateusz Olejarka Follow

Published on medium.com

Sometimes this file stays as a development leftover all the way from the test environment to production. If it does not contain anything sensitive it is still fine.

Mateusz Olejarka, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

A README.md file is meant to be helpful. It is the first file most people check when they look into a new project on GitHub, and from a developer's point of view that is perfectly fine. The problem starts when the file is a development leftover that travels all the way from the test environment to production. If it contains nothing sensitive, it is still fine. This case is about a README.md that was far too helpful and should never have ended up in the production environment.

The target here is a web site that served a README.md file. The file was written as onboarding documentation for developers working with Amazon S3, and it contained AWS credentials and bucket URIs for both a sandbox and a production environment.

Setup

The researcher needed only the AWS command line interface. The file itself explains the first step:

Text
The first thing you need is to install aws-cli, which is a simple command line tool that provides a client interface to AWS services.You can find it here: http://docs.aws.amazon.com/cli/latest/userguide/installing.htmlOnce installed, you will need to provide some information to authenticate and be able to upload files to the bucket.

That passage is harmless: one developer helping another, install this and see the docs there. The researcher downloaded aws-cli and configured it with the credentials found in the file, as shown below.

Finding it

The interesting part of the file was the sandbox section:

Text
SANDBOX  AWS Access Key ID: A*****************A  AWS Secret Access Key: P****************G  Default region name: us-east-1  Default output format [None]:>I have created a testing bucket for you in our sandbox environment, the bucket URI is s3://***********-sandbox.********.comAnd to get you started with service, you can simply sync all the content of a specific folder to the S3 bucket by executing:  aws s3 sync/path/to/your/folder s3://***********-sandbox.********.com

This gave an Amazon S3 bucket URI and what looked like valid access keys. As the Amazon documentation quoted in the report puts it:

Access keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS. If you don't have access keys, you can create them from the AWS Management Console.

The sandbox bucket looked interesting, and the keys came with it, but that bucket no longer existed. So the researcher kept reading.

Further down the file was the production section:

Text
PROD  aws configure  AWS Access Key ID: A*****************Q  Secret Access Key: k****************u  Default region name: us-east-1  Default output format [None]:aws s3 sync ~/data/AWS/ s3://***********.com/  new path  aws s3 sync ~/data/WORK/AWS/ s3://***********.com/  aws s3 sync ~/data/AWS/ s3://***********.com/

This was even better: no more sandbox, this was a production S3 instance. The file also closed with an invitation to ask questions:

Text
Please go through this documentation, it's a great way to start with AWS S3: http://docs.aws.amazon.com/cli/latest/reference/s3/index.htmlIf you have any questions, please don't hesitate contacting me, I am available on Slack as well if you needed some instant responses.

Exploitation

Step 1: configure aws-cli with the production keys

The researcher configured aws-cli with the production access key ID and secret access key from the file, using the default region us-east-1:

Text
aws configureAWS Access Key ID: A*****************QSecret Access Key: k****************uDefault region name: us-east-1Default output format [None]:aws s3 cp .\\********.txt s3://***********.com/********.txt

The important parts are the aws configure values (access key ID, secret access key, region) and the aws s3 cp command that uploads a local test file to the production bucket URI taken from the file.

Step 2: verify the keys by uploading a test file

The goal was simply to check whether the keys still worked, so the researcher uploaded a test file. The keys were valid and the test file was uploaded to the bucket. At that point the researcher was in, and only needed to write a report and submit it on the bug bounty platform the company used, then wait for a bounty.

Aftermath

In the meantime, the company whose web site hosted the file stopped having a bug bounty program. The researcher searched for a security contact without immediate results, then sent a message on Twitter.

On 31.08.2017 the researcher explained the situation: a vulnerability had been found in the service, the researcher had been unaware that the bug bounty program was paused, and asked to be directed to someone to report it to. The company replied the same day, apologised for the delay and gave an email address to send the report to.

The Twitter response was quick, but the email was not. On 17.09.2017 the researcher said an email about the issue had been sent to that address with no response yet and asked for verification. The company replied that it would verify the information. The researcher then shared an email address, and more time passed.

On 4.10.2017 the researcher asked for news, noting that the email had been sent a month earlier with no response whatsoever. On 5.10.2017 the company apologised for the delayed response and said that although there was no active bounty, it would like to send some promo codes. The researcher could not use the promo codes because of geographical issues, asked for a letter of reference as a form of recognition instead, got no response again, and dropped the topic.

Root cause

A README.md written for developers ended up in the production environment. It documented the onboarding process for S3 access and included the sandbox and production access key IDs, secret access keys, region, bucket URIs and example sync commands. Serving that file publicly meant anyone who requested it received working credentials for the production bucket.

The report does not describe any server-side control that should have blocked the file.

Impact

With the production keys, the researcher was able to upload a file to the production S3 bucket, which confirms write access. The report does not say what else the keys allowed, such as reading, listing or deleting objects, or what data the bucket held.

Fix

The lessons it draws are:

  • Check what files are in the application web root and remove anything that should not be there.

Variants to test

  1. Add README.md to content discovery dictionaries, along with other documentation extensions such as txt, adoc and rst. A positive result is a documentation file served from the production host that describes internal setup, credentials or infrastructure.
  2. A positive result is the same file, or a variant, returned from a host that should not serve it.
  3. Look for onboarding notes that reference cloud storage: bucket URIs, access key IDs, secret keys, regions and example sync commands. A positive result is a credential pair that authenticates, which can be confirmed with a harmless upload of a test file as done here.
  4. A positive result is a successful authenticated call against the bucket named in the file.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A company had a public website. Somewhere on that website sat a file called README.md. A README.md is a plain text file that developers write to explain a project to each other. On GitHub, a site where people share code, it is usually the first file anyone opens when they look at a new project, and from a developer's point of view that is a good habit.

The trouble starts when such a file is a leftover from the testing phase and nobody removes it before the site goes live. If the file says nothing sensitive, no harm is done. This file said a lot. It was written to help new developers connect to the company's Amazon S3 storage, and it contained the secret keys needed to do so, for both a test setup and the real, live setup.

Amazon S3 is a service from Amazon Web Services (AWS) for storing files in the cloud. Think of it as a huge online filing cabinet: you put files into a named drawer called a bucket, and you take them out again. To open the cabinet you need a key. In AWS that key comes as a pair: an access key ID (a bit like a username) and a secret access key (a bit like a password). Anyone holding both can act as that user against AWS.

The researcher found the file, read the keys, installed Amazon's command line tool, and used the keys to upload a small test file into the company's live bucket. That upload proved the keys worked. The researcher then tried to report the problem through the company's bug bounty platform, but the company had paused its programme in the meantime. What followed was a slow exchange over Twitter and email, ending with an offer of promo codes and no fix confirmation.

Background you need first

A few ideas come up again and again below, so here they are from zero.

Web root. A website is a folder of files on a server. The web root is the top folder the web server is allowed to hand out. If a file sits in the web root, anyone who knows or guesses its address can download it, exactly as if it were a page of the site. Developers sometimes drop notes, backups or documentation into that folder without realising the whole internet can read them.

README.md. A text file, usually written in a simple formatting language called Markdown, that explains how a project works: what to install, how to configure it, who to ask for help. The .md ending is just the file extension.

AWS and S3. AWS is Amazon's cloud platform. S3 is its file storage service. Files live inside buckets, and each bucket has an address (a URI) that looks like s3://bucket-name. Programs read and write buckets through AWS's API.

API. An API is the set of doors a program offers to other programs. A website's page is for humans; an API is for software. When a tool uploads a file to S3, it is knocking on S3's API door.

Credentials, access key ID and secret access key. Credentials are the proof of who you are. For AWS, the access key ID identifies the user and the secret access key is the password-like half used to sign each request. Signing means attaching a cryptographic stamp so AWS can check the request really came from the key holder and was not altered on the way. If someone else gets both halves, they can sign requests as that user.

aws-cli. A free command line tool from Amazon. You type commands into a terminal and it talks to AWS for you. aws configure stores your key pair and default settings on your computer; aws s3 cp copies a file to or from a bucket; aws s3 sync copies a whole folder and keeps the two sides matching.

Region. AWS runs data centres in many parts of the world. The region is which one you want to talk to. us-east-1 is one of them.

Bug bounty programme. A scheme where a company invites strangers to report security problems and pays a reward, the bounty, for good reports. Companies sometimes pause these programmes, and then there is no official channel to submit through.

Information disclosure. The vulnerability class here. It simply means the system gave away information it should have kept private. Nothing was broken into; the file was served openly to anyone who asked.

The case

The target was a website whose web root served a README.md file. The file was written as onboarding documentation for developers working with Amazon S3, and it contained AWS credentials and bucket addresses for both a sandbox (test) environment and a production (live) environment.

Setup

The researcher needed only the AWS command line interface. The file itself explains the first step:

Text
The first thing you need is to install aws-cli, which is a simple command line tool that provides a client interface to AWS services.You can find it here: http://docs.aws.amazon.com/cli/latest/userguide/installing.htmlOnce installed, you will need to provide some information to authenticate and be able to upload files to the bucket.

Line by line, in plain words:

  • "The first thing you need is to install aws-cli": before you can talk to AWS from a terminal, you install Amazon's command line tool.
  • "which is a simple command line tool that provides a client interface to AWS services": the tool is a client, meaning it sits on your computer and sends requests to Amazon's servers on your behalf.
  • "You can find it here: http://docs.aws.amazon.com/cli/latest/userguide/installing.html": a link to Amazon's own installation instructions.
  • "Once installed, you will need to provide some information to authenticate and be able to upload files to the bucket": after installing, you must prove who you are (authenticate) before the bucket will accept files from you.

That passage is harmless: one developer helping another, install this and see the docs there. The researcher downloaded aws-cli and configured it with the credentials found in the file, as shown further down.

Finding it

The interesting part of the file was the sandbox section:

Text
SANDBOX  AWS Access Key ID: A*****************A  AWS Secret Access Key: P****************G  Default region name: us-east-1  Default output format [None]:>I have created a testing bucket for you in our sandbox environment, the bucket URI is s3://***********-sandbox.********.comAnd to get you started with service, you can simply sync all the content of a specific folder to the S3 bucket by executing:  aws s3 sync/path/to/your/folder s3://***********-sandbox.********.com

Line by line:

  • "SANDBOX": this block is for the test environment, a safe copy of the setup where developers can experiment.
  • "AWS Access Key ID: A*****************A": the first half of a key pair, the part that names the user. The stars are where the real characters sat; they are hidden here so the key is not published again.
  • "AWS Secret Access Key: P****************G": the second half, the password-like part used to sign requests.
  • "Default region name: us-east-1": which AWS data centre the tool should talk to by default.
  • "Default output format [None]": how results should be printed; [None] means the tool's default.
  • "I have created a testing bucket for you in our sandbox environment, the bucket URI is s3://***-sandbox..com": the address of the test bucket, ready to use.
  • "And to get you started with service, you can simply sync all the content of a specific folder to the S3 bucket by executing: aws s3 sync/path/to/your/folder s3://***-sandbox..com": a ready-made example command that copies a local folder up to the bucket.

This gave an Amazon S3 bucket address and what looked like valid access keys. As the Amazon documentation quoted in the report puts it:

Access keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS. If you don't have access keys, you can create them from the AWS Management Console.

In other words: the two halves together are what lets software prove to AWS that it is allowed in, and they can be created in AWS's web console.

The sandbox bucket looked interesting, and the keys came with it, but that bucket no longer existed. So the researcher kept reading.

Further down the file was the production section:

Text
PROD  aws configure  AWS Access Key ID: A*****************Q  Secret Access Key: k****************u  Default region name: us-east-1  Default output format [None]:aws s3 sync ~/data/AWS/ s3://***********.com/  new path  aws s3 sync ~/data/WORK/AWS/ s3://***********.com/  aws s3 sync ~/data/AWS/ s3://***********.com/

Line by line:

  • "PROD": this block is for production, the live environment real users depend on.
  • "aws configure": the command that stores a key pair and default settings on your computer.
  • "AWS Access Key ID: A*****************Q": a different access key ID from the sandbox one, this time for the live setup.
  • "Secret Access Key: k****************u": its matching secret half.
  • "Default region name: us-east-1": the same region as before.
  • "Default output format [None]": the tool's default output.
  • "aws s3 sync ~/data/AWS/ s3://***********.com/": an example command copying a local folder (~/data/AWS/, where ~ means the user's home folder) up to the live bucket.
  • "new path aws s3 sync ~/data/WORK/AWS/ s3://***********.com/": a second example, copying a different local folder to the same bucket.
  • "aws s3 sync ~/data/AWS/ s3://***********.com/": the first example repeated.

This was even better: no more sandbox, this was a production S3 instance. The file also closed with an invitation to ask questions:

Text
Please go through this documentation, it's a great way to start with AWS S3: http://docs.aws.amazon.com/cli/latest/reference/s3/index.htmlIf you have any questions, please don't hesitate contacting me, I am available on Slack as well if you needed some instant responses.

Line by line:

  • "Please go through this documentation, it's a great way to start with AWS S3": a pointer to Amazon's S3 command reference.
  • "If you have any questions, please don't hesitate contacting me, I am available on Slack as well if you needed some instant responses": the author offers to answer questions on Slack, a workplace chat tool. Friendly, and a reminder that this file was written for colleagues, not for the public.

Exploitation

Step 1: configure aws-cli with the production keys

The researcher configured aws-cli with the production access key ID and secret access key from the file, using the default region us-east-1:

Text
aws configureAWS Access Key ID: A*****************QSecret Access Key: k****************uDefault region name: us-east-1Default output format [None]:aws s3 cp .\\********.txt s3://***********.com/********.txt

Line by line:

  • "aws configure": start the setup command. The tool then asks a series of questions.
  • "AWS Access Key ID: A*****************Q": the answer to its first question, the production key ID copied from the file.
  • "Secret Access Key: k****************u": the answer to its second question, the matching secret.
  • "Default region name: us-east-1": the region to use by default.
  • "Default output format [None]": accept the default output style.
  • "aws s3 cp .\.txt s3://.com/*****.txt": copy a local test file (the .txt file in the current folder) up to the production bucket, giving it a name inside the bucket.

The important parts are the aws configure values (access key ID, secret access key, region) and the aws s3 cp command that uploads a local test file to the production bucket address taken from the file.

Step 2: verify the keys by uploading a test file

The goal was simply to check whether the keys still worked, so the researcher uploaded a test file. The keys were valid and the test file was uploaded to the bucket. At that point the researcher was in, and only needed to write a report and submit it on the bug bounty platform the company used, then wait for a bounty.

A report that says "I uploaded a harmless test file and here is its name" is far more convincing than one that says "I think these keys might work".

Aftermath

In the meantime, the company whose website hosted the file stopped having a bug bounty programme. The researcher searched for a security contact without immediate results, then sent a message on Twitter.

On 31.08.2017 the researcher explained the situation: a vulnerability had been found in the service, the researcher had been unaware that the bug bounty programme was paused, and asked to be directed to someone to report it to. The company replied the same day, apologised for the delay and gave an email address to send the report to.

The Twitter response was quick, but the email was not. On 17.09.2017 the researcher said an email about the issue had been sent to that address with no response yet and asked for verification. The company replied that it would verify the information. The researcher then shared an email address, and more time passed.

On 4.10.2017 the researcher asked for news, noting that the email had been sent a month earlier with no response whatsoever. On 5.10.2017 the company apologised for the delayed response and said that although there was no active bounty, it would like to send some promo codes. The researcher could not use the promo codes because of geographical issues, asked for a letter of reference as a form of recognition instead, got no response again, and dropped the topic.

Root cause

A README.md written for developers ended up in the production environment. It documented the onboarding process for S3 access and included the sandbox and production access key IDs, secret access keys, region, bucket addresses and example sync commands. Serving that file publicly meant anyone who requested it received working credentials for the production bucket.

The report does not describe any server-side control that should have blocked the file. An allowlist, in this context, means the server only hands out files that appear on an approved list; anything else is refused.

Impact

With the production keys, the researcher was able to upload a file to the production S3 bucket, which confirms write access. The report does not say what else the keys allowed, such as reading, listing or deleting objects, or what data the bucket held.

Fix

The lessons it draws are:

  • Check what files are in the application web root and remove anything that should not be there.

Variants to test

  1. Add README.md to content discovery dictionaries, along with other documentation extensions such as txt, adoc and rst. A content discovery dictionary is a long list of common file and folder names that a tool tries against a site, one after another, to see which ones exist. A positive result is a documentation file served from the production host that describes internal setup, credentials or infrastructure.
  2. A positive result is the same file, or a variant, returned from a host that should not serve it.
  3. Look for onboarding notes that reference cloud storage: bucket addresses, access key IDs, secret keys, regions and example sync commands. A positive result is a key pair that authenticates, which can be confirmed with a harmless upload of a test file as done here.
  4. A positive result is a successful authenticated call against the bucket named in the file.

Glossary

  • Access key ID: the half of an AWS key pair that names the user, a bit like a username.
  • Allowlist: a list of things that are permitted; anything not on it is refused.
  • API: the set of doors a program offers to other programs so they can talk to it.
  • AWS: Amazon Web Services, Amazon's cloud platform.
  • aws-cli: Amazon's command line tool for talking to AWS from a terminal.
  • aws configure: the aws-cli command that stores a key pair and default settings on your computer.
  • aws s3 cp: the aws-cli command that copies a single file to or from an S3 bucket.
  • aws s3 sync: the aws-cli command that copies a whole folder and keeps both sides matching.
  • Bucket: a named container for files in Amazon S3, like a drawer in a filing cabinet.
  • Bug bounty programme: a scheme where a company invites and rewards reports of security problems.
  • Content discovery dictionary: a list of common file and folder names used to probe a site for hidden files.
  • Credentials: the proof of identity a system accepts, such as a key pair.
  • Information disclosure: a vulnerability where the system gives away information it should have kept private.
  • Markdown: a simple formatting language for plain text files, used for files ending in .md.
  • Production: the live environment real users depend on.
  • README.md: a Markdown file that explains a project to developers.
  • Region: the part of the world where AWS runs the data centre you talk to, such as us-east-1.
  • Rotate: replace a credential with a new one and switch off the old one.
  • Sandbox: a test environment where developers can experiment without touching live data.
  • S3: Amazon's cloud file storage service.
  • Secret access key: the password-like half of an AWS key pair, used to sign requests.
  • Sign: attach a cryptographic stamp to a request so the service can check who sent it and that it was not altered.
  • Slack: a workplace chat tool.
  • URI: an address for a resource, such as s3://bucket-name.
  • Web root: the top folder on a server whose files the web server hands out to anyone who asks.
  • Write access: permission to add or change files, as opposed to only reading them.

More by Mateusz Olejarka

View all

4 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Leaked secrets and credentials

The lesson behind this report.

Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.