ZeroMQ libzmq remote code execution
A malformed network message sent to a ZeroMQ endpoint could trigger a memory-safety flaw in the libzmq library, letting an attacker run arbitrary code on the victim's machine. The reporter disclosed it publicly because the project had no private security process.
- Fixed in 8 months
- Paid in 8 months
- Disclosed after 8 months
Bug report and exploit: https://github.com/zeromq/libzmq/issues/3351 Fix by me: https://github.com/zeromq/libzmq/pull/3353
My motive for full disclosure is as follows:
Is it true that it is not safe to use ZeroMQ over the internet because it will crash?
Earlier versions of the ZeroMQ library (before 2.1) were not very resilient against "fuzzing" attacks. A malformed packet or garbage data could cause an old version of the library to assert and exit. Since the release of 2.1, all reported cases of assertions caused by bad data have been fixed. If your testing uncovers a problem in this area, please file a bug report.
Source: http://zeromq.org/area:faq
The issue reporting page (http://zeromq.org/docs:issue-tracking) instructs to open a Github issue, with no special procedure for security issues, so I went ahead and did just that.
libzmq appears to be widely used and has wrapper implementations for Go, Python, Java, Node.js, etc.
Impact
Running arbitrary code on the victim's system.
Context
ZeroMQ (libzmq) is a messaging library that provides sockets for many messaging patterns over a transport layer. The report concerns the library itself, not a hosted service: the target is the libzmq codebase, and the affected behaviour is how the library handles malformed or unexpected data arriving over a socket. The researcher notes that libzmq is widely used and has wrapper implementations for Go, Python, Java, Node.js and others, so a memory corruption bug in the core library reaches a large number of applications.
The report was filed under the Internet Bug Bounty program on HackerOne, with a high severity and a CVSS score of 8.8, classified as generic memory corruption. It was disclosed on 12 September 2019.
Setup
No accounts, roles or special tooling are described. The researcher worked directly against the libzmq project: the bug report and exploit were published as a GitHub issue, and the fix was submitted as a pull request. The only precondition visible in the report is that the target is the library itself, reachable through whatever transport the application exposes.
Finding it
The researcher's starting point was the project's own public statements about robustness. The ZeroMQ FAQ was quoted as follows:
Is it true that it is not safe to use ZeroMQ over the internet because it will crash?
Earlier versions of the ZeroMQ library (before 2.1) were not very resilient against "fuzzing" attacks. A malformed packet or garbage data could cause an old version of the library to assert and exit. Since the release of 2.1, all reported cases of assertions caused by bad data have been fixed. If your testing uncovers a problem in this area, please file a bug report.
Source: http://zeromq.org/area:faq
That text sets an explicit expectation: since 2.1, malformed packets and garbage data should not be able to crash the library. The researcher quoted that text before filing the issue.
The project's issue reporting page (http://zeromq.org/docs:issue-tracking) instructs users to open a GitHub issue, with no special procedure for security issues. The researcher followed that instruction and filed the issue publicly, which is the reason the full details, including the exploit, are available.
Exploitation
The report does not walk through the exploit step by step. It points to the public issue for the bug report and exploit, and to a pull request for the fix:
Bug report and exploit: https://github.com/zeromq/libzmq/issues/3351
Fix by me: https://github.com/zeromq/libzmq/pull/3353
The issue contains the exploit itself; the report text here does not reproduce the payload, the socket type, the transport or the exact sequence of messages used to trigger the corruption. What the report does state is the outcome: running arbitrary code on the victim's system.
Root cause
The report does not describe the specific defect in the code. The report does not describe the specific defect in the code; the linked issue and pull request hold those details. The exact faulty function, the missing bounds check or the lifetime mistake is not stated here; the linked issue and pull request hold those details.
The existing defence in this case was the project's own assurance that assertion crashes from bad data had been fixed since 2.1.
Impact
As stated in the report, the impact is running arbitrary code on the victim's system. Because libzmq is a library used by many applications and language wrappers, the affected population is any deployment that passes attacker-controlled data into the library. The report does not enumerate which transports, socket types or configurations are exposed, so the conditions under which an attacker can deliver the malformed data are not specified beyond the general premise of untrusted input reaching libzmq.
Fix
The researcher submitted a fix as a pull request to the libzmq repository (https://github.com/zeromq/libzmq/pull/3353).
Variants to test
These follow from the shape of the finding rather than from details in the report:
- Take each documented guarantee in a project's FAQ or security page about malformed input and test it directly with garbage and truncated messages. A positive result is a crash, an assertion, or memory corruption where the documentation says the input is handled safely.
- Exercise every transport and socket type the library supports with malformed frames, since a fix in one path does not imply the others are covered. A positive result is a crash or corruption on a path the project believed was safe.
- Test the language wrappers (Go, Python, Java, Node.js and others named in the report) with the same malformed input, because a bug in the core library surfaces through every binding. A positive result is the same corruption reached through a wrapper.
Hunting notes
This kind of bug hides in libraries that parse untrusted bytes and in the gap between what a project claims about robustness and what its code actually enforces. The signal during recon is a public statement that malformed input is handled safely, especially one that names a version boundary, as the ZeroMQ FAQ does for 2.1. That statement is a testable claim, and testing it is cheap.
A second signal is the absence of a security process: the issue tracking page pointed researchers at a public GitHub issue with no special handling for security reports. That makes disclosure straightforward.
The report states the impact as running arbitrary code on the victim's system, and points to a public issue containing the bug report and exploit. The report was accepted at high severity with a CVSS of 8.8. The report does not record a bounty amount.
What happened, in plain words
ZeroMQ is a piece of software that lets different programs send messages to each other. It comes as a library, which is a bundle of ready-made code that other programs can plug in rather than writing everything from scratch. The library is called libzmq. It is very popular: the report notes that it has wrapper implementations for Go, Python, Java, Node.js and others, meaning people have built versions of it for many programming languages so that applications written in those languages can use it too.
Because so many programs rely on libzmq, a flaw inside it reaches all of them at once. The researcher found such a flaw, classified as generic memory corruption. Memory corruption means the program loses track of what is stored where in its memory, and an attacker can exploit that confusion to make the program do things it was never meant to do. In this case the outcome, as the report states it, is running arbitrary code on the victim's system: the attacker gets their own instructions executed on the victim's machine.
The researcher did not keep this private. The project's own issue reporting page told people to open a GitHub issue, with no special procedure for security problems, so the researcher filed the bug publicly, exploit included. The report was filed under the Internet Bug Bounty program on HackerOne, rated high severity with a CVSS score of 8.8, classified as generic memory corruption, and disclosed on 12 September 2019.
Context
ZeroMQ, and specifically libzmq, is a messaging library. A library is code that other software calls on to do a job, in the same way a household might call a plumber rather than install its own pipes. Here the job is messaging: libzmq provides sockets, which are the software equivalent of a letterbox or a phone line, through which programs exchange messages. It supports many messaging patterns over a transport layer, meaning it can carry those messages over different underlying channels.
The target of this report is not a website or a hosted service. It is the libzmq codebase itself, the source code of the library. The behaviour at issue is how that code handles malformed or unexpected data arriving over a socket. In everyday terms: what happens when someone posts a strange, badly formed letter through the letterbox. A robust system should notice the letter makes no sense and set it aside. A fragile one might trip over it.
The report notes that libzmq is widely used and has wrapper implementations for Go, Python, Java, Node.js and others. A wrapper is a thin layer that lets one language call code written in another, like an adapter plug that lets a foreign appliance fit your wall socket. Because of those wrappers, a memory corruption bug in the core library reaches a large number of applications, not just the ones written in the language libzmq itself is written in.
The report was filed under the Internet Bug Bounty program on HackerOne, with a high severity and a CVSS score of 8.8, classified as generic memory corruption. CVSS is a standard scoring system for the seriousness of a security flaw; 8.8 out of 10 sits in the high range. It was disclosed on 12 September 2019.
Setup
There are no accounts, roles or special tools described in the report. The researcher worked directly against the libzmq project. The bug report and exploit were published as a GitHub issue, and the fix was submitted as a pull request. GitHub is a website where software projects keep their code and track work; an issue is a public discussion thread about a problem, and a pull request is a proposed change to the code that the project can review and merge.
The only precondition visible in the report is that the target is the library itself, reachable through whatever transport the application exposes. A transport is simply the channel the messages travel over. The point is that the researcher did not need any privileged position: the library is the thing under test, and it can be reached through whatever channel an application using it happens to offer.
Finding it
The researcher's starting point was the project's own public statements about how robust the library is. The ZeroMQ FAQ, a page of frequently asked questions, was quoted as follows:
Is it true that it is not safe to use ZeroMQ over the internet because it will crash?
Earlier versions of the ZeroMQ library (before 2.1) were not very resilient against "fuzzing" attacks. A malformed packet or garbage data could cause an old version of the library to assert and exit. Since the release of 2.1, all reported cases of assertions caused by bad data have been fixed. If your testing uncovers a problem in this area, please file a bug report.
Source: http://zeromq.org/area:faq
Line by line, in plain words:
- The first line is the question being answered: is it true that using ZeroMQ over the internet is unsafe because it will crash? This is the worry the FAQ is addressing.
- The second line admits that earlier versions, before release 2.1, were not very resilient against fuzzing attacks. Fuzzing means feeding a program deliberately malformed, random or garbage input to see whether it breaks. A packet is a small chunk of data sent over a network, and garbage data is data that makes no sense to the program receiving it.
- The same line explains what went wrong in those old versions: a malformed packet or garbage data could cause the library to assert and exit. An assertion is a check inside a program that says "this should never happen"; when it fails, the program stops immediately. So the old library would simply shut down when fed nonsense.
- The third line makes a promise: since the release of 2.1, all reported cases of assertions caused by bad data have been fixed. In other words, from version 2.1 onwards, bad data should no longer be able to crash the library this way.
- The last line invites anyone who finds a problem in this area to file a bug report.
That text sets an explicit expectation: since 2.1, malformed packets and garbage data should not be able to crash the library. The researcher quoted that text before filing the issue. The reasoning is simple: a public promise about safety is a testable claim, and testing it costs little.
The project's issue reporting page (http://zeromq.org/docs:issue-tracking) instructs users to open a GitHub issue, with no special procedure for security issues. The researcher followed that instruction and filed the issue publicly, which is the reason the full details, including the exploit, are available. A security issue is a flaw that could be abused by an attacker, and projects often ask for those to be reported privately first so they can fix them before the world knows. Here there was no such private channel, so the report went straight into the open.
Exploitation
The report does not walk through the exploit step by step. It points to the public issue for the bug report and exploit, and to a pull request for the fix:
Bug report and exploit: https://github.com/zeromq/libzmq/issues/3351
Fix by me: https://github.com/zeromq/libzmq/pull/3353
Line by line:
- The first line gives the address of the GitHub issue where the bug report and the exploit live. An exploit is the concrete recipe or code that triggers the flaw.
- The second line gives the address of the pull request the researcher submitted, which contains the fix. "By me" means the researcher wrote the patch themselves.
The issue contains the exploit itself; the report text here does not reproduce the payload, the socket type, the transport or the exact sequence of messages used to trigger the corruption. A payload is the actual data sent to trigger the problem. What the report does state is the outcome: running arbitrary code on the victim's system. Arbitrary code means code of the attacker's choosing, not the program's own.
Root cause
The report does not describe the specific defect in the code. The report does not describe the specific defect in the code; the linked issue and pull request hold those details. The exact faulty function, the missing bounds check or the lifetime mistake is not stated here; the linked issue and pull request hold those details. A bounds check is a test that data fits within the space set aside for it, and a lifetime mistake is getting the timing wrong for when a piece of memory is created and destroyed.
The existing defence in this case was the project's own assurance that assertion crashes from bad data had been fixed since 2.1. In everyday terms, the project had checked that strange letters no longer make the system fall over, but had not checked that they cannot be used to slip instructions inside.
Impact
As stated in the report, the impact is running arbitrary code on the victim's system. Because libzmq is a library used by many applications and language wrappers, the affected population is any deployment that passes attacker-controlled data into the library. The report does not enumerate which transports, socket types or configurations are exposed, so the conditions under which an attacker can deliver the malformed data are not specified beyond the general premise of untrusted input reaching libzmq.
Fix
The researcher submitted a fix as a pull request to the libzmq repository (https://github.com/zeromq/libzmq/pull/3353).
Variants to test
These follow from the shape of the finding rather than from details in the report:
- Take each documented guarantee in a project's FAQ or security page about malformed input and test it directly with garbage and truncated messages. A positive result is a crash, an assertion, or memory corruption where the documentation says the input is handled safely. Truncated means cut short, as if a letter arrived with the last page missing.
- Exercise every transport and socket type the library supports with malformed frames, since a fix in one path does not imply the others are covered. A positive result is a crash or corruption on a path the project believed was safe.
- Test the language wrappers (Go, Python, Java, Node.js and others named in the report) with the same malformed input, because a bug in the core library surfaces through every binding. A binding is the same idea as a wrapper: the layer that connects one language to the library. A positive result is the same corruption reached through a wrapper.
Hunting notes
This kind of bug hides in libraries that parse untrusted bytes and in the gap between what a project claims about robustness and what its code actually enforces. To parse is to read incoming data and work out its structure. The signal during recon is a public statement that malformed input is handled safely, especially one that names a version boundary, as the ZeroMQ FAQ does for 2.1. Recon, short for reconnaissance, is the early stage of looking around a target for clues. That statement is a testable claim, and testing it is cheap.
A second signal is the absence of a security process: the issue tracking page pointed researchers at a public GitHub issue with no special handling for security reports. That makes disclosure straightforward.
The report states the impact as running arbitrary code on the victim's system, and points to a public issue containing the bug report and exploit. The report was accepted at high severity with a CVSS of 8.8. The report does not record a bounty amount.
Glossary
- Assertion: a check inside a program that says a condition should always be true; when it fails, the program stops immediately.
- Binding: a layer that lets code in one programming language call a library written in another.
- Bounds check: a test that data fits within the space set aside for it in memory.
- Bug bounty: a program that rewards people for finding and reporting security flaws.
- Codebase: the source code of a software project.
- CVSS: a standard scoring system for the seriousness of a security flaw, from 0 to 10.
- Exploit: the concrete recipe or code that triggers a security flaw.
- Fuzzing: feeding a program deliberately malformed, random or garbage input to see whether it breaks.
- Garbage data: data that makes no sense to the program receiving it.
- GitHub: a website where software projects keep their code and track work.
- Issue: a public discussion thread on GitHub about a problem in a project.
- Library: a bundle of ready-made code that other programs can plug in rather than writing everything from scratch.
- libzmq: the core ZeroMQ library, the code under test in this report.
- Memory corruption: a flaw where a program loses track of what is stored where in its memory, which an attacker can exploit.
- Packet: a small chunk of data sent over a network.
- Payload: the actual data sent to trigger a problem.
- Pull request: a proposed change to a project's code that the project can review and merge.
- Recon: the early stage of looking around a target for clues.
- Socket: the software equivalent of a letterbox or phone line through which programs exchange messages.
- Transport: the underlying channel that messages travel over.
- Truncated: cut short, with part of the data missing.
- Wrapper: a thin layer that lets one language call code written in another.
- ZeroMQ: a messaging library that provides sockets for many messaging patterns over a transport layer.