Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
699a8e9
Rework XOR code to make more sense
OJ Oct 10, 2016
0228306
Rejig platform to use windows instead of win32/win64
OJ Oct 14, 2016
7001192
Remove binary suffixes for payloads that don't exist
OJ Oct 14, 2016
786600b
Remove the unused binary_suffix var
OJ Oct 18, 2016
ca377ca
Move the binary suffix stuff to a better location
OJ Oct 26, 2016
1d617ae
Implement first pass of architecture/platform refactor
OJ Oct 27, 2016
052045c
Update rex-arch gem to 0.1.2
OJ Oct 28, 2016
d201c5b
Force x86_64 to change over to x64 in sysinfo, tidy arch checks
OJ Oct 28, 2016
a7485c4
Use constants for base_arch
OJ Oct 28, 2016
1ca2fe1
More platform/arch/session fixes
OJ Oct 28, 2016
e936a6d
Update Gemfile to include rex-arch update
OJ Oct 28, 2016
751742f
Fix typo in arch check for inject script
OJ Oct 28, 2016
bf7e7ae
Fix silly mistake with resetting arch in sysinfo
OJ Oct 28, 2016
6364e93
Update session types to have base_platform and base_arch
OJ Oct 29, 2016
9e3960f
Update session listing to show type or platform
OJ Oct 29, 2016
0737d7c
Tidy code, remove regex and use comparison for platform checks
OJ Oct 29, 2016
8b97183
Update UUID to match detected platform, fail exploit on invalid session
OJ Oct 29, 2016
57eabda
Merge upstream/master
OJ Oct 29, 2016
e5d3fee
Final regex fix for jobs arch check
OJ Oct 29, 2016
8605992
Remove superfluous session check in the post mixin
OJ Oct 29, 2016
7773d90
Update railgun to use arch to check for 64 bit
OJ Oct 29, 2016
0730613
Add comment to hilight need to support ARCH_CMD in sess check
OJ Oct 29, 2016
640827c
Final pass of regex -> string checks
OJ Oct 29, 2016
e4edbb1
Fix encoded_payload_spec
OJ Oct 29, 2016
eeff24d
Change BSD regex as per Brent's suggestion
OJ Oct 31, 2016
ddd2d5e
Remove junk spaces from EXE exploit module
OJ Oct 31, 2016
3c56f1e
Remove commented x64 arch from sock_sendpage
OJ Oct 31, 2016
6ce7352
Revert silly change in applocker bypass
OJ Oct 31, 2016
3c57ff5
Avoid internal constants for bypassuac file path generation
OJ Oct 31, 2016
b9bbb5e
Replace regex use with direct string checks in dbvis module
OJ Oct 31, 2016
ec8536f
Fix firefox module to use symbols where appopriate
OJ Oct 31, 2016
557424d
Small tidy of the multiport_egress_traffic module
OJ Oct 31, 2016
ffb53b7
Tidy arch check in meterpreter inject
OJ Oct 31, 2016
44ac3f8
Use ARCH constant in mainframe_shell
OJ Oct 31, 2016
294b1e5
Move session_type to base, and map shell arch to string
OJ Oct 31, 2016
47ec362
Small fixes for dbvis enum
OJ Oct 31, 2016
6ec7661
Fix arch typo in meterpreter_options for x64
OJ Nov 1, 2016
0fca448
Correctly call generate_stage on native init
OJ Nov 1, 2016
a79f860
Add UUIDs to mettle stages
acammack-r7 Nov 1, 2016
e5ea4a5
Fix typo in windows cred phish module
OJ Nov 4, 2016
50c2ed8
Fix post mixin platform/session check
OJ Nov 4, 2016
abe4602
Fix tests after arch refactor
OJ Nov 4, 2016
5f56848
Fix the DB/Session test
OJ Nov 4, 2016
3bc6808
Really fix the session test this time
OJ Nov 4, 2016
d751c43
FINALLY fix the last of the tests
OJ Nov 4, 2016
be2aabb
Merge updates to mettle stages from acammack-r7
OJ Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PATH
rb-readline-r7
recog
redcarpet
rex-arch
rex-arch (= 0.1.2)
rex-bin_tools
rex-core
rex-encoder
Expand Down Expand Up @@ -235,7 +235,7 @@ GEM
recog (2.0.22)
nokogiri
redcarpet (3.3.4)
rex-arch (0.1.1)
rex-arch (0.1.2)
rex-text
rex-bin_tools (0.1.1)
metasm
Expand Down
6 changes: 5 additions & 1 deletion lib/msf/base/serializer/readable_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ def self.dump_sessions(framework, opts={})
row = []
row << session.sid.to_s
row << session.type.to_s
row[-1] << (" " + session.platform) if session.respond_to?(:platform)
if session.respond_to?(:session_type)
row[-1] << (" " + session.session_type)
elsif session.respond_to?(:platform)
row[-1] << (" " + session.platform)
end

