-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Support Encrypted MSSQL Sessions #20677
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
base: master
Are you sure you want to change the base?
Conversation
f2aedf6 to
a6c4485
Compare
a6c4485 to
750e664
Compare
| def dio_close_handler(packet) | ||
| rsock.close | ||
|
|
||
| return super(packet) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed because the #close method is no longer replaced with something that'd close the channel. The original logic was prone to creating recursion loops during development and would send a close command back to Meterpreter when Meterpreter initiated the close operation.
The new implementation should simply things by always closing the channel from the channel object level instead of the rsock. Now when a channel is closed by Meterpreter, the #dio_close_handler will simply close and cleanup the channel locally without echoing the command back to Meterpreter.
When the channel is closed by Metasploit Framework, it's either closed by lsock.close which causes an EOF to be read in the Relay Manager which will dispatch to the on_exit callback, which by default calls #close_write. Alternatively, the channel object can be closed directly, but there's no longer a loop as everything is notified.
|
I started work on a test module for testing socket channels (TCP client, TCP server and UDP). It's a WIP, but can be used for testing here: https://github.com/zeroSteiner/metasploit-framework/blob/feat/mod/socket-channel-tests/test/modules/post/test/socket_channels.rb I think it probably makes sense to keep it in a separate branch and PR it on its own especially if there are pre-existing issues and inconsistencies. Preview |
This enables sessions to MSSQL servers that require encryption. Currently, Metasploit can bruteforce MSSQL servers that offer/require encryption because our login method will proxy the traffic over an SSL socket using the old
TDSSSLProxyclass. The existing logic didn't support sessions though, so when a user wanted encryption (setSSLto true) or the server required it, Metasploit would fail to establish an interactive session or do anything after the login operation. Metasploit was effecitvely unable to communicate with the MSSQL server after the login operation when encryption was requried or enabled.These changes add a new
MsTds::Channelwhich leverages Rex's socket abstraction to facilitate the necessary encapsulation for the TLS negotiation. The TLS negotiation is more complex than other protocols because the frames used during the negotiation process have to be encapsulated within MS-TDS framing. Once TLS is established, the MS-TDS frames are within the tunnel. This encapsulation can be seen in theMsTds::Channelclass#writeand#_read_handlermethods.The
MsTds::Channelhas a couple of advantages over the old proxy class. The first is the channel object is now always used for the communication, there's no need to switch to writing to the proxy object or swap sockets instead when SSL is in use. The second is that it's using the newRex::Proto::Tcp#starttlsmethod which ensures that the TLS options are consistent with other usages in the framework.Requires:
monitor_sockcan be used with the callbacks#starttlsmethodCloses #18745
Verification
MsTds::Channelobjectmssql_loginmodule to authenticate to it and establish an interactive sessionmsfconsoleprompt, notmeterpreter, use theconnectcommand and the-cargument to specify the session object, connect to a netcat listenerCtrl+Cfrom Metasploit, repeat the connection setup and terminate it from the netcat listenerMsTds::Channelby closing the connection from the MSSQL server using theKILLquery verb just know that theKILLquery can't be used to kill the connection that's making the query.#starttlsmethod)