[Twitter Open Source] Releases were & are built/executed/tested/released in the context of insecure/untrusted code
Several Twitter open-source projects resolve build dependencies over HTTP without integrity checks, allowing a man-in-the-middle to replace a downloaded JAR with malicious code. An attacker could then execute arbitrary code during builds or on production servers that use the compromised artifacts.
Originally disclosed on HackerOne
- Triaged in 9 days
- Fixed in 7 months
- Paid in 11 days
- Disclosed after 9 months
Summary:
CWE-829: Inclusion of Functionality from Untrusted Control Sphere CWE-494: Download of Code Without Integrity Check
Twitter maintains several Open Source Projects under the Twitter GitHub organization. These projects contain build files that indicate that some of these projects are resolving dependencies over HTTP instead of HTTPS. This allows these artifacts to be potentially MITMed to maliciously compromise them and infect the build artifacts that are produced. Additionally, if any of these JARs or other dependencies were compromised, any developers or production servers using these could continue to be infected past updating to fix this.
Description:
This attack leverages the build infrastructure loading dependencies over HTTP without any other sort of integrity check to allow them to be maliciously compromised.
This isn't just theoretical
POC code has existed since 2014 to maliciously compromise a JAR file inflight. See:
- https://max.computer/blog/how-to-take-over-the-computer-of-any-java-or-clojure-or-scala-developer/
- https://github.com/mveytsman/dilettante
MITM Attacks Increasingly Common
See:
- https://serverfault.com/a/153065
- https://security.stackexchange.com/a/12050
- Comcast continues to inject its own code into websites you visit (over HTTP)
Source Locations
Insecure Download
Scrooge
Tormentia
Scalding
Diffy
Bijection
Algebird
Hdfs-Du
Iago
Ambrose
- https://github.com/twitter/ambrose/blob/da7bcb932c418c157d9c372a4ca5f1884b874d78/cascading/pom.xml#L14-L19
- https://github.com/twitter/ambrose/blob/da7bcb932c418c157d9c372a4ca5f1884b874d78/scalding/pom.xml#L22-L27
BookKeeper
Elephant-Bird
JOAuth
Ect...
This list is not exaustive, I just wanted to come up with examples so the Twitter security team could get a general sense of what they are looking for.
Here are the GitHub queries I used to find these:
WARNING! If any of these builds are using a shared or reused ~/.gradle, ~/.m2 or whatever SBT uses as an artifact cache between builds and any of these downloads were maliciously compromised, the compromised jar may remain inside of cache directory and continue to be used in future builds.
Fix and Public Disclosure
At a minimum, all of these code locations where artifacts are downloaded from an untrusted source needs to be fixed. Previous releases should be rebuilt with the fix applied. The checksum of the released artifacts and artifacts built in a trusted environment should be made. If the checksums match, you can be certain that they weren't compromised.
If the checksums don't match, indicating a compromised artifact, CVE numbers need to be issued for the potentially malicious artifacts.
The ability to check if checksums match assume that these projects have reproducible builds.
Steps To Reproduce:
- Cone the Impacted Project
- Change this line in Dilettante so it is targeting the repository used in the build. https://github.com/mveytsman/dilettante/blob/master/dilettante.py#L143
- Start Dilettante on your local machine.
- Proxy the HTTP traffic for the build through Dilettante
- Execute the Build's tests.
- You should be greeted with the image of a cat.
Other Places to Look
Given how widely I'm finding this vulnerablity externally to Twitter, I'd advise that the Twitter Security team take some time to also analize their internal infrastructure for similar vulnerabilities.
This responsible disclosure follows Google's 90-day vulnerability disclosure policy (I'm not an employee of Google, I just like their policy).
Impact
By insecurely downloading code over an untrusted connection HTTP and executing the untrusted code inside of these JAR files as part of the unit/integration tests before a release opens these artifacts up to being maliciously compromised.
Remote code execution on a production server. Malicious compromise of build artifacts.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Build configuration files reference dependency repositories using HTTP instead of HTTPS and do not verify checksums, so downloaded artifacts can be tampered with in transit.
Impact
An attacker could achieve remote code execution on production servers and maliciously compromise build artifacts, and compromised JARs may persist in shared caches even after updates.
What the attacker needed
Attacker can intercept network traffic; build uses HTTP dependency resolution; no integrity checks on downloads
The fix
All insecure download locations should be changed to use HTTPS with integrity checks, previous releases should be rebuilt with the fix, and checksums should be compared to detect compromise.
How it was found
- Clone the impacted project.
- Modify the Dilettante tool to target the repository used in the build.
- Start Dilettante on your local machine.
- Proxy the build's HTTP traffic through Dilettante.
- Execute the build's tests.
- Observe the image of a cat, indicating successful compromise.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a project is built, it often downloads other pieces of software (dependencies) from the internet. If those downloads happen over an insecure connection (HTTP), someone on the network can secretly swap the real file for a malicious one. That malicious file then runs as part of the build or on servers, giving the attacker control.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.