Class: Rex::Proto::Ftp::Server
- Inherits:
-
Object
- Object
- Rex::Proto::Ftp::Server
- Defined in:
- lib/rex/proto/ftp/server.rb
Overview
Anonymous-only, in-memory FTP server. Designed for use as a fetch-payload delivery server.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#files ⇒ Object
Returns the value of attribute files.
-
#files_mutex ⇒ Object
Returns the value of attribute files_mutex.
-
#listen_host ⇒ Object
Returns the value of attribute listen_host.
-
#listen_port ⇒ Object
Returns the value of attribute listen_port.
-
#listener ⇒ Object
Returns the value of attribute listener.
-
#monitor_thread ⇒ Object
Returns the value of attribute monitor_thread.
-
#serve_once ⇒ Object
Returns the value of attribute serve_once.
-
#shutting_down ⇒ Object
Returns the value of attribute shutting_down.
Class Method Summary collapse
Instance Method Summary collapse
- #alias ⇒ Object
- #deregister_file(filename) ⇒ Object
-
#initialize(port = 21, host = '0.0.0.0', context = {}) ⇒ Server
constructor
A new instance of Server.
- #register_file(filename, data, serve_once: true) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port = 21, host = '0.0.0.0', context = {}) ⇒ Server
Returns a new instance of Server.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rex/proto/ftp/server.rb', line 24 def initialize(port = 21, host = '0.0.0.0', context = {}) self.listen_port = port self.listen_host = host self.context = context self.files = {} self.serve_once = {} self.files_mutex = Mutex.new self.shutting_down = false self.listener = nil self.monitor_thread = nil end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def context @context end |
#files ⇒ Object
Returns the value of attribute files.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def files @files end |
#files_mutex ⇒ Object
Returns the value of attribute files_mutex.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def files_mutex @files_mutex end |
#listen_host ⇒ Object
Returns the value of attribute listen_host.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def listen_host @listen_host end |
#listen_port ⇒ Object
Returns the value of attribute listen_port.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def listen_port @listen_port end |
#listener ⇒ Object
Returns the value of attribute listener.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def listener @listener end |
#monitor_thread ⇒ Object
Returns the value of attribute monitor_thread.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def monitor_thread @monitor_thread end |
#serve_once ⇒ Object
Returns the value of attribute serve_once.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def serve_once @serve_once end |
#shutting_down ⇒ Object
Returns the value of attribute shutting_down.
75 76 77 |
# File 'lib/rex/proto/ftp/server.rb', line 75 def shutting_down @shutting_down end |
Class Method Details
.hardcore_alias(port, host, *_rest) ⇒ Object
16 17 18 |
# File 'lib/rex/proto/ftp/server.rb', line 16 def self.hardcore_alias(port, host, *_rest) "#{host}-#{port}" end |
Instance Method Details
#alias ⇒ Object
20 21 22 |
# File 'lib/rex/proto/ftp/server.rb', line 20 def alias @alias || 'FTP Server' end |
#deregister_file(filename) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rex/proto/ftp/server.rb', line 43 def deregister_file(filename) files_mutex.synchronize do files.delete(filename) serve_once.delete(filename) end end |
#register_file(filename, data, serve_once: true) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rex/proto/ftp/server.rb', line 36 def register_file(filename, data, serve_once: true) files_mutex.synchronize do files[filename] = data self.serve_once[filename] = serve_once end end |
#start ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rex/proto/ftp/server.rb', line 50 def start self.listener = Rex::Socket::TcpServer.create( 'LocalHost' => listen_host, 'LocalPort' => listen_port, 'Context' => context ) self.monitor_thread = Rex::ThreadFactory.spawn("FTPServerMonitor-#{listen_host}-#{listen_port}", false) do monitor_socket end end |
#stop ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rex/proto/ftp/server.rb', line 61 def stop self.shutting_down = true begin monitor_thread&.kill rescue StandardError nil end begin listener&.close rescue StandardError nil end end |