Commit Graph

68737 Commits

Author SHA1 Message Date
Spencer McIntyre 2e3a2b6f6d Combine AWS SSM modules, autodetect platform 2023-04-19 18:05:50 -04:00
Spencer McIntyre 59b3c0e945 Set the platform in enum_ssm
Update the enum_ssm module to use the correct session type with the
appropriate platform. Also set the session information to the same
string which also removes the eye sore that is the shell banner.
2023-04-19 18:05:50 -04:00
Spencer McIntyre a7d8bc6757 Fix sessions opening over and over again
Also make some code cleanups
2023-04-19 18:05:50 -04:00
RageLtMan 153f950f11 Add AwsSsmCommandShellBind session type
Create an AwsSsmCommandShellBind session type to provide intercept
points for shell command interactions and a wrapper class which is
used to register the new session.

Update Msf::Handler::BindAwsSsm with its own #create_session method
utilizing the new session type to provide direct control of session
initialization.

Restore standard handler attributes and thread nomenclature in an
attempt to resolve the repeating session creation when #to_handler
is called on the payloads.

Testing:
  Tested in local framework, unfortunately the recurring session
init problem appears to persist. Requesting testing on an upstream
Framework by saner folks.
2023-02-04 20:57:26 -05:00
RageLtMan 7e19141dfc Standardize DS names and set OS platforms
Update SSM handler code to standardize datastore option names per
@zeroSteiner.
Update payload modules to reflect the OS targets against which they
are to execute.
2023-02-04 19:41:40 -05:00
Spencer McIntyre 687e82a9ed Satisfy rubocop 2023-02-03 15:29:19 -05:00
Spencer McIntyre 61c2726620 Fix NoMethodError for #opcode 2023-02-01 18:19:46 -05:00
RageLtMan 27d6a89b99 Use keepalive in SSM aux module 2023-01-21 09:26:06 -05:00
RageLtMan 453baca109 Drop mask_write, tweak logging 2023-01-21 08:29:28 -05:00
RageLtMan 589c2257e3 Implement reporting and pretty output 2023-01-20 23:17:34 -05:00
RageLtMan 3e54ae6e69 Resolve crashes noted by @smcintyre-r7, simplify
Bail out of console resize operation if ::IO.console doesn't exist
Enforce REGION datastore option and remove the multi-region enum
code by Aaron - users can write resource scripts if they need
automation.
2023-01-20 22:33:51 -05:00
Jeffrey Martin 99b2e1d709 add aws ssm gem to lock file 2023-01-13 09:59:05 -05:00
RageLtMan 14f992aa88 Address some of @smcityre-r7's comments
Explicitly `require 'aws-sdk-ec2'` in the aux module
Fix the hard-coded region to use datastore option
2023-01-13 09:55:51 -05:00
RageLtMan 274bf6dcb7 Make SSM keepalive optional 2023-01-13 09:54:34 -05:00
RageLtMan 60c2f0a480 SSM enumeration module filter and throttle
Expand SSM enumeration module docs to explain full functionality.
Enable the LIMIT configuration option to restricte results per
region.
Implement FILTER_EC2_ID configuration option to permit targeting
of a specific instance for session initiation.

Testing:
  Finds limtied sets of systems and initiates sessions
  Finds desired system ID and initiates session
2023-01-03 22:00:14 -05:00
RageLtMan 955fb2ef3e SSM WebSocket session keep-alive
The SSM session socket times out without data being sent at the
upper (SSM) WS layer. Implement keep-alive in a separate thread
which simply writes nothing into the channel at irregular intervals
to simulate user activity.

Testing:
  Sessions established with this code running have not timed-out
in over 15m despite being completely unused
2023-01-03 21:20:07 -05:00
RageLtMan eba4c4b047 Spoonfeed the skiddies: auto-sessions for SSM enum
Enable session acquisition from AWS SSM enumeration module simiar
to how the telnet login scanner acquires sessions on the sockets
exposed.

Testing
  Tested execution - finds systems, gets shells, autopwn-capable
2023-01-03 20:40:30 -05:00
RageLtMan 7666b30b82 Rudimentary enumeration module for EC2+SSM
Coopt Aaron Soto's EC2 enum module & replace the guts with an SSM
query for not-terminated EC2 instances with SSM capability. This
will proide users with the instance IDs needed to test their SSM
shells and can be expanded to report information or even act as a
"brute-force" module which automatically starts SSM sessions.

Testing:
  None - might eat your monitor lizard
2023-01-03 17:09:55 -05:00
RageLtMan 46c030a08b Finalize SSM Shell via WebSocket
Implement terminal resizing to WebSocket shell
Reorganize code to ease later extension
Implement peerinfo in channel context from AWS EC2 SSM information
gathered during session validation
Implement echo-filtering for session inputs (hacky, but works)