if show_extended
if session.respond_to?(:last_checkin) && session.last_checkin
Expand Down
10 changes: 9 additions & 1 deletion lib/msf/base/sessions/command_shell_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ def on_session(session)
if self.platform and self.platform.kind_of? Msf::Module::Platform
session.platform = self.platform.realname.downcase
end
session.arch = self.arch if self.arch

if self.arch
if self.arch.kind_of?(Array)
session.arch = self.arch.join('')
else
session.arch = self.arch
end
end

end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/mainframe_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class MainframeShell < Msf::Sessions::CommandShell
# initialize as mf shell session
#
def initialize(*args)
self.platform = "mainframe"
self.arch = "zarch"
self.platform = 'mainframe'
self.arch = ARCH_ZARCH
self.translate_1047 = true
super
end
Expand Down
138 changes: 95 additions & 43 deletions lib/msf/base/sessions/meterpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def run_cmd(cmd)
#
# Load the stdapi extension.
#
def load_stdapi()
def load_stdapi
original = console.disable_output
console.disable_output = true
console.run_single('load stdapi')
Expand All @@ -294,9 +294,8 @@ def load_stdapi()
#
# Load the priv extension.
#
def load_priv()
def load_priv
original = console.disable_output

console.disable_output = true
console.run_single('load priv')
console.disable_output = original
Expand All @@ -310,7 +309,6 @@ def is_valid_session?(timeout=10)

begin
self.machine_id = self.core.machine_id(timeout)
self.payload_uuid ||= self.core.uuid(timeout)

return true
rescue ::Rex::Post::Meterpreter::RequestError
Expand All @@ -325,41 +323,18 @@ def is_valid_session?(timeout=10)
def update_session_info
username = self.sys.config.getuid
sysinfo = self.sys.config.sysinfo
tuple = self.platform.split('/')

#
# Windows meterpreter currently needs 'win32' or 'win64' to be in the
# second half of the platform tuple, in order for various modules and
# library code match on that specific string.
#
if self.platform !~ /win32|win64/

platform = case self.sys.config.sysinfo['OS']
when /windows/i
Msf::Module::Platform::Windows
when /darwin/i
Msf::Module::Platform::OSX
when /freebsd/i
Msf::Module::Platform::FreeBSD
when /netbsd/i
Msf::Module::Platform::NetBSD
when /openbsd/i
Msf::Module::Platform::OpenBSD
when /sunos/i
Msf::Module::Platform::Solaris
when /android/i
Msf::Module::Platform::Android
else
Msf::Module::Platform::Linux
end.realname.downcase

#
# This normalizes the platform from 'python/python' to 'python/linux'
#
self.platform = "#{tuple[0]}/#{platform}"
# when updating session information, we need to make sure we update the platform
# in the UUID to match what the target is actually running on, but only for a
# subset of platforms.
if ['java', 'python', 'php'].include?(self.platform)
new_platform = guess_target_platform(sysinfo['OS'])
if self.platform != new_platform
self.payload_uuid.platform = new_platform
self.core.set_uuid(self.payload_uuid)
end
end


safe_info = "#{username} @ #{sysinfo['Computer']}"
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)
# Should probably be using Rex::Text.ascii_safe_hex but leave
Expand All @@ -369,6 +344,24 @@ def update_session_info
self.info = safe_info
end

def guess_target_platform(os)
case os
when /windows/i
Msf::Module::Platform::Windows.realname.downcase
when /darwin/i
Msf::Module::Platform::OSX.realname.downcase
when /mac os ?x/i
# this happens with java on OSX (for real!)
Msf::Module::Platform::OSX.realname.downcase
when /freebsd/i
Msf::Module::Platform::FreeBSD.realname.downcase
when /openbsd/i, /netbsd/i
Msf::Module::Platform::BSD.realname.downcase
else
Msf::Module::Platform::Linux.realname.downcase
end
end

#
# Populate the session information.
#
Expand Down Expand Up @@ -493,20 +486,79 @@ def create(param)

sock = net.socket.create(param)

# sf: unsure if we should raise an exception or just return nil. returning nil for now.
#if( sock == nil )
# raise Rex::UnsupportedProtocol.new(param.proto), caller
#end

# Notify now that we've created the socket
notify_socket_created(self, sock, param)

# Return the socket to the caller
sock
end

attr_accessor :platform
attr_accessor :binary_suffix
#
# Get a string representation of the current session platform
#
def platform
if self.payload_uuid
# return the actual platform of the current session if it's there
self.payload_uuid.platform
else
# otherwise just use the base for the session type tied to this handler.
# If we don't do this, storage of sessions in the DB dies
self.base_platform
end
end

