Commit Graph

89 Commits

Author SHA1 Message Date
h00die 6a851855a8 spelling fixes for lib folder 2024-01-06 15:54:49 -05:00
bcoles 431804ef15 Fix typos: Replace 'the the' with 'the' 2022-12-04 17:41:24 +11:00
Spencer McIntyre 218e8c2d0c Fix a Ruby 3 syntax issue
Closes #17124

This fixes a Ruby 3 syntax issue in how the parameters are passed. The
issue caused TcpServerChannels to fail to enqueue new client
connections.
2022-11-14 17:01:51 -05:00
Spencer McIntyre 7fa29c4345 Don't bother with the address type
The address is returned in the packed format so it's always a string of
either length 0 (resolution failed), length 4 (IPv4) or length 16
(IPv6).

Anything else is invalid and will actually cause Rex::Socket.addr_ntoa
to throw an error. All meterpreters today return the IP address in one
of those three correct lengths.
2022-11-10 11:13:30 -05:00
Spencer McIntyre 83b3bfa19c Fix an error when a hostname fails to resolve 2022-11-09 08:49:19 -05:00
Spencer McIntyre 40a4d09c26 Fix SSL support in Meterpreter's TCP server 2021-11-12 09:16:22 -05:00
Spencer McIntyre fba2330f0b Support SSL TCP server channels in Meterpreter 2021-11-12 09:05:17 -05:00
Spencer McIntyre 0887188e12 Synchronize the initsock routine
This prevents the socket from being closed while negotiating SSL
2021-09-29 11:13:31 -04:00
Spencer McIntyre a5a5bfcbad Support pivoted SSL client channels 2021-09-29 11:13:31 -04:00
dwelch-r7 b95be3ed10 Zeitwerk rex folder 2021-02-08 12:24:12 +00:00
OJ d14dac26ec Support removal of TLV strings
This first bit of code aims to add a "map" to the packet functionality
that is able to translate to and from "method strings" to "command ids".
IDs are sent across the wire, and they're now integers. This removes the
need for the strings to be present in things like native meterp, and
hence makes things a little less obvious on the wire, and way less
obvious on disk/in the payload.

Given that we need this functionality in other Meterpreters to support
the removal of strings, some code has been added that can generate
source files for Python, C# and C. This code might move, but for now
it's at least in a spot where it's used the most.
2020-06-24 08:10:54 +10:00
OJ 8070074da3 Almost final refactor of how IDs are handled 2020-06-09 08:58:26 +10:00
OJ 641f298819 Support removal of TLV strings
This first bit of code aims to add a "map" to the packet functionality
that is able to translate to and from "method strings" to "command ids".
IDs are sent across the wire, and they're now integers. This removes the
need for the strings to be present in things like native meterp, and
hence makes things a little less obvious on the wire, and way less
obvious on disk/in the payload.

Given that we need this functionality in other Meterpreters to support
the removal of strings, some code has been added that can generate
source files for Python, C# and C. This code might move, but for now
it's at least in a spot where it's used the most.
2020-06-09 08:57:40 +10:00
Spencer McIntyre 078652749d Switch how channel class args are passed around 2020-02-28 10:10:47 -05:00
Spencer McIntyre e5fc41a22f Refactor the initialize method to use 'packet' 2020-02-24 14:01:01 -05:00
Spencer McIntyre e5befa676f Fix a bug with te tcp_server_channel 2020-02-18 16:06:46 -05:00
Spencer McIntyre 28e9bc5d14 Move the params_hash_from_response class method 2020-02-18 14:17:00 -05:00
Spencer McIntyre 0459e05420 Update returned socket parameters from meterpreter 2020-02-18 00:36:04 -05:00
Brent Cook 1a493c4508 Only send a close channel message once, avoid if Meterpreter told us
Don't send a close message for a nil channel ID, and if we do send a close
message, only do it once. I could have added a mutex somewher in _close(), but
because it's a class method, it's a little awkward and would require all of the
callers to instead have voluntary lock. As an alternative, I just made the
finalizer close the channel instead.

Fixes #10177
2018-09-25 02:30:38 -05:00
Spencer McIntyre 2610757f27 Include the StreamServer interface for pivoting 2018-04-20 15:10:53 -04:00
Brent Cook 5a4abeb110 make Rex UDPSocket.send work just like the real thing 2017-01-02 09:38:26 -06:00
Brent Cook bb684bb3b1 tcp channel fixes 2016-12-30 14:59:10 -06:00
OJ d136844d3b Add error handling around double-bind of ports 2016-05-03 10:42:41 +10:00
OJ 6d504316ae Add MSF-side support for reverse port forwards
This includes changes to the portfwd command so that the output is
nicer, things are easier to use, and users have the ability to create
reverse port forwards.
2016-04-06 15:38:39 +10:00
James Lee 0073a8f40e Wrap comments at 78, style 2016-03-24 15:20:43 -05:00
James Lee 6388578ee6 Style fixes 2016-03-23 16:15:46 -05:00
James Lee effee42e2f Raise a better exception for WSAEADDRINUSE 2016-03-23 13:15:38 -05:00
RageLtMan c871ceea0a Implement consistent socket abstraction
In current nomenclature, Rex Sockets are objects created by calls
to Rex::Socket::<Transport>.create and Rex::Socket.create_...
When the LocalHost or Comm parameters are set to remotely routed
addresses (currently via Meterpreter sessions), Rex will create a
Channel which will abstract communications with the remote end of
the session. These channel based abstractions are called pivots,
and present in three separate flavors:
1 - TcpClientChannel, a fully abstracted, selectable Socket.
2 - TcpServerChannel, a virtual Channel which distributes client
channels.
3 - UdpChannel, a virtual Channel which provides common methods for
UDP socket operations, but is not a full (selectable) abstraction.

