Disable clamav via unix socket#17672
Conversation
| if writable?(datastore[CLAMAV_UNIX_SOCKET].to_s) | ||
| print_good('File does exist and is writable!') | ||
|
|
||
| Socket.unix(datastore[CLAMAV_UNIX_SOCKET].to_s) do |sock| |
There was a problem hiding this comment.
Just to confirm - does this approach work against a remote target?
i.e. won't this only shut down a Socket on the current host machine, and not the remote target?
There was a problem hiding this comment.
For reference - here's an example of a module that uses socat that's available on the remote host to interact with the socket on the remote file system:
And here's an example of using python that's on the remote host to interact with the remote socket:
metasploit-framework/modules/exploits/linux/local/cve_2021_38648_omigod.rb
Lines 165 to 166 in db29036
It uploads the following python script:
There was a problem hiding this comment.
Just to confirm - does this approach work against a remote target?
i.e. won't this only shut down a Socket on the current host machine, and not the remote target?
Correct, this is a post module to disable clamav after a linux host has been compromised.
There was a problem hiding this comment.
Thanks for the update!
As Metasploit won't always be running on the same host as the target, the module would have to be updated to also work remotely - like in the module examples above 👍
There was a problem hiding this comment.
To clarify, this module is a post, module meant to be executed through a meterpreter session. The meterpreter session can be on a remote host and this should still execute without issue.
Originally I interpreted "work on remote target" as "will this work against a ip:port combo?". My bad!
There was a problem hiding this comment.
Hey @archcloudlabs, I gave this test. With msfconsole running on one machine, and clamav running on a separate machine and I got the following error:
msf6 post(linux/manage/disable_clamav) > rexploit
[*] Reloading module...
[*] Checking file path /run/clamav/clamd.ctl exists and is writable...
[+] File does exist and is writable!
[-] Post failed: Errno::ENOENT No such file or directory - connect(2) for /run/clamav/clamd.ctl
[-] Call stack:
[-] /Users/jheysel/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/socket.rb:64:in `connect'
[-] /Users/jheysel/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/socket.rb:64:in `connect_internal'
[-] /Users/jheysel/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/socket.rb:137:in `connect'
[-] /Users/jheysel/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/socket.rb:1078:in `unix'
[-] /Users/jheysel/rapid7/metasploit-framework/modules/post/linux/manage/disable_clamav.rb:38:in `run'
[*] Post module execution completed
I think this is the issue that @adfoster-r7 was trying to point out. As it's written, the module only works if msfconsole is running on the same machine you're trying to exploit.
Socket.unix(datastore[CLAMAV_UNIX_SOCKET].to_s) do |sock| interacts with the filesystem that msfconsole is running on and not specifically the filesystem the meterpreter session is running on. In your case, because you're running msfconsole and on the same system as your meterpreter session and clamav, the exploit works. The examples posted above should help resolve this issue.
Please let us know if you'd like any further clarification, we're happy and hear to help!
There was a problem hiding this comment.
Thank you for clarifying, I apologize for misunderstanding originally.
I've gone ahead and copied the F5 example and check if socat is on the target host before executing the SHUTDOWN command.
Let me know if this is sufficient!
|
Updating output below |
Release NotesThis PR includes post module that will disable ClamAV on Linux systems. |
|
Thanks for all the pointers! |
Anytime! Thanks for the contribution 🙇 |
This PR includes an additional metasploit module that will disable ClamAV on Linux systems.
The bug resides in the ClamAV Unix socket permitting any user to submit the "shutdown" command which will disable ClamAV.
This is bug is referenced in an open PR in the ClamAV repo here.
This module differs from clamav_control as it requires a Unix socket to interact with.
Verification
List the steps needed to make sure this thing works
Video
A walk through demonstrating this module can be seen here.