Module: Msf::Payload::TransportConfig

Overview

This module contains helper functions for creating the transport configuration stubs that are used for Meterpreter payloads.

Constant Summary

Constants included from Rex::Payloads::Meterpreter::UriChecksum

Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN_MAX_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITPH, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITW, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INIT_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MIN_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MODES, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_UUID_MIN_LEN

Instance Method Summary collapse

Methods included from UUID::Options

#generate_payload_uuid, #generate_uri_uuid_mode, #initialize, #record_payload_uuid, #record_payload_uuid_url

Methods included from Rex::Payloads::Meterpreter::UriChecksum

#generate_uri_checksum, #generate_uri_uuid, #process_cookie_resource, #process_query_string_resource, #process_uri_resource, #process_uuid_string, #uri_checksum_lookup

Methods included from Pingback::Options

#initialize

Instance Method Details

#transport_config_bind_named_pipe(opts = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/msf/core/payload/transport_config.rb', line 118

def transport_config_bind_named_pipe(opts={})
  ds = opts[:datastore] || datastore
  {
    scheme:     'pipe',
    lhost:      '.',
    uri:        "/#{ds['PIPENAME']}",
  }.merge(timeout_config(opts))

end

#transport_config_bind_tcp(opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/msf/core/payload/transport_config.rb', line 33

def transport_config_bind_tcp(opts={})
  ds = opts[:datastore] || datastore
  # For bind TCP, the payload binds on the target machine. LHOST is not meaningful
  # for bind payloads and is often left blank. If unset, bind to all interfaces:
  # '::' for IPv6 targets, '0.0.0.0' for IPv4. This avoids the mistake of binding
  # to the target's public/external IP which may not be assigned to any local interface.
  lhost = ds['LHOST'].presence || (Rex::Socket.is_ipv6?(ds['RHOST'].to_s) ? '::' : '0.0.0.0')
  {
    scheme: 'tcp',
    lhost:  lhost,
    lport:  ds['LPORT'].to_i
  }.merge(timeout_config(opts))
end

#transport_config_reverse_http(opts = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/msf/core/payload/transport_config.rb', line 76

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
  # going up as part of the stage.
  uri = opts[:uri]
  unless uri
    type = opts[:stageless] == true ? :init_connect : :connect
    uri = luri + generate_uri_uuid_mode(type, uuid: opts[:uuid])
  end

  ds = opts[:datastore] || datastore
  opts[:scheme] ||= 'http'
  scheme, lhost, lport = transport_uri_components(opts)

  {
    scheme:          scheme,
    lhost:           lhost,
    lport:           lport.to_i,
    uri:             uri,
    ua:              ds['HttpUserAgent'],
    proxy_host:      ds['HttpProxyHost'],
    proxy_port:      ds['HttpProxyPort'],
    proxy_type:      ds['HttpProxyType'],
    proxy_user:      ds['HttpProxyUser'],
    proxy_pass:      ds['HttpProxyPass'],
    host:            ds['HttpHostHeader'],
    cookie:          ds['HttpCookie'],
    referer:         ds['HttpReferer'],
    c2_profile:      opts[:c2_profile],
    custom_headers:  get_custom_headers(ds)
  }.merge(timeout_config(opts))
end

#transport_config_reverse_https(opts = {}) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/msf/core/payload/transport_config.rb', line 47

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

#transport_config_reverse_ipv6_tcp(opts = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/msf/core/payload/transport_config.rb', line 25

def transport_config_reverse_ipv6_tcp(opts={})
  ds = opts[:datastore] || datastore
  config = transport_config_reverse_tcp(opts)
  config[:scheme] = 'tcp6'
  config[:scope_id] = ds['SCOPEID']
  config
end

#transport_config_reverse_named_pipe(opts = {}) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/msf/core/payload/transport_config.rb', line 109

def transport_config_reverse_named_pipe(opts={})
  ds = opts[:datastore] || datastore
  {
    scheme: 'pipe',
    lhost:  ds[:pipe_host] || ds['PIPEHOST'],
    uri:    "/#{ds[:pipe_host] || ds['PIPENAME']}"
  }.merge(timeout_config(opts))
end

#transport_config_reverse_tcp(opts = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/msf/core/payload/transport_config.rb', line 12

def transport_config_reverse_tcp(opts={})
  ds = opts[:datastore] || datastore
  config = transport_config_bind_tcp(opts)
  config[:lhost] = ds['LHOST']
  config
end

#transport_config_reverse_udp(opts = {}) ⇒ Object



19
20
21
22
23
# File 'lib/msf/core/payload/transport_config.rb', line 19

def transport_config_reverse_udp(opts={})
  config =transport_config_reverse_tcp(opts)
  config[:scheme] = 'udp'
  config
end

#transport_uri_components(opts = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/msf/core/payload/transport_config.rb', line 56

def transport_uri_components(opts={})
  ds = opts[:datastore] || datastore
  if opts[:url]
    u = URI(opts[:url])
    scheme = u.scheme
    lhost = u.host
    lport = u.port
  else
    scheme = opts[:scheme]
    lhost = ds['LHOST']
    lport = ds['LPORT']
  end
  if ds['OverrideRequestHost']
    scheme = ds['OverrideScheme'] || scheme
    lhost = ds['OverrideLHOST'] || lhost
    lport = ds['OverrideLPORT'] || lport
  end
  [scheme, lhost, lport]
end