Skip to content
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

AWS SSM Sessions #17430

Merged
merged 37 commits into from
Jun 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3624bee
Initial implementation for AWS SSM shells
Dec 31, 2022
9850534
Initial WebSocket connection wrapper
Jan 1, 2023
cfc24f1
Implement SSM WebSocket init/auth
Jan 1, 2023
c733dbc
Start processing AWS SSM WebSocket session frames
Jan 1, 2023
43d746c
Implement SSM WebSocket Sessions
Jan 3, 2023
46c030a
Finalize SSM Shell via WebSocket
Jan 3, 2023
7666b30
Rudimentary enumeration module for EC2+SSM
Jan 3, 2023
eba4c4b
Spoonfeed the skiddies: auto-sessions for SSM enum
Jan 4, 2023
955fb2e
SSM WebSocket session keep-alive
Jan 4, 2023
60c2f0a
SSM enumeration module filter and throttle
Jan 4, 2023
274bf6d
Make SSM keepalive optional
Jan 13, 2023
14f992a
Address some of @smcityre-r7's comments
Jan 13, 2023
99b2e1d
add aws ssm gem to lock file
jmartin-tech Jan 4, 2023
3e54ae6
Resolve crashes noted by @smcintyre-r7, simplify
Jan 21, 2023
589c225
Implement reporting and pretty output
Jan 21, 2023
453baca
Drop mask_write, tweak logging
Jan 21, 2023
27d6a89
Use keepalive in SSM aux module
Jan 21, 2023
61c2726
Fix NoMethodError for #opcode
smcintyre-r7 Feb 1, 2023
687e82a
Satisfy rubocop
smcintyre-r7 Feb 3, 2023
7e19141
Standardize DS names and set OS platforms
Feb 5, 2023
153f950
Add AwsSsmCommandShellBind session type
Feb 5, 2023
8ac5ae2
Fix sessions opening over and over again
smcintyre-r7 Apr 18, 2023
d8c8255
Set the platform in enum_ssm
smcintyre-r7 Apr 18, 2023
15ff487
Combine AWS SSM modules, autodetect platform
smcintyre-r7 Apr 18, 2023
a7d8bc6
Fix sessions opening over and over again
smcintyre-r7 Apr 18, 2023
59b3c0e
Set the platform in enum_ssm
smcintyre-r7 Apr 18, 2023
2e3a2b6
Combine AWS SSM modules, autodetect platform
smcintyre-r7 Apr 18, 2023
5b94077
Merge remote-tracking branch 'origin/pr/38' into feature/aws_ssm_sess…
Apr 22, 2023
5132302
Filter control bytes from SSM output
Apr 22, 2023
d797e5e
Simplify SSM shell output filtering
Apr 22, 2023
3a4cb35
shell_command_token_base get 0th output index
Apr 22, 2023
867902e
SSM start/stop publication
Apr 28, 2023
e926951
Fix linux tests, remove Windows support (#39)
smcintyre-r7 May 10, 2023
d8dd9bb
Move the publish timeout logic (#40)
smcintyre-r7 May 11, 2023
713ec6a
Merge branch 'master' into feature/aws_ssm_sessions
sempervictus May 16, 2023
f929d2c
Drop redundant shell_command in powershell.rb
May 16, 2023
120dc87
Pr/collab/17430 (#41)
smcintyre-r7 May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/msf/base/sessions/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,37 @@ def platform
def desc
'Powershell session'
end

#
# Takes over the shell_command of the parent
#
def shell_command(cmd, timeout = 1800)
# insert random marker
strm = Rex::Text.rand_text_alpha(15)
endm = Rex::Text.rand_text_alpha(15)

# Send the shell channel's stdin.
shell_write(";'#{strm}'\n" + cmd + "\n'#{endm}';\n")

etime = ::Time.now.to_f + timeout

buff = ''
# Keep reading data until the marker has been received or the 30 minute timeout has occured
while (::Time.now.to_f < etime)
res = shell_read(-1, timeout)
break unless res

timeout = etime - ::Time.now.to_f

buff << res
next unless buff.include?(endm)

# if you see the end marker, read the buffer from the start marker to the end and then display back to screen
buff = buff.split(/#{strm}\r\n/)[-1]
buff = buff.split(endm)[0]
buff.gsub!(/(?<=\r\n)PS [^>]*>/, '')
return buff
end
buff
end
sempervictus marked this conversation as resolved.
Show resolved Hide resolved
end
You are viewing a condensed version of this merge commit. You can view the full changes here.