-
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
smb_version module should support RPORT
#19072
Comments
Interesting! We coincidentally needed something similar for our acceptance testing, i.e. running test targets in docker on arbitrary ports. So this is also useful from just a generic engineering perspective. I guess the problem is for a chunk of our SMB modules, what would the user expect to have happen if you supply RPORT - should it skip scanning 139 and 445, and scan only the user's RPORT? 🤔 Would need a few more brain cycles to work out the best backwards-compatible approach here |
We can do a non-breaking fix where RPORT would add to the array and change it to a This way we will test 445, 139 by default, and the user's non-default port if one is provided |
@nrathaus I like that approach for the flexibility, but I'm not sure what exact code you would want. I think you can add a commit to the PR though! |
@jeffmcjunkin done - #19076 |
So I like the idea of making the ports configurable, it makes a lot of sense. My concern is that what is currently defaulting to 139 as well as 445 should both be configurable. Since the negotiation to the service on 139 is different than what is used to 445 we should test to ensure that negotiating is automatic. If it's not automatic, we'll likely need different data store options (RPORT_SMB and RPORT_NETBIOS probably?) for each so the framework can be told what negotiating mechanism to use. This should ensure that it works in the scenario where the Metasploit user is forwarding and connecting to 445/tcp on whatever proxy/pivot host they're using to 139/tcp on the Windows target and vice versa. |
I see that there is some references to Which is auto-true set on port 445:
Which means that if you put a custom port, this smb_direct wouldn't be enabled, causing a potential cascade of an issue, especially it used in the So I think you are correct, fixing that |
FWIW with Impacket I PR'd a separate argument for the protocol for that scenario, @smcintyre-r7 : fortra/impacket#1730 |
The problem with this approach on Metasploit, is that there are many cases that need to be fixed where |
So after looking into this a bit more, I think we can do it in a way that's backwards compatible and wouldn't require too many changes. Right now, If the With that in place, it should be relatively easy to update if datastore['RPORT'].present? && datastore['RPORT'] != 0
smb_services = [
{ port: datastore['RPORT'], direct: datastore['SMBDirect'] }
]
else
smb_services = [
{ port: 445, direct: true },
{ port: 139, direct: false }
]
end With that in place we could pass it down to the updated |
@smcintyre-r7 I made a bit simpler modification with two additional options for users, Let me know what you think |
Metasploit run lines:
|
I'd kinda prefer what I had originally suggested to keep the datastore options and their significance intuitive and consistent. I think a lot of users are inclined to just use the muscle memory of setting |
@smcintyre-r7 please look at it now, I made the suggested changes - PR #19076 |
The changes I see in #19076 are not quite what I had in mind. Those changes add two new datastore options instead of reusing the existing RPORT and SMBDirect. I've been waiting for #19095 to land to incorporate the changes from a008288 which adds the |
@smcintyre-r7 there is no need to wait, as setting SMBDirect is sufficient to change the behavior of the underlying code, but if you want to wait, we will wait |
Summary
The
auxiliary/scanner/smb/smb_version
module currently takes great pains to exclude theRPORT
variable (amongst several others):https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/smb/smb_version.rb#L50
Motivation
In some pivoting scenarios (for example,
ssh -L
) the redirected SMB server may not be listening on the normal TCP port 445. Allowing the option (with the default of 445, of course) will enable these scenarios.In my quick testing, removing line 50, as well as lines 53-59, re-enabled those options and enabled the workflow I'm describing.
Hopefully this isn't too much of an xkcd 1172 scenario.
Before removing those lines:
Afterwards:
The text was updated successfully, but these errors were encountered: