diff --git a/lib/msf/core/payload/python/meterpreter_loader.rb b/lib/msf/core/payload/python/meterpreter_loader.rb index b5db7c647f..3c14a4d7c1 100644 --- a/lib/msf/core/payload/python/meterpreter_loader.rb +++ b/lib/msf/core/payload/python/meterpreter_loader.rb @@ -1,6 +1,7 @@ # -*- coding: binary -*- require 'msf/core' +require 'msf/core/payload/transport_config' require 'msf/base/sessions/meterpreter_options' require 'msf/core/payload/uuid/options' @@ -16,6 +17,7 @@ module Payload::Python::MeterpreterLoader include Msf::Payload::Python include Msf::Payload::UUID::Options + include Msf::Payload::TransportConfig include Msf::Sessions::MeterpreterOptions def initialize(info = {}) @@ -106,17 +108,11 @@ module Payload::Python::MeterpreterLoader # so we need to generate it # TODO: move this to somewhere more common so that it can be used across payload types unless opts[:url].to_s == '' + + # Build the callback URL (TODO: share this logic with TransportConfig uri = "/#{opts[:url].split('/').reject(&:empty?)[-1]}" - - scheme = opts[:url].to_s.split(':')[0] - lhost = ds['LHOST'] - lport = ds['LPORT'] - if ds['OverrideRequestHost'] - scheme = ds['OverrideScheme'] || scheme - lhost = ds['OverrideLHOST'] || lhost - lport = ds['OverrideLPORT'] || lport - end - + opts[:scheme] ||= opts[:url].to_s.split(':')[0] + scheme, lhost, lport = transport_uri_components(opts) callback_url = "#{scheme}://#{lhost}:#{lport}#{ds['LURI']}#{uri}/" # patch in the various payload related configuration diff --git a/lib/msf/core/payload/transport_config.rb b/lib/msf/core/payload/transport_config.rb index 57c06aaa3d..678d3b305f 100644 --- a/lib/msf/core/payload/transport_config.rb +++ b/lib/msf/core/payload/transport_config.rb @@ -36,12 +36,26 @@ module Msf::Payload::TransportConfig def transport_config_reverse_https(opts={}) ds = opts[:datastore] || datastore + opts[:scheme] ||= 'https' config = transport_config_reverse_http(opts) config[:ssl_cert_hash] = get_ssl_cert_hash(ds['StagerVerifySSLCert'], ds['HandlerSSLCert']) config end + def transport_uri_components(opts={}) + ds = opts[:datastore] || datastore + scheme = opts[:scheme] + lhost = ds['LHOST'] + lport = ds['LPORT'] + if ds['OverrideRequestHost'] + scheme = ds['OverrideScheme'] || scheme + lhost = ds['OverrideLHOST'] || lhost + lport = ds['OverrideLPORT'] || lport + end + [scheme, lhost, lport] + end + def transport_config_reverse_http(opts={}) # most cases we'll have a URI already, but in case we don't # we should ask for a connect to happen given that this is @@ -54,15 +68,8 @@ module Msf::Payload::TransportConfig end ds = opts[:datastore] || datastore - - scheme = opts[:url].to_s.split(':')[0] - lhost = ds['LHOST'] - lport = ds['LPORT'] - if ds['OverrideRequestHost'] - scheme = ds['OverrideScheme'] || scheme - lhost = ds['OverrideLHOST'] || lhost - lport = ds['OverrideLPORT'] || lport - end + opts[:scheme] ||= 'http' + scheme, lhost, lport = transport_uri_components(opts) { scheme: scheme,