-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The latest Metasploit version seems to have some sort of memory leak? #19098
Comments
I have also been facing this issue. The targeted OS was ubuntu 22.04, sometimes the module works fine in the vm. Most of the time the exploit just get stuck, the fans ramp up and i eventually get the Anyone able to get around this issue ? |
I had the same issue in two different environments. Affected environment: Also strange, but running msfconsole without sudo helped me, there was no memory leak in that case. |
I've been unable to replicate; Are folk running with or without a database? Exact replication steps would be appreciated, or if anyone's able to track down the commit that has caused the issue that would also be helpful |
It's the same regardless of whether or not I'm running it with a database. As for replication steps, here's what I did:
It's weird, I can't seem to replicate this issue when I use a fresh Kali VM and fully updating it. But I can easily replicate it with my slightly modified Kali VM. Not sure if it's my tmux config, xfce4-terminal, docker, or something else. Here are my modifications to my Kali VM, in case anyone has the time to check. I'll try testing more and see if I can find out the root cause. |
Having this issue recently after upgrading to version Conditions when this issue arises:
Testing: TryHackMe Room Blue |
@ctf-box:/tmp$ msfconsole -v I started noticing this issue for the past week. The problem somewhat relates to interacting with sessions, channels and background activities. I was unable to find a way to replicate it reliably, but I noticed:
I had a theory that this is somehow related to closed/dead sessions not being sanitized properly. With each meterpreter session, you get a thread, and if you have multiple sessions + multiple closed/dead sessions, the threads stack up. They are cached somewhere in ~/.msf4 because msfconsole loads a good chunk of memory on startup.
Edit: Use the workaround here: #19098 (comment) |
I was able to replicate the issue with a local machine. |
I can confirm that 6.4.0 works fine, 6.4.1 has the issue. As you can see, in my env, running msfconsole as user takes 13 sec, running with sudo or sudo -i takes 120 - 150 sec.
|
To reproduce, have Windows 10 VM which executes msfvenom windows/x64/meterpreter/reverse_tcp payloads. |
Tested with v6.4.5-dev-211de574aa, and it works without issues ... |
My local machine is Ubuntu 22.04 and metasploit-framework version is 6.4.4+20240417170723~1rapid7-1. |
Tried with v6.4.5-dev, that's my case. I also noticed, that sometimes on exit command, there are two different responses (maybe some potential hint), also it seems that at some point it start allocating huge amount of memory, on exit command. |
I seem to have encountered this issue on 6.4.3-dev shipped as latest on Kali. The mentioned idea about VPN playing a part might be true as it is also a the case for me. I do use the database as well. |
Something I noticed today is that my history file is 18MB, and this install is basically from yesterday. There's 1.2M lines that's repeating the same x lines. Could possibly be related? Removed that file and it started again with only 300 MB. After this I connected to a machine through SSH. Upgraded the session. And once I interacted with it via |
I've collected some data on memory usage using top. After clearing ~/.msf4, I was repeating the following: create listener, execute meterpreter staged payload on Win10, once connected, close session using exit. It seems it starts acting weird after session 8, the 9th session is still fine (but loads longer), afterwards the memory allocation starts escalating. The process seemed to be allocating 0-48 virtual memory for sessions 1 to 9. The 10th session allocated 300MB, 11th - 600, 12th - 1670, 13th - 3957. I was looking into VIRT/RES memory usage at different states: Before Creating Listener (BL), Listener Created (LC), Victim VM Connected (C'ed), After exiting meterpreter (AE) and Message from meterpreter when says session Died or User Exit, or both at the same time. If anyone interested, here's a csv. |
@adfoster-r7 I cloned the repo and checked out that branch. But I seem to be receiving the same problem. Once I connect to the upgraded session memory instantly spikes to ~2.4GB. Does not happen with a clean database, so could be that my current database is a little "corrupt"? |
@donran Does 6.4.0 work for you, and 6.4.4 breaks for you? If so, you could run a git bisect to find out what's gone wrong 🕵️ It's a tool for running through a a series of commits for identifying when an issue was first introduced Start the git bisect:
Check out the version that's working for you, and mark it as 'good':
Then check out the latest code and mark it as bad:
The bisect will then put you somewhere in the middle between those two releases, and you can incrementally work out which commit introduced the problem via a divide-and-conquer approach, i.e.
After the 7 or so steps of saying
If something goes wrong, you run Hopefully that sheds some light on the problem |
And now I cannot reproduce the issue anymore in my env since I used the v6.4.5-dev-211de574aa version. |
Something I did note when doing this is that I had to run |
@adfoster-r7 I think I might've been tricked due to the thing I mentioned about having to run msfconsole twice because it always allocated 2.4GB on the first run. I noticed this while doing the bisects. Tried it again now on that commit, and as expected, the second time it does not allocate that much memory. |
I have done some additional experiments, and I think it is actually the problem with history manager.
I was wrong regarding commands stored in the memory. It was meterpreter_history file. So it seems meterpreter_history and history files have direct impact on the issue.
Latest workaround: #19098 (comment) |
This will be fixed in Metasploit version 6.4.5 (PR) The workaround for now until you can update to Metasploit 6.4.5 is to:
diff --git a/lib/rex/ui/text/shell/history_manager.rb b/lib/rex/ui/text/shell/history_manager.rb
index 3d53a8c3c0..ec23aa4ac1 100644
--- a/lib/rex/ui/text/shell/history_manager.rb
+++ b/lib/rex/ui/text/shell/history_manager.rb
@@ -27,6 +27,7 @@ class HistoryManager
# @param [Proc] block
# @return [nil]
def with_context(history_file: nil, name: nil, &block)
+ block.call; return nil
push_context(history_file: history_file, name: name)
begin |
@donran Does that workaround work for yourself? |
@adfoster-r7 It works for me. Tested on version 6.4.3-dev |
@adfoster-r7 - this fix worked for me as well. Running deb from metasploit.com repo: 6.4.4+20240417170723~1rapid7-1 amd64 Thank you so much! |
The fix worked! @adfoster-r7 Tested with
|
I can also confirm that the workaround works. Thank you very much @adfoster-r7 😄 |
Metasploit-framework 6.4.5 is released to Kali, as well the official installers - so updating to the latest version should work as a solution. Will close this off 👍 |
Workaround available here: #19098 (comment)
Summary
I upgraded to the latest version of metasploit (6.4.2 and 6.4.3) and in the past few days, trying to run exploit modules (almost any type of module) fills up the ram of my Kali Linux VM and crashes with the error:
The simplest example I can recreate this with is TryHackMe's room called Blue:
I can confirm that this doesn't happen with an older version of Metasploit (6.3.43), with the same Kali Linux VM config:
The text was updated successfully, but these errors were encountered: