Class: BetterCap::Proxy::TCP::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/proxy/tcp/module.rb

Overview

Base class for transparent TCP proxy modules, example:

class SampleModule < BetterCap::Proxy::TCP::Module
  def on_data( event )
    event.data = 'aaa'
  end

  def on_response( event )
    event.data = 'bbb'
  end
end

Constant Summary collapse

@@loaded =

Loaded modules.

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dispatch(event_name, event) ⇒ Object

Execute method even_name for each loaded module instance using event as its argument.



65
66
67
68
69
# File 'lib/bettercap/proxy/tcp/module.rb', line 65

def dispatch( event_name, event )
  @@loaded.each do |name,mod|
    mod.send( event_name, event )
  end
end

.inherited(subclass) ⇒ Object

Called when a class inherits this base class.



45
46
47
48
# File 'lib/bettercap/proxy/tcp/module.rb', line 45

def inherited(subclass)
  name = subclass.name.upcase
  @@loaded[name] = subclass
end

.load(file) ⇒ Object

Load file as a proxy module.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bettercap/proxy/tcp/module.rb', line 51

def load( file )
  begin
    require file
  rescue LoadError
    raise BetterCap::Error, "Invalid TCP proxy module specified."
  end

  @@loaded.each do |name,mod|
    @@loaded[name] = mod.new
  end
end

Instance Method Details

#on_data(event) ⇒ Object

This callback is called when the target is sending data to the upstream server. event is an instance of the BetterCap::Proxy::TCP::Event class.



32
# File 'lib/bettercap/proxy/tcp/module.rb', line 32

def on_data( event ); end

#on_finish(event) ⇒ Object

This callback is called when the connection is terminated. event is an instance of the BetterCap::Proxy::TCP::Event class.



38
# File 'lib/bettercap/proxy/tcp/module.rb', line 38

def on_finish( event ); end

#on_response(event) ⇒ Object

This callback is called when the upstream server is sending data to the target. event is an instance of the BetterCap::Proxy::TCP::Event class.



35
# File 'lib/bettercap/proxy/tcp/module.rb', line 35

def on_response( event ); end