Learning Library

← Back to Library

Mongol: MongoDB Heartbleed‑Style Memory Leak

Key Points

  • A new CVE dubbed “Mongol” was publicly disclosed on Christmas, letting unauthenticated attackers leak sensitive server memory from MongoDB instances.
  • The flaw mirrors the 2014 Heartbleed bug in OpenSSL, exploiting an out‑of‑bounds read caused by mismatched compression handling.
  • MongoDB’s use of ZLIB‑compressed BSON messages allows an attacker to claim an artificially large uncompressed size, forcing the server to allocate an oversized buffer.
  • When the real data is decompressed into that buffer, the excess space leaks internal memory back to the attacker as part of the server’s response.
  • This pre‑authentication memory‑leak poses a serious risk for anyone managing MongoDB deployments and underscores the urgency of applying the relevant patches.

Full Transcript

# Mongol: MongoDB Heartbleed‑Style Memory Leak **Source:** [https://www.youtube.com/watch?v=9Wg6tiaar9M](https://www.youtube.com/watch?v=9Wg6tiaar9M) **Duration:** 00:09:43 ## Summary - A new CVE dubbed “Mongol” was publicly disclosed on Christmas, letting unauthenticated attackers leak sensitive server memory from MongoDB instances. - The flaw mirrors the 2014 Heartbleed bug in OpenSSL, exploiting an out‑of‑bounds read caused by mismatched compression handling. - MongoDB’s use of ZLIB‑compressed BSON messages allows an attacker to claim an artificially large uncompressed size, forcing the server to allocate an oversized buffer. - When the real data is decompressed into that buffer, the excess space leaks internal memory back to the attacker as part of the server’s response. - This pre‑authentication memory‑leak poses a serious risk for anyone managing MongoDB deployments and underscores the urgency of applying the relevant patches. ## Sections - [00:00:00](https://www.youtube.com/watch?v=9Wg6tiaar9M&t=0s) **Mongol Bleed Holiday Database Leak** - The speaker explains the newly disclosed, unauthenticated memory‑leak vulnerability in MongoDB (called Mongol or Mongol Bleed), likening it to Heartbleed and detailing how an out‑of‑bounds read in BSON/ZLIB handling can expose sensitive server memory, all revealed on Christmas morning. - [00:03:05](https://www.youtube.com/watch?v=9Wg6tiaar9M&t=185s) **MongoDB Compression Exploit Demo** - The speaker demonstrates exploiting a vulnerable MongoDB Docker image by using a concise Python script that crafts a compressed message with a forged decompressed length, enabling arbitrary data leakage and file writes. - [00:06:24](https://www.youtube.com/watch?v=9Wg6tiaar9M&t=384s) **MongoDB Exposure Risks in Ubisoft Breach** - The speaker explains how insecure MongoDB instances can leak sensitive data such as passwords, using the recent Ubisoft Rainbow Six Siege breach and multiple hacker groups exploiting the vulnerability as examples. - [00:09:33](https://www.youtube.com/watch?v=9Wg6tiaar9M&t=573s) **Approaching One Million Subscribers** - The creator thanks viewers, urges them to subscribe, and shares excitement about being close to a million subs with a goal to reach it by year‑end. ## Full Transcript
0:00Imagine the shock on my face when I 0:02awoke Christmas morning to open gifts 0:04with my children and instead I was 0:06greeted with a CVE that affected 0:08MongoDB. Uh the not not a great time for 0:11anybody who's in the world of database 0:13maintenance right now. Uh so Mongol is 0:15the bug we're talking about today. Uh it 0:16is a vulnerability that allows an 0:18unauthenticated attacker to leak 0:21sensitive server memory out of the 0:23MongoDB server process. It's not a great 0:26place to be if you are in the world of 0:28maintaining database infrastructure. 0:30Also not a great place to be if you 0:32exist on the internet because someone 0:34dropped this proof of concept publicly 0:37on Christmas. If you're this guy, come 0:39on, brother. You couldn't have waited 0:40till the next day over. Whatever. It's 0:41fine. Mongol bleed is an illusion to 0:43heartbleleed, the vulnerability in 0:45OpenSSL from 10 years ago. God, I'm so 0:48old. 2014. uh which basically the same 0:50kind of thing happened to OpenSSL where 0:52because of an outofbounds read error you 0:55were able to leak memory out of OpenSSL 0:58which was able to leak sensitive 1:00cryptographic information about an open 1:02SSH server for example okay so uh Mongol 1:06is basically the exact same thing the 1:08way this works is MongoDB is just like 1:10any other networkfacing Damon right you 1:13talk to it over some kind of binary 1:15format in this version it's called BSON 1:17or I think binary server object notation 1:20and the way that you talk to it. The 1:23messages can be com compressed over 1:25ZLIB, right? It's a compression 1:26algorithm and to talk over ZLIB, you 1:28don't need to be authenticated, right? 1:30You can actually do the authentication 1:32transaction over this Z-Lib compression. 1:35So therefore, vulnerabilities that are 1:36exposed via ZLIB are exposed to people 1:39pre-authentication, right? 1:40Unauthenticated attackers. The way this 1:42works is you send the server a 1:45compressed message, but inside of the 1:47compressed message, you actually control 1:49the field that says, "Oh, by the way, 1:52the uncompressed size of the data after 1:54it's been decompressed is this size, 1:57right? You, the attacker, control that 1:59data." MongoDB then allocates a buffer 2:02based on how big you say your decompress 2:05buffer is. The Z-Lib library is going to 2:08use the actual data and decompress the 2:11data into that buffer, but there's extra 2:13room left over because you said the 2:14decompressed buffer was actually bigger 2:16than it really is. And then MongoDB 2:19treats that entire transaction as valid 2:22and it will send you the response, 2:23right? The reason why people are calling 2:25this Mongol, by the way, is that this is 2:27exactly how heartbleleed worked back in 2:292014. Okay, the classic um XKCD a comic 2:32kind of explains it pretty pretty 2:34simply. Server, are you still there? If 2:35so, reply potato. By the way, potato is 2:37six letters. User Meg wants these 2:39letters. Potato. Are you still there? If 2:42so, reply bird. Four letters. User Meg 2:44wants these four letters. Bird. Hm. Uh, 2:47server, if you're still there. If so, 2:49reply with the word hat. Oh, and by the 2:51way, hat is 500 letters long. User Meg 2:54wants these 500 letters. Hat. And then 2:56it dumps all of the data behind the 2:58variable hat. Right. So, to show you the 3:00vulnerability working, right, we have a 3:02vulnerable version of MongoDB set up. 3:04This came again with the MongoDB pock 3:05that went live on Christmas. Jesus 3:07Christ. Um, is you run docker compose 3:09up. I have docker desktop running. Uh, 3:10and what you can do here is it'll run 3:12the server for you. And now you have a 3:14vulnerable version of it running 3:15locally. Now, if we go into the um, not 3:18hello world. If you go into Mongol, you 3:20do a little Python 3 on the Mongoled 3:23script, it's going to send the payload 3:26to the server and it's going to leak out 3:29arbitrary data up to some fixed amount 3:31and just write that to a file. Like that 3:33is that is the entire exploit. It is 3:34that simple. And before we keep going, 3:35look at that guys. I'm almost at a 3:37million subscribers. If you could smash 3:39that sub button, I really would 3:40appreciate it. Mean the world to me. 3:42Thank you so much. So the magic of the 3:43exploit is literally just in this one 3:45Python function here, send probe. What 3:47this function does is sets up a message 3:49to send to the server, right? And it 3:51does this using zlib compression. And 3:53then within the actual message that's 3:55going to be compressed, you have this op 3:57compressed message, right? It's a 3:58structure that MongoDB reads out to, you 4:01know, um, to read information about what 4:02is being compressed and decompressed. 4:04And so you have the original op code, 4:06the messages being sent to the server. 4:08But here is where all the evil happens, 4:11right? You have buffer size. This is the 4:14size that the server is being told that 4:17the decompressed message length actually 4:19is even though it depends on just what 4:21the data actually naturally decompresses 4:23to. Right? So because of this you can 4:26say in this message that the size of the 4:29data is some astronomically large buffer 4:32and MongoDB will allocate that room for 4:34you decompress your message into the 4:36buffer and then send you the totality of 4:38it back. So what's happening here is we 4:40start with this number 20 and we tell 4:43the server that we're actually going to 4:45send it 20 + 500 bytes, right? We're 4:48going to do that over and over and over 4:49again up until the number 8192. Now, as 4:52far as I understand it, because of the 4:53way that the um underlying gibb c heap 4:56works, basically by changing the size, 4:59you're telling MongoDB that your buffer 5:01decompresses into, you're telling it to 5:03use a different, it's called a bin, like 5:06a basically the gibbc heap is allocated 5:08into these things called bins. Bins are 5:10basically a function of how big the 5:11allocation is. And so if you're trying 5:13to leak memory out of the gibbc heap, 5:17you need to change the size of the field 5:19that you're going to allocate, which 5:21therefore changes what bin you are 5:23leaking from. Right? So if like a 5:25sensitive password is allocated in a 5:27field that is 6,000 bytes long, you want 5:29to allocate a chunk that has that size. 5:31So you could potentially allocate that 5:33chunk in it. Now why this may seem so 5:35like benign is that we are literally 5:37just being a we literally just being 5:39sent uninitialized memory from the 5:41server. But the problem is like it's not 5:44within the threat model of MongoDB for 5:46you to be able to read unitionalized 5:48memory, right? So like if someone does 5:50like a database query, right, where they 5:52like they select the password from the 5:54user, obviously it's hashed, but my my 5:55example is that the metadata of that 5:58query from not just you, but other users 6:01or other clients connected to the server 6:03are being exposed to you by giving you 6:06access to that previously used now 6:09uninitialized memory. Because by default 6:11the gibb c he via a malo call or 6:13otherwise a lot of other calls don't 6:15clear the data out. So if you just do 6:16malo and then binary send to send it 6:19over the wire you're going to get that 6:20data without any sanitization in it. 6:22It's it's crazy. Now obviously the data 6:24that I'm showing you here is not super 6:27interesting because I'm not hosting a 6:29real instance of MongoDB that's doing 6:31real transactions with real user data. 6:33If this were an actively like like a 6:36high traffic instance of MongoDB, this 6:38would be littered with user information 6:41like passwords, maybe keys for various 6:44things like things that like the average 6:46person should not see that are just the 6:48artifact of previous transactions. Like 6:50obviously a real password shouldn't be 6:52there. But you see my point, right? Like 6:53just things that are sensitive that are 6:54not meant for other people could be 6:56disclosed through this vulnerability. 6:58And as a result, hackers take no time to 7:02take advantage of a good vulnerability. 7:04It seems like uh Ubisoft claims that 7:05Rainbow Six Siege servers have been 7:07breached as well as uh Rain Yeah, 7:10Rainbow 6 is also super So there 7:12are a couple games that have been 7:14potentially popped. I don't know. 7:15There's no claim here that it is because 7:17of the breaking news. Um so VX 7:19underground, who is a well-known hacker 7:21malware person on Twitter, um basically 7:24he kind of did a little rundown of 7:25what's actually happening with regard to 7:26Rainbow Six Siege. So there have been I 7:28guess multiple instances of breaches of 7:31R rain Rainbow Six Siege that involved 7:32different groups of people. There is a 7:35second group of people that is unrelated 7:38to this first breach that did exploit 7:40the MongoDB instance from Ubisoft using 7:43Mongol which allowed them to pivot to an 7:46internal Git repo and then they 7:48exfiltrated a large portion of Ubisoft's 7:50internal source code which is probably 7:52leading to the gigantic hacks that are 7:54happening right now. Again, I'm just 7:56scrolling Twitter as I'm making this 7:57video and there are like people who are 7:59saying that things they've bought in 8:01game is are getting stolen uh gifted 8:04roughly 339 what is that billion 8:06trillion dollars of in-game currency to 8:09players. So there's a lot of bad stuff 8:11going on and yeah we are talking about 8:12like four groups of different people 8:15supposedly uh hacking into Ubisoft 8:18servers. So if you're Ubisoft not having 8:20a great time. I do want to highlight, by 8:21the way, that MongoDB's Atlas database, 8:23which is their self-hosted version of 8:25MongoDB that people can rent out. This 8:27was patched well before anything went 8:29public. So, if you use Atlas, don't 8:31worry about this. The only instances 8:33that are still vulnerable are instances 8:35that have not been updated that are, you 8:37know, still exposed to the vulnerability 8:38post the release of the PC on Christmas. 8:41So, TLDDR, right? If you use any of 8:43these versions of MongoDB, these 8:45versions are affected. And the way that 8:47you fix it is you upgrade to the newest 8:48version. just go take care of that right 8:50now. I don't think there's any huge 8:51interop like backwards compatibility 8:53issues. So, it should be as simple as 8:54just run a little update and and you're 8:56good to go. Uh, and if you're not going 8:57to update, you're you're going to be 8:59Ubisoft and you're going to have a bad 9:00time. And the question on your mind, I'm 9:01sure, would Rust have fixed this? I 9:03mean, the answer technically is yes, 9:04right? One of the major features of Rust 9:06is that if you do a runtime out of 9:07bounds read of a buffer, it'll actually 9:09kill the process. It'll panic. Now, 9:11obviously, in a high performance server 9:13environment, you don't want your servers 9:14to die. Obviously with Rust, you're just 9:16choosing that you want to kill the 9:17server instead of leaking the 9:19information, right? It's kind of a 9:20choice of which one is more important to 9:22you as a language. And obviously, this 9:24one being written entirely uh pretty 9:26much in in C++. It just reminds you that 9:28memory safety issues like this are 9:30potentially an issue. Anyway, guys, 9:31that's it for now. Thanks for watching. 9:32I appreciate it. If you like this video, 9:33hit that sub button. I got I'm very 9:35close to a million subs. I can't believe 9:36I'm here. It's actually bonkers. It'd be 9:38cool if I got to a million by the end of 9:39the year. You can make it happen. See 9:40you in the next one. Take care.