#
# Get a string representation of the current session architecture
#
def arch
if self.payload_uuid
# return the actual arch of the current session if it's there
self.payload_uuid.arch
else
# otherwise just use the base for the session type tied to this handler.
# If we don't do this, storage of sessions in the DB dies
self.base_arch
end
end

#
# Generate a binary suffix based on arch
#
def binary_suffix
# generate a file/binary suffix based on the current arch and platform.
# Platform-agnostic archs go first
case self.arch
when 'java'
'jar'
when 'php'
'php'
when 'python'
'py'
else
# otherwise we fall back to the platform
case self.platform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we're missing OSX here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we are. But technically we don't yet have OSX payloads. I did have a bigger selection of binary suffixes in here to begin with, but after chatting to @bcook-r7 I removed the ones we don't yet have payloads for. Mettle will no doubt change things up, but as we add more official payloads, this will get bigger.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agree with not getting too far ahead of ourselves. Linux should probably change soon too to reflect multiple architectures (but not now).

when 'windows'
"#{self.arch}.dll"
when 'linux' , 'aix' , 'hpux' , 'irix' , 'unix'
'lso'
when 'android', 'java'
'jar'
when 'php'
'php'
when 'python'
'py'
else
nil
end
end
end

# These are the base arch/platform for the original payload, required for when the
# session is first created thanks to the fact that the DB session recording
# happens before the session is even established.
attr_accessor :base_arch
attr_accessor :base_platform

attr_accessor :console # :nodoc:
attr_accessor :skip_ssl
attr_accessor :skip_cleanup
Expand Down
3 changes: 2 additions & 1 deletion lib/msf/base/sessions/meterpreter_android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Meterpreter_Java_Android < Msf::Sessions::Meterpreter_Java_Java

def initialize(rstream, opts={})
super
self.platform = 'java/android'
self.base_platform = 'android'
self.base_arch = ARCH_JAVA
end

def load_android
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_armle_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'armle/linux'
self.binary_suffix = 'lso'
self.base_platform = 'linux'
self.base_arch = ARCH_ARMLE
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'java/java'
self.binary_suffix = 'jar'
self.base_platform = 'java'
self.base_arch = ARCH_JAVA
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_mipsbe_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'mipsbe/linux'
self.binary_suffix = 'lso'
self.base_platform = 'linux'
self.base_arch = ARCH_MIPSBE
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_mipsle_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'mipsle/linux'
self.binary_suffix = 'lso'
self.base_platform = 'linux'
self.base_arch = ARCH_MIPSLE
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/msf/base/sessions/meterpreter_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def on_session(session)
session.load_session_info
end

if session.platform =~ /win32|win64/i
# only load priv on native windows
if session.platform == 'windows' && [ARCH_X86, ARCH_X64].include?(session.arch)
session.load_priv rescue nil
end
end

if session.platform =~ /android/i
if session.platform == 'android'
if datastore['AutoLoadAndroid']
session.load_android
end
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'php/php'
self.binary_suffix = 'php'
self.base_platform = 'php'
self.base_arch = ARCH_PHP
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/msf/base/sessions/meterpreter_python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class Meterpreter_Python_Python < Msf::Sessions::Meterpreter

def initialize(rstream, opts={})
super
self.platform = 'python/python'
self.binary_suffix = 'py'
self.base_platform = 'python'
self.base_arch = ARCH_PYTHON
end

def lookup_error(error_code)
Expand Down Expand Up @@ -116,5 +116,6 @@ def supports_zlib?
false
end
end

end
end
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_x64_mettle_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def supports_zlib?
end
def initialize(rstream, opts={})
super
self.platform = 'x64/linux'
self.binary_suffix = 'lso'
self.base_platform = 'linux'
self.base_arch = ARCH_X64
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_x64_win.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Sessions
class Meterpreter_x64_Win < Msf::Sessions::Meterpreter
def initialize(rstream, opts={})
super
self.platform = 'x64/win64'
self.binary_suffix = 'x64.dll'
self.base_platform = 'windows'
self.base_arch = ARCH_X64
end

def lookup_error(code)
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_x86_bsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Sessions
class Meterpreter_x86_BSD < Msf::Sessions::Meterpreter
def initialize(rstream, opts={})
super
self.platform = 'x86/bsd'
self.binary_suffix = 'bso'
self.base_platform = 'bsd'
self.base_arch = ARCH_X86
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/base/sessions/meterpreter_x86_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Sessions
class Meterpreter_x86_Linux < Msf::Sessions::Meterpreter
def initialize(rstream, opts={})
super
self.platform = 'x86/linux'
self.binary_suffix = 'lso'
self.base_platform = 'linux'
self.base_arch = ARCH_X86
end
end

Expand Down
Loading