Unfortunately this differentiation results in inconsistent returns
from the aforementioned socket creation calls, as the call chain
creates parameters and supplies them to the create method on the
comm object referenced in the params. The comm object may be a
channel, and produce a virtual representation of a socket with
functional methods analogous to Sockets, but without a kernel FD.

This commit begins the work of ensuring that all calls for socket
creation return selectable Rex::Socket objects with semantics
familiar to Ruby developers who have not read into the details of
Rex::Socket and Rex::Post.

-----

Summary of changes:

Convert Rex::IO::StreamAbstraction to SocketAbstraction and use
the new mixin in StreamAbstraction and DatagramAbstraction. This
approach allows for common methods to reuse the abstraction data
flow, while initializing separate types of socket obects and an
optional monitor as needed.

In the Rex::Post::Meterpreter namespace, extract common methods
from Stream to a SocketAbstraction mixin, include that mixin in
Stream, and add Datagram with the dio_write handler override
exported from the current implementation of UdpChannel, also using
the mixin. This relies on the Rex::IO work above to implement the
proper type of socket abstraction to the Channel descendants.

In Rex::Post::Meterpreter::Extensions::Stdapi::Net, convert the
UdpChannel to inherit from the Rex::Post::Meterpreter::Datagram
class, implementing only the send method at this tier. Convert
create_udp_channel to return the local socket side of the datagram
abstraction presented analogous to the TcpClientChannel approach
used before.

-----

Notes and intricacies:

In order to implement recvfrom on the UDP abstraction, a shim layer
has been put in place to forward the sockaddr information from the
remote peer to the local UDP socketpair in the abstraction. This
information takes up buffer space in the UDP socket, and in order
to maintain compatibility with consumers, the dio_write_handler
pushes the data buffer, and in a separate send call, he sockaddr
information from the remote socket. On the abstraction side, the
recvfrom_nonblock call of the real UDPSocket has been overriden
via the mixed in module to call the real method twice, once for
the data buffer, and once for the packed sockaddr data. The Rex
level consumer for recvfrom calls the underlying nonblock method
and expects this exact set of returns (as opposed to what standard
library UDPSocket.recvfrom returns, which is a data buffer and an
Array of sockaddr data).

-----

Testing:
  Local and lab testing only so far.
  Test RC script to be added in GH comments.

-----

Issues:
  Currently, sendto on a remote socket does not appear to honor
LocalPort which causes DNS responses (#6611) to come from the
wrong port to remote clients being serviced over a pivot socket.
2016-03-21 03:32:52 -04:00
James Lee 2e837b26e8 Use a Queue instead of Array 2015-11-02 16:02:45 -06:00
James Lee 0132f9ce67 Extend accepted clients with Rex Socket stuff 2015-10-09 08:53:02 -05:00
James Lee e9ccec4755 Refactor load_session_info
All of this code is in sore need of some specs but I think this change
makes it a bit easier to understand what it is supposed to be doing.
2014-01-21 18:55:54 -06:00
sinn3r d483f2ad79 Land #2618 - rm shebangs 2013-11-11 11:55:23 -06:00
Jonathan 575072585f removed shebangs from files within rex 2013-11-07 18:51:59 -05:00
OJ 2fbac9b129 Add getproxy command
This command pulls out system proxy details on windows machines.
2013-10-30 18:40:51 +10:00
Spencer McIntyre 6c382c8eb7 Return nil on error, and move the module to post/multi. 2013-10-09 16:52:53 -04:00
Meatballs 72155f8e9e Comment update 2013-09-19 19:46:05 +01:00
Tab Assassin 2e9096d427 Retab changes for PR #1734 2013-09-05 14:59:41 -05:00
Tab Assassin 322ed35bb4 Merge for retab 2013-09-05 14:59:34 -05:00
Tab Assassin 7e5e0f7fc8 Retab lib 2013-08-30 16:28:33 -05:00
Meatballs 6c62463f83 Add ipv6 resolution and remove nix 2013-06-20 22:17:31 +01:00
Meatballs 26479bbe82 Fixup resolve_host 2013-04-14 10:58:51 +01:00
Meatballs 6a7fc70274 Remove length stuff 2013-04-14 10:54:19 +01:00
Meatballs 6bca2b305f Typo 2013-04-14 10:44:00 +01:00
Meatballs 849b42ffb9 Further tidy 2013-04-14 10:42:15 +01:00
Meatballs 4b4f77eb0f Finalize 2013-04-14 10:32:56 +01:00
Meatballs 3660ad8c0a Initial attempt 2013-04-07 23:03:43 +01:00
James Lee c3fa62cd59 Whitespace at EOL 2013-03-07 18:16:57 -06:00
m m c1ca9fea79 netstat and arp commands in win32/posix meterpreter 2012-08-28 17:02:37 -05:00
James Lee 5110aad0f3 Add better docs on some File methods 2012-07-17 17:32:27 -06:00
HD Moore d656e3185f Mark all libraries as defaulting to 8-bit strings 2012-06-29 00:18:28 -05:00