Module: Msf::Payload::Adapter::Fetch::Server::TFTP

Included in:
TFTP
Defined in:
lib/msf/core/payload/adapter/fetch/server/tftp.rb

Overview

Provides the server used by TFTP fetch payload adapters.

Instance Method Summary collapse

Instance Method Details

#add_resource(fetch_service, uri, srv_entry) ⇒ Object



52
53
54
55
56
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 52

def add_resource(fetch_service, uri, srv_entry)
  vprint_status("Adding TFTP resource #{uri}")
  fetch_service.register_file(uri, srv_entry[:data], datastore['FETCH_SRVONCE'])
  @myresources << uri
end

#cleanup_tftp_fetch_service(fetch_service) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 31

def cleanup_tftp_fetch_service(fetch_service)
  @myresources.each do |uri|
    fetch_service.deregister_file(uri)
  end
  @myresources = []
  fetch_service = nil
end

#fetch_protocol ⇒ Object



39
40
41
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 39

def fetch_protocol
  'TFTP'
end

#initialize(*args) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 3

def initialize(*args)
  super
  register_options(
    [
      Msf::OptBool.new('FETCH_SRVONCE', [ true, 'Stop serving the payload after it is retrieved', true ])
    ]
  )
end

#register_options(registered_options, owner = self.class) ⇒ void (protected)

This method returns an undefined value.

Native Linux TFTP fetches always store the payload under its served URI, while curl's tftp:// support can use the configured destination. Since LinuxOptions registers destination options after this mixin initializes, update their display conditions after each batch of options is registered.

Parameters:

  • registered_options (Array<Msf::OptBase>) —

    Options to register.

  • owner (Class) (defaults to: self.class) —

    Class that owns the options.



20
21
22
23
24
25
26
27
28
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 20

def register_options(registered_options, owner = self.class)
  result = super
  if linux?
    %w[FETCH_FILENAME FETCH_WRITABLE_DIR].each do |option_name|
      options[option_name]&.conditions = ['FETCH_COMMAND', '==', 'CURL']
    end
  end
  result
end

#start_tftp_fetch_handler(srvport, srvhost) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 58

def start_tftp_fetch_handler(srvport, srvhost)
  fetch_service = start_tftp_server(srvport, srvhost)
  if fetch_service.nil?
    cleanup_handler
    fail_with(Msf::Exploit::Failure::BadConfig, "Fetch handler failed to start on #{Rex::Socket.to_authority(srvhost, srvport)}")
  end
  fetch_service
end

#start_tftp_server(srvport, srvhost) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/msf/core/payload/adapter/fetch/server/tftp.rb', line 43

def start_tftp_server(srvport, srvhost)
  vprint_status("Starting TFTP server on #{Rex::Socket.to_authority(srvhost, srvport)}")
  Rex::ServiceManager.start(
    Rex::Proto::TFTP::Server,
    srvport, srvhost,
    { 'Msf' => framework, 'MsfExploit' => self }
  )
end