Stream Control Transmission Protocol (SCTP)#56
Conversation
|
Looks like you're pulling in some commits that are already landed to master; I think a rebase will fix that |
|
Ping @hdm and skape (can't seem to find a GH handle which is mildly ironic): i did this in an hour this morning and it dawns on me that there had to be some reason why the founders didn't - obviously there aren't any comments to find on code that doesn't exist, so hoping you might recall whether this was discussed and why it wasn't implemented if it was. Ping @zeroSteiner, @OJ, @timwr regarding relevant meterpreter types and discussion re implementing the pivot infrastructure in the various meterps you gents maintain. Far as SCTP compatibility for Framework-side, looks like SCTPLabs has a usermode SCTP implementation which is cross-platform @ https://github.com/sctplab/usrsctp |
09844e0 to
72864c7
Compare
Pardon, all set. |
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Netstat doesn't show SCTP sockets (on Linux anyway), but any NIDS and flow monitors might notice that "this one is not like the others." Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
|
@adfoster-r7 - we gotta land this for the framework side (new shells!!) to get reviewed. Who's taking this one? You? Come at me bro! 😁 |
|
Looks like SCTP wouldn't work on windows: Or Mac: But I was able to create a socket for the linux-y boxes I checked, such as ubuntu 2016, and centos 7, alpine 3.14 with a simple test script. Mac returned -1, all the other targets gave a valid fd back #include <stdio.h>
#include <sys/socket.h>
int main() {
int listenfd;
listenfd = socket(AF_INET, SOCK_STREAM, 132);
printf("fd: %d\n", listenfd);
}It would be great if there was wider support; but it looks like it's still a lot of targets that it could work against |
adfoster-r7
left a comment
There was a problem hiding this comment.
I think we if we move the constants to rex socket, I'd be good with these changes - it's mostly copied from the existing tcp files
| class ::Socket | ||
| IPPROTO_SCTP = 132 | ||
| SOL_SCTP = 132 | ||
| end |
There was a problem hiding this comment.
Thoughts on adding these constants to ::Rex::Socket instead?
There was a problem hiding this comment.
At the end of the day, Rex::Sockets are still Sockets so i figure the constant belongs with the rest of them. No objection to moving if we have a good reason.
The actual namespace where IPPROTO_* and SOL_* constants are defined in Ruby is ::Socket:: - parallel to where you find the SCTP constants in languages which define it.
There was a problem hiding this comment.
The rationale behind the comment was - we shouldn't patch core files we don't own, that's why ::Rex::Socket exists in the first place right?
There's also load order issues if a module ends up depending on this patched ::Socket constant, but this file hasn't been loaded etc
There was a problem hiding this comment.
Kind of? Rex::Socket is really a factory for the dynamic dispatch of API-consistent "virtual wiring" but it uses ::Socket for "everything" under the skin. If you're worried about namespace corruption, just take a look at .class.ancestors in almost any Msf object - some of the gems we pull in do things that make my work look downright pristine 😉
IMO, I'm not so much corrupting someone else's namespace as i'm fixing a missing element in their implementation - that's a real Socket class per the RFC, and they just neglected to define the constant.
There was a problem hiding this comment.
I'll treat this as not a blocker, but I'm not a massive fan of the pattern
| elsif param.proto == 'sctp' | ||
| klass = Rex::Socket::SctpServer | ||
| else | ||
| raise Rex::BindFailed.new(param.localhost, param.localport), caller |
There was a problem hiding this comment.
not a blocker: I think this is the right exception to raise here, but I worry it might be hard to debug if this code path ever triggers as it's probably caught and silently ignored in some cases in framework
There was a problem hiding this comment.
If that is the case, (IMO) we should fix it higher up in the stack where it is erroneously ignored.
I look at Rex as the "kernel" of Metasploit which needs to be consistent and informative as much as possible, especially going down to the core (Socket, IO, Event, locking, all that fun junk). That said, Errors are Objects too and we can do whatever we want with them - like mixing in/extending with an ancestor which will increase chances of trapping on Socket errors...
RFC: https://www.rfc-editor.org/rfc/rfc4960.html Define constants for SCTP in ::Socket namespace for IPPPROTO and SOL. Create param definitions and socket marshalling using the newly defined constants. Implement stream-server mechanics for SctpServer from TcpServer extending the clients with Rex::Socket::Sctp upon connection. Testing: ```ruby svr = Rex::Socket::SctpServer.create( 'LocalHost' => '127.0.0.1', 'LocalPort' => 8888 ) csock = nil Thread.new { csock = svr.accept } cli = Rex::Socket::Sctp.create( 'PeerHost' => '127.0.0.1', 'PeerPort' => 8888 ) cli.write("test\n") csock.gets $stdout.write(File.read('/proc/net/sctp/eps')) ``` Notes: No idea how/whether this is going to work on non-Linux hosts Meterpreters will need SCTPs implementation to pivot, along with the relevant encapsulation and relay mechanics within TLVs.
72864c7 to
30a2f19
Compare
|
Regarding OS support, from what i can tell, it's any moderately modern Linux (Android is an open question), any FreeBSD after 7 (which to me implies HBSD as well, but i'll test that theory to make sure), as well as Solaris 10+. |
|
Thanks boss. |
With the introduction of SCTP socket support in Rex::Socket via rapid7/rex-socket#56, Framework can utilize this protocol for session transports similarly to TCP as it is a stream-wise transport. Implement bind and reverse handlers for the new socket type. Implement example bind and reverse payloads using socat copying from the initial udp sessions implementation. Testing: Rudimentary bind session test against local Libvirt Linux VM Next steps: Implement the language-level payloads for the interpreters common to POSIX environments supporting SCTP. Implement meterpreter transports for SCTP in Python, PHP, Mettle, and Java modalities (Windows doesn't support it without carrying its own usermode protocol library).
RFC: https://www.rfc-editor.org/rfc/rfc4960.html
Define constants for SCTP in ::Socket namespace for IPPPROTO
and SOL.
Create param definitions and socket marshalling using the newly
defined constants.
Implement stream-server mechanics for SctpServer from TcpServer
extending the clients with Rex::Socket::Sctp upon connection.
Testing:
Notes:
No idea how/whether this is going to work on non-Linux hosts
Meterpreters will need SCTPs implementation to pivot, along with the relevant encapsulation and relay mechanics within TLVs.