Secure Your Jenkins Instance Or Hackers Will Force You To! (Snapchat’s $5,000 Vulnerability)
A Jenkins instance was exposed with login via a Gmail account, and after authentication the attacker could access the Script Console to read files and execute commands. This allowed remote code execution on the server.
Published on nahamsec.com
Vulnerability Write-Ups
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 a write-up of a Snapchat bug bounty finding, published on 22 August 2017 by Ben Sadeghipour (@nahamsec), with a $5,000 reward. The target was an exposed Jenkins instance on a Snapchat corporate domain. Jenkins is a build and deployment server: it holds build history, credentials, API keys, source code and, through its Script Console, the ability to run arbitrary Groovy on the server. The finding was reached by applying the recon methodology from the author's talk "Doing Recon Like a Boss" and his HackerOne blog post on recon and content discovery to public programmes, in this case Slack and Snapchat.
The image sits at the start of the article, just after the reference to the talk.
Setup
The author performed the recon exactly as described in the talk. The tools involved were subdomain brute forcing, Censys, and a small script for generating hostname permutations.
Finding it
Step 1: subdomain brute forcing
Brute forcing subdomains is described as a typical starting point for a large programme, but the subdomains found were not interesting, so the author moved on.
Step 2: Amazon Web Services
S3 buckets were considered and skipped: Snapchat is heavily dependent on Google and states in its HackerOne programme that it hosts its app on Google, so the author did not spend time on S3.
Step 3: disclosed reports on HackerOne
The author likes to look for known or disclosed vulnerabilities during recon. A glance at Snapchat's Hacktivity page produced the following hosts:
- render.bitstrips.com
- blog.snapchat.com
- accounts.snapchat.com
- fastly.sc-cdn.net
- sc-corp.net (credited to Shubs)
sc-cdn.net and sc-corp.net caught his attention. A subdomain brute force made little sense on corporate and CDN domains, where the interesting subdomains are likely to follow a unique pattern, so the question became how to find them.
Step 4: Censys and Shodan
Certificate data on Censys was the next step. The usual query looks like this:
443.https.tls.certificate.parsed.extensions.subject_alt_name.dns_names:domain.com
This surfaced subdomains that brute forcing would not have found. Among the results was a host of the form REDACTED-jenkins-Environment.sc-corp.net, which redirected the user to a login page. The author reasoned that if an environment exists, others probably do, and wrote a script to try permutations of REDACTED-jenkins-$env.sc-corp.net against this list:
dev, alpha, stage, prod, beta, local, test
Several of those returned HTTP 302, which suggested they were behind a login.
Step 5: trying to get in
The obvious first move was to try the prod instance and log in, but that did not work (the author credits preben_ve and HackerOne report 231460). Moving down the list, one of the other instances allowed login to Jenkins using a gmail account. Once authenticated, the author expected minimal permissions that would not allow much, let alone access to the Script Console. Instead he ran a script that read a file on the server, stopped testing immediately and reported it to Snapchat. There was no need to run more scripts to demonstrate impact, since reading any file on the system was already enough. To demonstrate RCE he included the command execution script and asked the team to try it at their own risk.
Exploitation
The exploitation section of the article is a general discussion of Jenkins attack scenarios, run against the author's own Jenkins instance. The screenshots in this part are explicitly not related to the Snapchat report.
Step 6: known vulnerabilities
Two examples are highlighted:
- CVE-2016-9299, Jenkins Java deserialisation remote code execution.
- CVE-2015-8103, Jenkins CLI RMI Java deserialisation, with a public exploit.
Access to build information
Access to builds on Jenkins can give access to credentials, API keys and secrets, and obviously the source code.
Plugins
Jenkins allows plugins such as GitHub OAuth, which lets users log in with their organisation account and can expose the GitHub token. That token can then be used against the GitHub API, for example:
https://api.github.com/orgs/ORG_NAME/repos?access_token=XXXXX
Groovy scripts
The Script Console allows reading files with one line of code. It also allows command execution on the server:
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = 'ls /etc/'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
This builds two string buffers, starts ls /etc/ as a process, attaches the buffers to its output and error streams, waits up to one second for it to finish or kills it, and prints both streams. The same pattern with any other command gives arbitrary command execution on the Jenkins host.
Root cause
An internal Jenkins environment was reachable from the internet on a corporate domain and accepted authentication through a gmail account, and the authenticated user had enough permission to use the Script Console. The report does not describe the permission configuration or the authentication realm in more detail. The hostname was found through the Censys certificate search, which surfaced subdomains brute forcing would not have found.
Impact
With Script Console access, an attacker can read any file on the server and execute commands on it. Build information can expose credentials, API keys, secrets and source code, and an OAuth plugin can expose a GitHub token usable against the GitHub API. Jenkins is typically used for deployment, so a compromised server most likely has access to production or internal servers; private keys and host entries on it are useful for pivoting. The author notes that going further than the initial proof is against most programme rules and is not needed in a bug bounty. The report does not state which files were read or what the Snapchat instance contained.
Fix
Snapchat removed the instance immediately and paid the bounty shortly afterwards. The article's takeaways for other owners and testers:
- Jenkins has granular user permissions, so being authenticated does not guarantee remote command execution.
- Authentication through GitHub or Google OAuth should not discourage testing.
- Limited access (no script console, no build info) may still expose the user list under "People", which could allow credential brute forcing, though the author would not go that far.
- Do not spam programmes with "publicly accessible Jenkins" reports unless one of the exploitation paths above is actually possible.
Variants to test
- Certificate transparency and Censys searches for Jenkins hostnames on corporate domains. A positive result is a hostname pattern such as
REDACTED-jenkins-$env.sc-corp.netthat returns 302, hinting at a login. - Permutation scripts over environment names (dev, alpha, stage, prod, beta, local, test). A positive result is several hosts returning 302, one of which accepts login.
- Login through a gmail account on an exposed Jenkins. A positive result is a session that reaches the Script Console or build pages.
- Checking the "People" page when the console is not available. A positive result is a list of usernames that can be tested against the login form.
- Reviewing installed plugins such as GitHub OAuth for exposed tokens. A positive result is a token that returns data from the GitHub API.
- Checking build history for credentials, API keys and source code. A positive result is any secret or repository content visible to the authenticated user.
What happened, in plain words
In 2017, a security researcher named Ben Sadeghipour found a Snapchat server that was supposed to be private but could be reached from the public internet. The server was running Jenkins, a tool that software teams use to build and deploy their apps automatically. Because the server was exposed and the researcher could log in with a Gmail account, he was able to read a file on it and included a command execution script for the team to try. Snapchat fixed the problem quickly and paid him $5,000. This article retells his story in simple terms, explaining every technical idea along the way.
The image appears at the start of the original article, right after the author mentions his talk "Doing Recon Like a Boss".
Background: what is Jenkins and why does it matter?
Jenkins is a build and deployment server. Imagine a factory assembly line for software: developers write code, and Jenkins automatically compiles it, runs tests, and pushes it to production servers. To do that, Jenkins stores a lot of sensitive information: build history, passwords, API keys, source code, and sometimes private keys for servers. It also has a feature called the Script Console that lets administrators run code on the server itself. If an attacker can reach that console, they can run any command on the machine.
The researcher had previously given a talk and written a blog post about a method for finding such servers: looking at public information to discover hidden parts of a company's infrastructure. He decided to test that method on public bug bounty programmes, including Snapchat's on HackerOne. A bug bounty programme is a deal where a company pays people for reporting security problems responsibly.
Step 1: Brute forcing for subdomains
A subdomain is a prefix added to a main domain name. For example, mail.example.com is a subdomain of example.com. Companies often have many subdomains for different services: blog, shop, api, and so on. Some of these may be forgotten or less protected.
Brute forcing means trying a long list of common names to see which ones exist. The researcher started by guessing subdomains of Snapchat's domains, but the ones he found were not interesting. So he moved on.
Step 2: Amazon Web Services
Many companies store files in Amazon S3 buckets, which are cloud storage containers. If a bucket is misconfigured, anyone can read or write files. The researcher considered checking for S3 buckets, but he knew Snapchat relies heavily on Google for hosting, as stated in their bug bounty programme description. So he skipped S3 to save time.
Step 3: Snapchat's disclosed reports on HackerOne
HackerOne is a platform where companies run bug bounty programmes. It has a public page called Hacktivity that lists reports that have been disclosed (made public) by the company. The researcher looked at Snapchat's Hacktivity page and found these hostnames:
- render.bitstrips.com
- blog.snapchat.com
- accounts.snapchat.com
- fastly.sc-cdn.net
- sc-corp.net (thanks to Shubs)
Two of these caught his attention: sc-cdn.net and sc-corp.net. The first looks like a content delivery network (CDN) domain, used to serve files quickly to users. The second looks like a corporate domain, used for internal services. He thought about brute forcing subdomains of these, but realised that corporate and CDN domains often use unique naming patterns, so a simple wordlist would not work. He needed another way to find them.
Step 4: Censys and Shodan
Censys and Shodan are search engines for internet-connected devices. They scan the whole internet and index information about servers, such as the certificates they use for HTTPS. HTTPS is the secure version of HTTP, the protocol browsers use to load websites. When a website uses HTTPS, it presents a certificate that proves its identity. That certificate often lists the domain names it is valid for, in a field called Subject Alternative Name (SAN).
The researcher used Censys to search for certificates that include a given domain. His usual query looked like this:
443.https.tls.certificate.parsed.extensions.subject_alt_name.dns_names:domain.com
This query means: look at certificates seen on port 443 (the standard HTTPS port), parse them, and find any whose SAN field contains domain.com. It returned subdomains that brute forcing would have missed. Among the results was a hostname of the form REDACTED-jenkins-Environment.sc-corp.net. The word "jenkins" in the name suggested a Jenkins server, and "Environment" suggested a particular deployment environment (like development, staging, or production). When he visited it, he was redirected to a login page.
He reasoned that if one environment exists, others probably do. So he wrote a small script to try different environment names in place of "Environment". The list of names he tried was:
dev, alpha, stage, prod, beta, local, test
Several of these returned HTTP status code 302. HTTP status codes are three-digit numbers that servers send to browsers to indicate what happened. A 302 means "redirect": the server is telling the browser to go to a different URL, often a login page. So a 302 suggested that those hosts existed and were protected by a login.
Step 5: Trying to get in
The obvious next step was to try the production instance (the one that serves real users) and attempt to log in. But that did not work; the author credits preben_ve and HackerOne report 231460 for that. So he moved down the list and tried the other instances. One of them allowed him to log in to Jenkins using a Gmail account. That means the Jenkins server accepted a Gmail account for authentication.
Once logged in, he expected to have very limited permissions, perhaps not even access to the Script Console. But he was able to run a script that read a file on the server. At that point, he stopped testing immediately and reported the issue to Snapchat. There was no need to run more scripts to prove the impact, because reading any file on the system is already a serious breach. To demonstrate that remote code execution (RCE) was possible, he included a script that executes commands and asked the Snapchat team to try it at their own risk. RCE means an attacker can run their own commands on the server, which is the most severe kind of vulnerability.
Step 6: Exploiting Jenkins
The rest of the article is a general discussion of Jenkins attack scenarios, demonstrated on the author's own Jenkins instance. The screenshots in this part are not related to the Snapchat report.
Example 1: Known vulnerabilities
Jenkins, like any software, has had security bugs. Two examples are:
- CVE-2016-9299: a Java deserialisation vulnerability that allows remote code execution. Deserialisation is the process of turning stored data back into objects; if an attacker can control that data, they can make the server run their code.
- CVE-2015-8103: a similar flaw in the Jenkins command-line interface (CLI) that uses Java RMI (Remote Method Invocation). A public exploit exists.
These are just examples of known Jenkins vulnerabilities.
Example 2: Access to build information
If you can log in to Jenkins, you might see build history. Builds often contain credentials, API keys, secrets, and source code. API keys are like passwords that allow programs to talk to each other. Secrets are any sensitive values. Source code is the human-written instructions for the software. So access to builds can leak a lot.
Example 3: Plugins
Jenkins supports plugins that add features. One is the GitHub OAuth plugin, which lets users log in with their GitHub account. OAuth is a way to grant access without sharing a password. If misconfigured, this plugin can expose a GitHub token. A token is a string that acts like a temporary password for an API. With that token, an attacker can access the GitHub API, which is a set of URLs that let programs interact with GitHub. For example, this URL lists repositories in an organisation:
https://api.github.com/orgs/ORG_NAME/repos?access_token=XXXXX
Here, ORG_NAME is the organisation name and XXXXX is the token. If the token is valid, the API returns data.
Example 4: Groovy scripts
The Script Console in Jenkins allows running Groovy code. Groovy is a programming language that runs on the Java platform. With one line of code, you can read a file. You can also execute a command on the server with this script:
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = 'ls /etc/'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
Let's break it down line by line:
def sout = new StringBuilder(), serr = new StringBuilder(): creates two empty text buffers, one for standard output and one for standard error. Think of them as two buckets to catch what the command prints.def proc = 'ls /etc/'.execute(): starts a new process running the commandls /etc/.lslists files in a directory, and/etc/is a standard directory on Linux systems that contains configuration files. So this lists the contents of/etc/.proc.consumeProcessOutput(sout, serr): connects the process's output and error streams to the two buffers, so anything the command prints goes into them.proc.waitForOrKill(1000): waits up to 1000 milliseconds (one second) for the command to finish; if it takes longer, it kills it.println "out> $sout err> $serr": prints the contents of both buffers, prefixed without>anderr>.
By replacing ls /etc/ with any other command, an attacker can run arbitrary commands on the Jenkins server.
Root cause
An internal Jenkins environment was reachable from the internet on a corporate domain and accepted logins through a Gmail account. The authenticated user had enough permission to use the Script Console. The report does not describe the permission configuration or the authentication realm in more detail. The hostname was found through the Censys certificate search, which surfaced subdomains brute forcing would not have found.
Impact
With Script Console access, an attacker can read any file on the server and execute commands on it. Build information can expose credentials, API keys, secrets, and source code. An OAuth plugin can expose a GitHub token usable against the GitHub API. Jenkins is typically used for deployment, so a compromised server most likely has access to production or internal servers; private keys and host entries on it are useful for pivoting (moving deeper into the network). The author notes that going further than the initial proof is against most programme rules and is not needed in a bug bounty. The report does not state which files were read or what the Snapchat instance contained.
Fix
Snapchat removed the instance immediately and paid the bounty shortly afterwards. The article's takeaways for other owners and testers:
- Jenkins has granular user permissions, so being authenticated does not guarantee remote command execution.
- Authentication through GitHub or Google OAuth should not discourage testing.
- Limited access (no script console, no build info) may still expose the user list under "People", which could allow credential brute forcing, though the author would not go that far.
- Do not spam programmes with "publicly accessible Jenkins" reports unless one of the exploitation paths above is actually possible.
Variants to test
- Certificate transparency and Censys searches for Jenkins hostnames on corporate domains. A positive result is a hostname pattern such as
REDACTED-jenkins-$env.sc-corp.netthat returns 302, hinting at a login. - Permutation scripts over environment names (dev, alpha, stage, prod, beta, local, test). A positive result is several hosts returning 302, one of which accepts login.
- Login through a Gmail account on an exposed Jenkins. A positive result is a session that reaches the Script Console or build pages.
- Checking the "People" page when the console is not available. A positive result is a list of usernames that can be tested against the login form.
- Reviewing installed plugins such as GitHub OAuth for exposed tokens. A positive result is a token that returns data from the GitHub API.
- Checking build history for credentials, API keys, and source code. A positive result is any secret or repository content visible to the authenticated user.
Glossary
- API: Application Programming Interface; a set of rules and URLs that let one program talk to another.
- API key: A secret string that identifies a program to an API, like a password for software.
- Brute forcing: Trying many possibilities (like common names) until you find one that works.
- Build: The process of turning source code into a runnable application, often automated by Jenkins.
- CDN: Content Delivery Network; a system of servers that deliver web content quickly to users around the world.
- Censys: A search engine that indexes devices and certificates on the public internet.
- Certificate: A digital document that proves a website's identity and enables HTTPS.
- CVE: Common Vulnerabilities and Exposures; a unique identifier for a publicly known security flaw.
- Deserialisation: The process of converting stored data back into objects in memory; if attacker-controlled, it can lead to code execution.
- Environment: A separate deployment of an application, such as development, staging, or production.
- Groovy: A programming language that runs on the Java platform, used in Jenkins scripts.
- HackerOne: A platform where companies run bug bounty programmes and receive vulnerability reports.
- Hacktivity: HackerOne's public page listing disclosed reports.
- HTTP status code: A three-digit number a server sends to indicate the result of a request (e.g. 302 for redirect).
- HTTPS: The secure version of HTTP, using encryption.
- Jenkins: An automation server for building and deploying software.
- OAuth: An open standard for access delegation, commonly used to log in with a third-party account.
- Permutation: A variation of a name, such as changing the environment part of a hostname.
- Plugin: An add-on that extends Jenkins' functionality.
- Port 443: The standard network port for HTTPS traffic.
- RCE: Remote Code Execution; a vulnerability that lets an attacker run commands on a remote server.
- Redirect: An HTTP response that tells the browser to go to a different URL.
- RMI: Remote Method Invocation; a Java technology for calling methods on remote objects.
- S3 bucket: A cloud storage container in Amazon Web Services.
- SAN: Subject Alternative Name; a field in a certificate that lists the domain names it is valid for.
- Script Console: A Jenkins feature that allows running Groovy scripts on the server.
- Secret: Any sensitive value, such as a password or key.
- Shodan: A search engine for internet-connected devices.
- Subdomain: A prefix added to a domain name, like
bloginblog.example.com. - Token: A string that acts like a temporary password for an API or session.
- 302: HTTP status code meaning "Found" or "Redirect".