Testing:
  Verified console resizing, color/reset/etc
  Verified peerinfo and interaction
  Verified common session operations

Notes:
  SSM WebSocket sessions time out pretty quickly, implementing
dedicated SSM session types which support suspend/resume to match
backgrounding/foregrounding operations in the console should help
to resolve this. Alternatively, a keep-alive using empty frames
may be implemented in the SsmChannel itself on a separate thread.
2023-01-03 15:10:31 -05:00
RageLtMan 43d746c404 Implement SSM WebSocket Sessions
Alter WebSocket::Interface::Channel to accept a mask_write flag to
set the Channel behavior for outgoing data (since the on_data_write
handler can only deal with the buffer provided, not how the wsframe
containing it is written to the "wire"). Set the flag to false for
SSM's WebSocket operations.

Extract Rex::Proto::Http::WebSocket::AmazonSsm from the handler to
permit reuse by other framework elements.

Implement SSM-specific UUID handling.
Create sane SsmFrame constructor to permit convenient operations.

Implement Http::WebSocket::AmazonSsm::Inteface::SsmChannel from
Http::WebSocket::Inferface::Channel with message-type handling and
output processing. Acknowledge incoming messages, process incoming
acknowledgements, increment sequence IDs appropriately, and handle
basic logging.

This new session type removes the 2500 char output restriction and
stateless peer cwd.

Testing:
  Execution of handler now provides stateful interactive shells

Next steps:
  More testing, preferably by other people with upstream framework.
  Peerinfo and presentation updates for the session channel
  Misc cleanup

Future work:
  Implement new SSM session type with support for multi-console,
port-forwarding/socket routing, and custom SSM documents.
  Implement FSM handlers for session suspension and resumption in
Http::WebSocket::AmazonSsm::Interface::SsmChannel
2023-01-03 09:34:14 -05:00
RageLtMan c733dbc906 Start processing AWS SSM WebSocket session frames
Create BinData structure to handle the proprietary format of AWS'
SSM WebSocket protocol. Implement relevant inter-field dependencies
and a virtual payload_valid field to handle the SHA256 digest check
for the current state of r the payload_data field.

Implement user-accessible SSM document definition to permit use of
custom-defined command and session documents (stubbing for session
types such as port-forwarding) which may be of use when dealing
with restrictive IAM.

Restructure handler in preparation for moving the WebSocket code
into Rex::Proto for use by other consumers such as custom payloads
and session types like fully interactive (vs REPL) modalities, or
some form of "cloud-native" MeterSSM.

Testing:
  Verified acquisition of SSM WS frame and relevant field ops

Next Steps:
  Create WS loop to abstract shell communications
  Wrap in Rex*Abstraction bowties for the session handler
  Test -> ? -> Profit
2023-01-01 11:21:32 -05:00
RageLtMan cfc24f138a Implement SSM WebSocket init/auth
Using the implementation in https://github.com/humanmade/ssm, use
the onconnect websocket authenticator as a JSON string written as
a wstext Frame into the established WebSocket. This keeps the sock
open with AWS after returning it from the method, but subsequent
operations will require definition and encoding/decoding of SSM's
proprietary data structures.

Testing:
  The initialized WebSocket is kept open and returns wsframes when
requested.

Next steps:
  Port the various data structures from the JavaScript library
  Implement encoding & decoding for their wire-level formats
  Implement state management and data flow handling logic for
the WS SSM protocol.
2022-12-31 20:46:19 -05:00
RageLtMan 9850534d55 Initial WebSocket connection wrapper
Port WebSocket initiation routine from Exploit::Remote::HttpClient.
Currently inert since it appears to require a handshake procedure
along with its own type of data frame.

Implement graceful fail-down for session establishment which tries
to initiate a WebSocket session for proper functionality, failing
down to the script-execution style session abstraction if the WS
session does not marshal properly. Use this exception handling to
deal with the WIP WS session state.

Testing:
  Gets the same kind of command-abstracted session as before
  Interface-extended socket returns garbage from naive #write and
nothing from put_string or put_binary - not going to get anything
out of this thing until we establish the handshake procedure.

Next steps:
  Figure out data frame structures for handshake and console IO
  Implement handshake on-init, validate state
  Implement IO abstraction for the resulting Channel for handoff
to #handle_connection
2022-12-31 19:05:06 -05:00
RageLtMan 3624bee263 Initial implementation for AWS SSM shells
Amazon Web Services provides conveniently privileged backdoors in
the form of their SSM agents which do not require connectivity with
the target instance, merely valid credentials to AWS' API. Due to
this indirect "connection" paradigm, this mechanism can be used to
control otherwise "air-gapped" targets.

