Finding hidden gems vol. 4: Rakefile a.k.a. how to get AWS keys again
A Rakefile was publicly accessible and referenced a deployment configuration file, which was also accessible and contained AWS keys. An attacker could use these keys to access AWS resources.
Published on medium.com
Staying in application development area as in previous post. Some time ago I was interested in applications created in Ruby.
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.
Context
This is the fourth instalment in a series about files that end up in an application's web root when they were never meant to be served. The previous part looked at a .sh file; this one stays in application development territory and looks at Ruby projects. Rake is a Make-like build tool implemented in Ruby, and its task definitions live in a file called Rakefile, written in standard Ruby syntax. A Rakefile is the Ruby world's equivalent of a Makefile: it declares tasks, prerequisites and rule patterns, and it can reference other files the build depends on.
The target here is not a single named product. The researcher worked from a list of domains and checked them for exposed development files. The asset recorded for the write-up is medium.com, which is where the story was published, not the host that was tested.
Setup
The tooling was deliberately simple: a multi-threaded Python script, the same approach used in the earlier part of the series, run against a domain list to see whether any of these files were reachable. No accounts, roles or special preconditions are described. The only input was the domain list and the set of filenames to probe for.
Finding it
The starting point was a review of trending Ruby repositories on GitHub. Browsing that list, the researcher noticed that some projects ship a Rakefile. Since a Rakefile is plain Ruby and describes how the project is built and deployed, it can carry references to configuration paths and other internals. That made it worth adding to the list of filenames to probe for on live hosts.
Running the script against the domain list turned up several Rakefile files. One of them stood out:
require ‘rubygems’require ‘bundler/setup’require ‘rake’require ‘rspec/core’require ‘rspec/core/rake_task’[ — CUT — ]path = “conf/deployment.yml”[ — CUT — ]task :spec => :buildtask :default => :build
The file pulls in RubyGems, Bundler, Rake and RSpec, and then, in the part shown, assigns a path: conf/deployment.yml. That is a reference to a deployment configuration file. The reasoning from there was straightforward: the Rakefile itself is only a hint, but the file it points at is where the interesting data would live. The expectation was that requesting deployment.yml would return a 403, since configuration directories are usually protected, but it was worth checking anyway.
Exploitation
Step 1: request the referenced configuration file
The path taken from the Rakefile was requested. The report does not reproduce the exact request line or the URL, only the outcome: the file was accessible. The expected 403 did not happen.
Step 2: read the credentials
The response body contained AWS keys, split across a production section and a development section:
production:[--CUT--]aws_key: AKIA[--CUT--]ARaws_secret: vx[--CUT--]nIst development:[--CUT--]
The aws_key value begins with the AKIA prefix used for AWS access key IDs, and it sits next to a matching aws_secret. Both are in clear text inside a file served over HTTP. The researcher rated this as another P1.
Root cause
The deployment configuration was reachable over the web, and the report's advice is to keep such files out of the web root and set proper permissions. The file was accessible, so the anticipated 403 never appeared. The Rakefile made the second file easy to find by naming its path directly, but the underlying mistake is the placement and the missing permissions, not the reference itself.
Impact
The exposed values are an AWS access key ID and its secret. The file was accessible and contained the keys in clear text. What those credentials actually allow depends on the IAM policy attached to them, which the report does not describe; the researcher treats the exposure itself as a P1. The report does not state which AWS account or services the keys belonged to, or whether they were used.
Fix
The guidance it gives developers is to keep anything that is not needed out of the application web root, and to set proper permissions on the configuration folder so that its contents cannot be fetched.
Variants to test
- Probe for
Rakefileon Ruby hosts and read it for referenced paths such as configuration files, then request those paths directly. A positive result is a 200 with build or deployment content rather than a 403 or 404. - Probe for the other development files the researcher names:
Makefile,Dockerfileand similar. A positive result is a served development file that should not be public. - Follow every path a discovered build file mentions, including relative ones like
conf/deployment.yml. A positive result is a configuration file containing credentials. - Extend the filename list with other application development artefacts, as the researcher resolved to do. A positive result is any file that should not be publicly readable but returns 200.
What happened, in plain words
A security researcher was looking for files that developers accidentally leave on a public web server. These are files that were only ever meant to sit on a developer's own computer, or on a private build machine, but somehow ended up in the folder the website serves to anyone who visits. In this fourth part of his series, he focused on projects written in Ruby, a popular programming language for building web applications.
He found several Rakefile files on live websites, and one of them was especially interesting. That file is a set of instructions for building and deploying the project, and inside it was a line pointing to another file, conf/deployment.yml. He guessed that second file would be protected, but he tried it anyway. It was not protected. It was served to anyone who asked, and inside it were Amazon Web Services (AWS) credentials: a key and a secret that let software talk to Amazon's cloud services. He rated this as a P1, which in bug bounty language means a serious, high-priority finding.
That is the whole story. No clever attack, no breaking in. Just two files that should have been private, sitting in public view, one of them pointing straight at the other.
Background: what a web root is, and why stray files matter
When you visit a website, the server has a folder on disk that it treats as public. Everything inside that folder can be fetched by anyone with a browser. This folder is often called the web root. Think of it like the front counter of a shop: whatever you put on the counter, a customer can pick up. Anything you want to keep private belongs in the back room, not on the counter.
Developers sometimes build their project in a way that puts extra files on the counter by accident. A build script, a configuration file, a note to themselves. None of these were meant for visitors, but the server does not know that. If the file is in the public folder and nothing blocks it, the server hands it over like any other page.
This series is about exactly those files. The previous part looked at a .sh file, which is a shell script. This part stays in the same territory, application development, but moves to Ruby projects.
What Rake and a Rakefile are
Ruby is a programming language. When a Ruby project needs to be built, tested or deployed, developers often use a tool called Rake. Rake is a build tool: it runs a list of tasks in order, a bit like a recipe with steps. The recipe itself is written in a file called a Rakefile, and that file is written in ordinary Ruby code.
If you have heard of Makefile (used in C and other projects), a Rakefile is the Ruby equivalent. It declares tasks, what each task depends on, and patterns for generating work. It can also mention other files the build needs, such as configuration files. That last point is why it is interesting to a security researcher: a Rakefile can act like a signpost, pointing at files that hold real secrets.
The setup: a simple script and a list of domains
The researcher did not use anything complicated. He wrote a small Python script that runs several checks at the same time (that is what multi-threaded means: several workers doing the same job in parallel instead of one after another). The script took a list of domain names and, for each one, asked the server whether a particular file existed.
This is the same approach he used earlier in the series. There were no accounts to create, no special access, no insider knowledge. The only inputs were the list of domains and the list of filenames to check for.
How he found the Rakefile
Before probing live sites, he looked at which files real Ruby projects tend to contain. He browsed the trending Ruby repositories on GitHub, a website where developers publish their code. Some of those projects included a Rakefile. Seeing that gave him the idea to add Rakefile to the list of filenames his script should look for on live websites.
Running the script against his domain list turned up several Rakefile files. One of them was especially interesting:
require ‘rubygems’require ‘bundler/setup’require ‘rake’require ‘rspec/core’require ‘rspec/core/rake_task’[ — CUT — ]path = “conf/deployment.yml”[ — CUT — ]task :spec => :buildtask :default => :build
Here is what that file is doing, piece by piece:
require ‘rubygems’loads RubyGems, the standard package manager for Ruby. A package manager is like an app store for code libraries: it fetches and installs pieces of software your project needs.require ‘bundler/setup’loads Bundler, a tool that makes sure the exact versions of libraries listed in the project are the ones used.require ‘rake’loads Rake itself, the build tool.require ‘rspec/core’andrequire ‘rspec/core/rake_task’load RSpec, a testing framework, and its Rake integration, so tests can be run as build tasks.[ — CUT — ]marks a place where the researcher removed lines to keep the write-up short. The original file had more content there.path = “conf/deployment.yml”stores a file path in a variable calledpath. This is the signpost: it tells us the project keeps a deployment configuration file atconf/deployment.yml.task :spec => :builddefines a task calledspec(the tests) that depends on a task calledbuild. In other words, build first, then test.task :default => :buildsays that if you run Rake with no task name, it should runbuildby default.
The important line for our purposes is the path one. A deployment configuration file is where settings for putting the application live, and settings files often contain credentials. So the Rakefile itself is only a hint, but the file it points at is where the valuable data would be.
Trying the file it pointed to
The researcher expected that requesting conf/deployment.yml would return a 403 response. HTTP status codes are the server's short answers to a request: 200 means "here is the page", 404 means "not found", and 403 means "forbidden, you are not allowed to see this". Configuration folders are usually locked down, so a 403 was the sensible guess.
But it was worth checking anyway, because guesses are sometimes wrong. He requested the path. The report does not reproduce the exact request or the full URL, only the result: the file was accessible. The expected 403 never came.
What was inside
The response contained AWS credentials, split into a production section and a development section:
production:[--CUT--]aws_key: AKIA[--CUT--]ARaws_secret: vx[--CUT--]nIst development:[--CUT--]
Reading that line by line:
production:starts a section of settings for the live, real-world version of the application.aws_key: AKIA[--CUT--]ARis an AWS access key ID. AWS is Amazon Web Services, a cloud platform where companies rent servers and storage. An access key ID is like a username for a piece of software: it identifies who is making the request. TheAKIAprefix is the standard start for this kind of key. The middle has been cut out to avoid publishing the full value.aws_secret: vx[--CUT--]nIstis the matching secret. Think of the key ID as the username and the secret as the password. Together they let software sign in to AWS and use whatever permissions that account has.development:starts a second section for the development environment, the version used while building and testing.[--CUT--]again marks removed content.
Both values were sitting in clear text, in a file served over ordinary HTTP. Anyone who could reach the host and knew or guessed the path could read them, with no login required. The researcher rated this as another P1.
Why this happened
Two mistakes combined. The deployment configuration was reachable over the web, and the report's advice is to keep such files out of the web root. The web server therefore served them like any other static file, such as an image or a stylesheet. The file was accessible, so the expected 403 never appeared.
The Rakefile made the second file easy to find because it named the path directly. But the real problem is the placement and the missing permissions, not the reference.
What the exposure means
The leaked values are an AWS access key ID and its secret. The file was accessible and contained the keys in clear text. What those credentials actually allow depends on the permissions (the IAM policy) attached to them in AWS. The report does not describe those permissions, which AWS account the keys belonged to, which services they could reach, or whether anyone used them. The researcher treats the exposure itself as a P1.
How to fix it
The report does not say what the site owner changed after being told. The advice it gives to developers is straightforward:
- Keep anything that is not needed out of the application web root. If a file does not need to be downloadable by visitors, it does not belong in the public folder.
- Set proper permissions on the configuration folder so its contents cannot be fetched over the web.
Things to try yourself
If you want to look for the same kind of mistake, here are the patterns the researcher describes, in the same order:
- Check Ruby hosts for a
Rakefile, read it for paths it references (such as configuration files), then request those paths directly. You have a hit when the server returns a 200 with build or deployment content, rather than a 403 or 404. - Check for the other development files the researcher names:
Makefile,Dockerfileand similar. You have a hit when a served development file that should not be public is returned. - Follow every path a discovered build file mentions, including relative ones like
conf/deployment.yml. You have a hit when a configuration file contains credentials. - Keep extending your filename list with other application development artefacts, as the researcher resolved to do. You have a hit when any file that should not be publicly readable returns a 200.
Glossary
- AWS (Amazon Web Services): Amazon's cloud platform, where companies rent servers, storage and other services.
- AWS access key ID: the identifier half of a pair of credentials used by software to sign in to AWS, like a username. Often starts with
AKIA. - AWS secret: the secret half of that pair, like a password. It must never be public.
- Bundler: a Ruby tool that installs and pins the exact library versions a project needs.
- Configuration file: a file holding settings for an application, such as where to connect or which credentials to use.
- Deployment: the process of putting an application live on a server for real users.
- Domain: a website's name, such as example.com.
- 403: an HTTP status code meaning "forbidden", the server refuses to show you the resource.
- 404: an HTTP status code meaning "not found".
- 200: an HTTP status code meaning "OK", the server is returning the resource.
- HTTP status code: a short number a web server returns with every response to say how the request went.
- IAM policy: the set of permissions in AWS that decides what a given credential is allowed to do.
- Makefile: a build recipe file used by the
maketool, common in C and similar projects. - Multi-threaded: running several jobs at the same time in parallel rather than one after another.
- P1: a high-priority severity rating in bug bounty work, meaning a serious issue.
- Python: a popular programming language, often used for small automation scripts.
- Rake: a build tool for Ruby projects, similar to
make. - Rakefile: the file that defines Rake's tasks, written in Ruby syntax.
- Repository: a project's collection of code and files, often hosted on a site like GitHub.
- Rotating keys: replacing exposed credentials with new ones and disabling the old ones.
- RSpec: a testing framework for Ruby.
- Ruby: a programming language, popular for web applications.
- RubyGems: the standard package manager for Ruby libraries.
- Static file: a file served as-is, such as an image or stylesheet, without the server running any code for it.
- Web root: the folder on a web server whose contents are publicly reachable.
- YAML: a human-readable text format often used for configuration files, usually with a
.ymlextension.