-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Add socket channel tests #20689
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
Add socket channel tests #20689
Conversation
|
Converted to a draft so I can watch the tests run and ensure everything is running and passing in the way I'd expect. |
1f18b7e to
95fa10e
Compare
9a1b15e to
a7b5aef
Compare
5c1bc74 to
96f8a47
Compare
jheysel-r7
left a comment
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.
Thanks for making these changes @zeroSteiner! Changes were as expected:
Testing
PHP Meterpreter on Linux
msf payload(php/meterpreter/reverse_tcp) > WARNING: Local file /home/msfuser/git/metasploit-framework/data/meterpreter/meterpreter.php is being used
msf post(test/socket_channels) > run
[*] Running against session 2
[*] Session type is meterpreter and platform is linux
[*] Running UDP channel tests...
[-] Meterpreter session 4 is not valid and will be closed
WARNING: Local file /home/msfuser/git/metasploit-framework/data/meterpreter/meterpreter.php is being used
[*] Sending stage (41224 bytes) to 172.16.199.138
[*] 172.16.199.138 - Meterpreter session 4 closed.
[-] [[UDP] Has the correct peer information] FAILED: [UDP] Has the correct peer information
[-] [[UDP] Has the correct peer information] Exception: Interrupt:
[-] [[UDP] Receives data from the peer] FAILED: [UDP] Receives data from the peer
[-] [[UDP] Receives data from the peer] Exception: Interrupt:
[+] [UDP] Sends data to the peer
[*] Running TCP client channel tests...
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running TCP server channel tests...
[-] [[TCP-Server] Accepts a connection] FAILED: [TCP-Server] Accepts a connection
[-] [[TCP-Server] Accepts a connection] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Has the correct peer information] FAILED: [TCP-Server] Has the correct peer information
[-] [[TCP-Server] Has the correct peer information] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Receives data from the peer] FAILED: [TCP-Server] Receives data from the peer
[-] [[TCP-Server] Receives data from the peer] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Sends data to the peer] FAILED: [TCP-Server] Sends data to the peer
[-] [[TCP-Server] Sends data to the peer] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Propagates close events to the server] FAILED: [TCP-Server] Propagates close events to the server
[-] [[TCP-Server] Propagates close events to the server] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Propagates close events to the peer] FAILED: [TCP-Server] Propagates close events to the peer
[-] [[TCP-Server] Propagates close events to the peer] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] [[TCP-Server] Propagates close events from the peer] FAILED: [TCP-Server] Propagates close events from the peer
[-] [[TCP-Server] Propagates close events from the peer] Exception: Rex::Post::Meterpreter::RequestError: core_channel_open: Operation failed: 1
[-] Passed: 6; Failed: 9; Skipped: 0
[*] Post module execution completed
Java Meterpreter on Linux
msf post(test/socket_channels) > run
[*] Running against session -1
[*] Session type is meterpreter and platform is linux
[*] Running TCP client channel tests...
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running UDP channel tests...
[-] FAILED: [UDP] Has the correct peer information
[+] [UDP] Receives data from the peer
[+] [UDP] Sends data to the peer
[*] Running TCP server channel tests...
[+] [TCP-Server] Accepts a connection
[+] [TCP-Server] Has the correct peer information
[+] [TCP-Server] Receives data from the peer
[+] [TCP-Server] Sends data to the peer
[+] [TCP-Server] Propagates close events to the server
[+] [TCP-Server] Propagates close events to the peer
[+] [TCP-Server] Propagates close events from the peer
[-] Passed: 14; Failed: 1; Skipped: 0
[*] Post module execution completed
Linux Meterpreter
msf post(test/socket_channels) > run
[*] Running against session -1
[*] Session type is meterpreter and platform is linux
[*] Running TCP client channel tests...
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running UDP channel tests...
[-] FAILED: [UDP] Has the correct peer information
[+] [UDP] Receives data from the peer
[+] [UDP] Sends data to the peer
[*] Running TCP server channel tests...
[+] [TCP-Server] Accepts a connection
[+] [TCP-Server] Has the correct peer information
[+] [TCP-Server] Receives data from the peer
[+] [TCP-Server] Sends data to the peer
[+] [TCP-Server] Propagates close events to the server
[+] [TCP-Server] Propagates close events to the peer
[+] [TCP-Server] Propagates close events from the peer
[-] Passed: 14; Failed: 1; Skipped: 0
[*] Post module execution completed
Python Meterpreter on Linux
msf post(test/socket_channels) > run
[*] Running against session -1
[*] Session type is meterpreter and platform is linux
[*] Running TCP client channel tests...
[+] [TCP-Client] Has the correct peer information
[+] [TCP-Client] Receives data from the peer
[+] [TCP-Client] Sends data to the peer
[+] [TCP-Client] Propagates close events to the peer
[+] [TCP-Client] Propagates close events from the peer
[*] Running UDP channel tests...
[-] FAILED: [UDP] Has the correct peer information
[+] [UDP] Receives data from the peer
[+] [UDP] Sends data to the peer
[*] Running TCP server channel tests...
[+] [TCP-Server] Accepts a connection
[+] [TCP-Server] Has the correct peer information
[+] [TCP-Server] Receives data from the peer
[+] [TCP-Server] Sends data to the peer
[+] [TCP-Server] Propagates close events to the server
[+] [TCP-Server] Propagates close events to the peer
[+] [TCP-Server] Propagates close events from the peer
[-] Passed: 14; Failed: 1; Skipped: 0
[*] Post module execution completed
SSH Session Failing on Linux:
msf post(test/socket_channels) > run
[*] Running against session -1
[*] Session type is shell and platform is linux
[*] Running TCP client channel tests...
[-] FAILED: [TCP-Client] Allows binding to port 0
[-] SSH Command Stream encountered an error: undefined method `shutdown' for nil (Server Version: SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.14)
[+] [TCP-Client] Has the correct peer information
[*] 172.16.199.130 - SSH session 1 closed. Reason: Died
[-] [[TCP-Client] Receives data from the peer] FAILED: [TCP-Client] Receives data from the peer
[-] [[TCP-Client] Receives data from the peer] Exception: Rex::ConnectionTimeout: The connection with (127.0.0.1:46523) timed out.
[-] [[TCP-Client] Sends data to the peer] FAILED: [TCP-Client] Sends data to the peer
[-] [[TCP-Client] Sends data to the peer] Exception: Rex::ConnectionTimeout: The connection with (127.0.0.1:40485) timed out.
[-] [[TCP-Client] Propagates close events to the peer] FAILED: [TCP-Client] Propagates close events to the peer
[-] [[TCP-Client] Propagates close events to the peer] Exception: Rex::ConnectionTimeout: The connection with (127.0.0.1:44695) timed out.
[-] [[TCP-Client] Propagates close events from the peer] FAILED: [TCP-Client] Propagates close events from the peer
[-] [[TCP-Client] Propagates close events from the peer] Exception: Rex::ConnectionTimeout: The connection with (127.0.0.1:44561) timed out.
[*] Running TCP server channel tests...
[-] [[TCP-Server] Allows binding to port 0] FAILED: [TCP-Server] Allows binding to port 0
[-] [[TCP-Server] Allows binding to port 0] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Accepts a connection] FAILED: [TCP-Server] Accepts a connection
[-] [[TCP-Server] Accepts a connection] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Has the correct peer information] FAILED: [TCP-Server] Has the correct peer information
[-] [[TCP-Server] Has the correct peer information] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Receives data from the peer] FAILED: [TCP-Server] Receives data from the peer
[-] [[TCP-Server] Receives data from the peer] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Sends data to the peer] FAILED: [TCP-Server] Sends data to the peer
[-] [[TCP-Server] Sends data to the peer] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Propagates close events to the server] FAILED: [TCP-Server] Propagates close events to the server
[-] [[TCP-Server] Propagates close events to the server] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Propagates close events to the peer] FAILED: [TCP-Server] Propagates close events to the peer
[-] [[TCP-Server] Propagates close events to the peer] Exception: Rex::ConnectionError: A socket error occurred.
[-] [[TCP-Server] Propagates close events from the peer] FAILED: [TCP-Server] Propagates close events from the peer
[-] [[TCP-Server] Propagates close events from the peer] Exception: Rex::ConnectionError: A socket error occurred.
[!] UDP channels are not supported by SSH sessions.
[-] Passed: 1; Failed: 13; Skipped: 0
[*] Post module execution completed
96f8a47 to
1a9c101
Compare
3740931 to
2d646a9
Compare
|
I'm reconsidering the severity of the While it's kinda confusing that Rex::Socket is different in this regard, as long as the author ensures that their sockets are always either raw Ruby UDPSocket instances or Rex::Socket::Udp instances, there shouldn't be any bugs. With that in mind, I think either I should update the test and moving forward we'll keep the Rex API causing it to pass, or the Rex API should be updated to be consistent with Rex::Socket::Udp. A quick search seems to show the use in framework is mixed. The following output shows multiple uses both where two values are expected to be returned (Ruby socket) and three values are expected to be returned (Rex::Socket). #recvfrom grep |
2d646a9 to
f2a05ad
Compare
Release NotesAdds tests for socket channels in Meterpreter and SSH sessions. |
Adds tests for socket channels in Meterpreter and SSH sessions.
Verification
Demo: Python Meterpreter on Linux
Demo: SSH on Linux
This is full of fail and the underlying issue (possibly issues?) should be addressed, but this PR was already scope creep'ed out of the work in #20677. UDP should be skipped because UDP channels aren't defined in the SSH spec, but TCP client and server channels should work.