1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

deduplicate code from python meterpreter

This commit is contained in:
Brent Cook 2017-12-10 13:08:05 -06:00
parent b7c231bb93
commit f7dfba6bae
2 changed files with 22 additions and 19 deletions

View File

@ -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

View File

@ -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,