This approach abstracts asynchronous request/response parsing for
SSM requests into an IO channel with which the AWS SSM client is
then wrapped to emulate the expected Stream. The mechanism is rather
raw and could use better error handling, retries on laggy output,
and a threadsafe cursor implementation. It may be possible to start
an actually interactive session using the #start_session method in
the AWS client library, but so far testing has not yielded positive
results.

There is a significant limitation with these sessions not present
in normal stream-wise abstractions: a response limit of 2500 chars.
This limitation can be overcome by utilizing an S3 bucket to store
command output; however, due to the nature of access we seek to
obtain, it would not only add to the logged event loads but retain
the results of our TTPs in a "buffer" accessible to other people.
This functionality can be added down the line in the form of S3
config options in the handler to be passed into the SSM client for
command execution and acquisition of output.

Testing:
  Gets sessions, provides command IO, leaves a bunch of log entries
in CloudTrail (something to keep in mind for opsec considerations).

Next steps:
  Reorganize our WebSocket code a bit to provide connection and WS
state management inside Rex::Proto::Http::Client which can then be
exposed to the Handler without having to mix-in other namespaces
from Exploit.
  Use the #start_session SSM Client method to extract the WS URL
for the relevant channel, and utilize that as the underpinning for
our session comms.
2022-12-31 15:04:27 -05:00
Metasploit 69f47aa6a7
automatic module_metadata_base.json update 2022-12-12 17:09:12 -06:00
Spencer McIntyre d09aef7dc5
Land #17350, Remove unnecesary sleep
Remove unnecesary sleep in several bypassuac modules
2022-12-12 17:45:10 -05:00
Spencer McIntyre 5a66666b4d Fix check methods by using #present? 2022-12-12 16:53:34 -05:00
Metasploit f534168636
automatic module_metadata_base.json update 2022-12-12 13:46:17 -06:00
Spencer McIntyre 024fc87b4c
Land #17272, Add F5 MCP post module
Add F5 MCP post module
2022-12-12 14:20:31 -05:00
Ron Bowes 5b1e37bf66
Merge pull request #2 from smcintyre-r7/pr/collab/17272
Store service credentials in the database
2022-12-12 10:10:03 -08:00
dwelch-r7 c9aab1201c
Land #17363, Add enckrbkey database persistence support 2022-12-12 17:44:47 +00:00
Grant Willcox 2cb66a5c8b
Land #17355, Update the creds command to allow viewing ssh key contents 2022-12-12 11:29:47 -06:00
adfoster-r7 431bfdfc52
Add enckrbkey database persistence support 2022-12-12 17:19:17 +00:00
Grant Willcox c5439b85ef
Land #17361, unlock concurrent-ruby 2022-12-12 10:36:48 -06:00
Grant Willcox 8a68111198
Land #17357, Update docs site to support mermaid 2022-12-12 10:04:07 -06:00
Jeffrey Martin 60302e1f02
unlock concurrent-ruby
Version was locked due to yanked ver 1.1.0, this should have been unlocked long ago.
2022-12-12 08:58:22 -06:00
adfoster-r7 fd3fb5f3a4
Update docs site to support mermaid 2022-12-11 01:22:30 +00:00
adfoster-r7 2ea880c799
Show ssh key with verbose creds command 2022-12-10 00:08:54 +00:00
Grant Willcox c84b2a67d7
Land #17345, Update report api to return nil when no active db 2022-12-09 14:02:28 -06:00
Metasploit 90828ac2bb
automatic module_metadata_base.json update 2022-12-09 12:42:23 -06:00
Spencer McIntyre d9b217e50b
Land #17351, Fix bug in s4u_persistence module
Fix buggy default in s4u_persistence module
2022-12-09 13:16:53 -05:00
Grant Willcox b65b0a7bc5
Land #17352, Fixes crash in meterp when file_version asks for a file that doesn't exist 2022-12-09 12:10:29 -06:00
Grant Willcox e29d9effba
Land #17346, Update rspec thread counting logic 2022-12-09 10:32:55 -06:00
Jeffrey Martin 32a5c350cb
Land 17349, Update Ruby version to 3.0.5 2022-12-09 08:39:03 -06:00
Ashley Donaldson 99e576d023
Fixes crash in meterp when file_version asks for a file that doesn't exist 2022-12-09 11:55:29 +11:00
Ashley Donaldson 8d097e0fd0
Fixes bug in s4u_persistence module 2022-12-09 11:24:16 +11:00
Ashley Donaldson c54109586c
Remove unnecesary sleep in several bypassuac modules 2022-12-09 11:09:19 +11:00
Grant Willcox f6beef9b23
Update Ruby version in Dockerfile 2022-12-08 14:59:58 -06:00
Grant Willcox 6126598d16
Update Ruby version to 3.0.5 from 3.0.2 to fix security issues and compatibility 2022-12-08 13:58:46 -06:00
Metasploit 9b62242974
automatic module_metadata_base.json update 2022-12-08 13:52:01 -06:00