Class: BetterCap::Options
- Inherits:
-
Object
- Object
- BetterCap::Options
- Defined in:
- lib/bettercap/options/options.rb
Overview
accordingly.
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Core options.
-
#proxies ⇒ Object
readonly
Proxies related options.
-
#servers ⇒ Object
readonly
Misc servers related options.
-
#sniff ⇒ Object
readonly
Sniffing related options.
-
#spoof ⇒ Object
readonly
Spoofing related options.
Class Method Summary collapse
-
.parse! ⇒ Object
Initialize the BetterCap::Context, parse command line arguments and update program state accordingly.
Instance Method Summary collapse
-
#get_redirections(ifconfig) ⇒ Object
Create a list of BetterCap::Firewalls::Redirection objects which are needed given the specified command line arguments.
-
#initialize(iface) ⇒ Options
constructor
Create a BetterCap::Options class instance using the specified network interface.
- #need_gateway? ⇒ Boolean
-
#redir(address, port, to, proto = 'TCP') ⇒ Object
Helper method to create a Firewalls::Redirection object.
-
#redir_single(from, address, port, to, proto = 'TCP') ⇒ Object
Helper method to create a Firewalls::Redirection object for a single address (
from
). -
#starting_message ⇒ Object
Print the starting status message.
- #validate!(ctx) ⇒ Object
Constructor Details
#initialize(iface) ⇒ Options
Create a BetterCap::Options class instance using the specified network interface.
30 31 32 33 34 35 36 |
# File 'lib/bettercap/options/options.rb', line 30 def initialize( iface ) @core = CoreOptions.new iface @spoof = SpoofOptions.new @sniff = SniffOptions.new @proxies = ProxyOptions.new @servers = ServerOptions.new end |
Instance Attribute Details
#core ⇒ Object (readonly)
Core options
19 20 21 |
# File 'lib/bettercap/options/options.rb', line 19 def core @core end |
#proxies ⇒ Object (readonly)
Proxies related options.
25 26 27 |
# File 'lib/bettercap/options/options.rb', line 25 def proxies @proxies end |
#servers ⇒ Object (readonly)
Misc servers related options.
27 28 29 |
# File 'lib/bettercap/options/options.rb', line 27 def servers @servers end |
#sniff ⇒ Object (readonly)
Sniffing related options.
23 24 25 |
# File 'lib/bettercap/options/options.rb', line 23 def sniff @sniff end |
#spoof ⇒ Object (readonly)
Spoofing related options.
21 22 23 |
# File 'lib/bettercap/options/options.rb', line 21 def spoof @spoof end |
Class Method Details
.parse! ⇒ Object
Initialize the BetterCap::Context, parse command line arguments and update program state accordingly. Will rise a BetterCap::Error if errors occurred.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bettercap/options/options.rb', line 41 def self.parse! ctx = Context.get OptionParser.new do |opts| opts.version = BetterCap::VERSION opts. = "Usage: bettercap [options]" ctx..core.parse!( ctx, opts ) ctx..spoof.parse!( ctx, opts ) ctx..sniff.parse!( ctx, opts ) ctx..proxies.parse!( ctx, opts ) ctx..servers.parse!( ctx, opts ) end.parse! # Initialize logging system. Logger.init( ctx ) if ctx..core.check_updates UpdateChecker.check exit end # Validate options. ctx..validate!( ctx ) # Load firewall instance, network interface informations and detect the # gateway address. ctx.update! ctx end |
Instance Method Details
#get_redirections(ifconfig) ⇒ Object
Create a list of BetterCap::Firewalls::Redirection objects which are needed given the specified command line arguments.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/bettercap/options/options.rb', line 96 def get_redirections ifconfig redirections = [] if @servers.dnsd or @proxies.sslstrip? redirections << redir( ifconfig[:ip_saddr], 53, @servers.dnsd_port ) redirections << redir( ifconfig[:ip_saddr], 53, @servers.dnsd_port, 'UDP' ) end if @proxies.proxy @proxies.http_ports.each do |port| redirections << redir( ifconfig[:ip_saddr], port, @proxies.proxy_port ) end end if @proxies.proxy_https @proxies.https_ports.each do |port| redirections << redir( ifconfig[:ip_saddr], port, @proxies.proxy_https_port ) end end if @proxies.tcp_proxy redirections << redir_single( @proxies.tcp_proxy_upstream_address, ifconfig[:ip_saddr], @proxies.tcp_proxy_upstream_port, @proxies.tcp_proxy_port ) end if @proxies.custom_proxy @proxies.http_ports.each do |port| redirections << redir( @proxies.custom_proxy, port, @proxies.custom_proxy_port ) end end if @proxies.custom_https_proxy @proxies.https_ports.each do |port| redirections << redir( @proxies.custom_https_proxy, port, @proxies.custom_https_proxy_port ) end end @proxies.custom_redirections.each do |r| redirections << redir( ifconfig[:ip_saddr], r[:from], r[:to], r[:proto] ) end redirections end |
#need_gateway? ⇒ Boolean
80 81 82 |
# File 'lib/bettercap/options/options.rb', line 80 def need_gateway? ( @core.should_discover_hosts? or @spoof.enabled? ) end |
#redir(address, port, to, proto = 'TCP') ⇒ Object
Helper method to create a Firewalls::Redirection object.
85 86 87 |
# File 'lib/bettercap/options/options.rb', line 85 def redir( address, port, to, proto = 'TCP' ) Firewalls::Redirection.new( @core.iface, proto, nil, port, address, to ) end |
#redir_single(from, address, port, to, proto = 'TCP') ⇒ Object
Helper method to create a Firewalls::Redirection object for a single address ( from
).
90 91 92 |
# File 'lib/bettercap/options/options.rb', line 90 def redir_single( from, address, port, to, proto = 'TCP' ) Firewalls::Redirection.new( @core.iface, proto, from, port, address, to ) end |
#starting_message ⇒ Object
Print the starting status message.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/bettercap/options/options.rb', line 140 def on = '✔'.green off = '✘'.red status = { 'spoofing' => ( @spoof.enabled? ? on : off ), 'discovery' => ( @core.discovery? ? on : off ), 'sniffer' => ( @sniff.enabled? ? on : off ), 'tcp-proxy' => ( @proxies.tcp_proxy ? on : off ), 'http-proxy' => ( @proxies.proxy ? on : off ), 'https-proxy' => ( @proxies.proxy_https ? on : off ), 'sslstrip' => ( @proxies.sslstrip? ? on : off ), 'http-server' => ( @servers.httpd ? on : off ), 'dns-server' => ( @proxies.sslstrip? or @servers.dnsd ? on : off ) } msg = "Starting [ " status.each do |k,v| msg += "#{k}:#{v} " end msg += "] ...\n\n" Logger.info msg Logger.warn "You are running an unstable/beta version of this software, please" \ " update to a stable one if available." if BetterCap::VERSION =~ /[\d\.+]b/ end |
#validate!(ctx) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/bettercap/options/options.rb', line 73 def validate!( ctx ) @core.validate! @proxies.validate!( ctx ) # Print starting message. end |