Class: BetterCap::CoreOptions
- Inherits:
-
Object
- Object
- BetterCap::CoreOptions
- Defined in:
- lib/bettercap/options/core_options.rb
Instance Attribute Summary collapse
-
#check_updates ⇒ Object
If true, bettercap will check for updates then exit.
-
#debug ⇒ Object
If true will enable debug messages.
-
#discovery ⇒ Object
If false will disable active network discovery, the program will just use the current ARP cache.
-
#gateway ⇒ Object
Gateway IP address.
-
#iface ⇒ Object
Network interface.
-
#ignore ⇒ Object
Comma separated list of ip addresses to ignore.
-
#log_timestamp ⇒ Object
If true the Logger will prepend timestamps to each line.
-
#logfile ⇒ Object
Log file name.
-
#no_target_nbns ⇒ Object
If true, targets NBNS hostname resolution won’t be performed.
-
#packet_throttle ⇒ Object
If different than 0, this time will be used as a delay while sending packets.
-
#silent ⇒ Object
If true will suppress every log message which is not an error or a warning.
-
#targets ⇒ Object
Comma separated list of targets.
-
#use_ipv6 ⇒ Object
If true, IPv6 target endpoints are enabled.
-
#use_mac ⇒ Object
If not nil, the interface MAC address will be changed to this value.
Instance Method Summary collapse
- #check_ip!(v, error) ⇒ Object
-
#discovery? ⇒ Boolean
Return true if active host discovery is enabled, otherwise false.
-
#ignore_ip?(ip) ⇒ Boolean
Return true if the
ipaddress needs to be ignored, otherwise false. -
#initialize(iface) ⇒ CoreOptions
constructor
A new instance of CoreOptions.
- #parse!(ctx, opts) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(iface) ⇒ CoreOptions
Returns a new instance of CoreOptions.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bettercap/options/core_options.rb', line 47 def initialize( iface ) @iface = iface @gateway = nil @targets = nil @logfile = nil = false @silent = false @debug = false @ignore = nil @discovery = true @no_target_nbns = false @packet_throttle = 0.0 @check_updates = false @use_mac = nil @use_ipv6 = false end |
Instance Attribute Details
#check_updates ⇒ Object
If true, bettercap will check for updates then exit.
41 42 43 |
# File 'lib/bettercap/options/core_options.rb', line 41 def check_updates @check_updates end |
#debug ⇒ Object
If true will enable debug messages.
37 38 39 |
# File 'lib/bettercap/options/core_options.rb', line 37 def debug @debug end |
#discovery ⇒ Object
If false will disable active network discovery, the program will just use the current ARP cache.
27 28 29 |
# File 'lib/bettercap/options/core_options.rb', line 27 def discovery @discovery end |
#gateway ⇒ Object
Gateway IP address.
20 21 22 |
# File 'lib/bettercap/options/core_options.rb', line 20 def gateway @gateway end |
#iface ⇒ Object
Network interface.
18 19 20 |
# File 'lib/bettercap/options/core_options.rb', line 18 def iface @iface end |
#ignore ⇒ Object
Comma separated list of ip addresses to ignore.
24 25 26 |
# File 'lib/bettercap/options/core_options.rb', line 24 def ignore @ignore end |
#log_timestamp ⇒ Object
If true the Logger will prepend timestamps to each line.
33 34 35 |
# File 'lib/bettercap/options/core_options.rb', line 33 def end |
#logfile ⇒ Object
Log file name.
31 32 33 |
# File 'lib/bettercap/options/core_options.rb', line 31 def logfile @logfile end |
#no_target_nbns ⇒ Object
If true, targets NBNS hostname resolution won’t be performed.
29 30 31 |
# File 'lib/bettercap/options/core_options.rb', line 29 def no_target_nbns @no_target_nbns end |
#packet_throttle ⇒ Object
If different than 0, this time will be used as a delay while sending packets.
39 40 41 |
# File 'lib/bettercap/options/core_options.rb', line 39 def packet_throttle @packet_throttle end |
#silent ⇒ Object
If true will suppress every log message which is not an error or a warning.
35 36 37 |
# File 'lib/bettercap/options/core_options.rb', line 35 def silent @silent end |
#targets ⇒ Object
Comma separated list of targets.
22 23 24 |
# File 'lib/bettercap/options/core_options.rb', line 22 def targets @targets end |
#use_ipv6 ⇒ Object
If true, IPv6 target endpoints are enabled.
45 46 47 |
# File 'lib/bettercap/options/core_options.rb', line 45 def use_ipv6 @use_ipv6 end |
#use_mac ⇒ Object
If not nil, the interface MAC address will be changed to this value.
43 44 45 |
# File 'lib/bettercap/options/core_options.rb', line 43 def use_mac @use_mac end |
Instance Method Details
#check_ip!(v, error) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/bettercap/options/core_options.rb', line 153 def check_ip!(v,error) if Network::Validator.is_ip?(v) @use_ipv6 = false elsif Network::Validator.is_ipv6?(v) @use_ipv6 = true else raise BetterCap::Error, error end end |
#discovery? ⇒ Boolean
Return true if active host discovery is enabled, otherwise false.
164 165 166 |
# File 'lib/bettercap/options/core_options.rb', line 164 def discovery? ( @discovery and @targets.nil? ) end |
#ignore_ip?(ip) ⇒ Boolean
Return true if the ip address needs to be ignored, otherwise false.
223 224 225 |
# File 'lib/bettercap/options/core_options.rb', line 223 def ignore_ip?(ip) !@ignore.nil? and @ignore.include?(ip) end |
#parse!(ctx, opts) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 138 139 140 141 142 143 144 145 146 |
# File 'lib/bettercap/options/core_options.rb', line 64 def parse!( ctx, opts ) opts.separator "" opts.separator "MAIN:".bold opts.separator "" opts.on( '-I', '--interface IFACE', 'Network interface name - default: ' + @iface.to_s.yellow ) do |v| @iface = v end opts.on( '--use-mac ADDRESS', 'Change the interface MAC address to this value before performing the attack.' ) do |v| @use_mac = v raise BetterCap::Error, "Invalid MAC address specified." unless Network::Validator.is_mac?(@use_mac) end opts.on( '--random-mac', 'Change the interface MAC address to a random one before performing the attack.' ) do |v| @use_mac = [format('%0.2x', rand(256) & ~1), (1..5).map { format('%0.2x', rand(256)) }].join(':') end opts.on( '-G', '--gateway ADDRESS', 'Manually specify the gateway address, if not specified the current gateway will be retrieved and used. ' ) do |v| @gateway = v check_ip!( v, "The specified gateway '#{v}' is not a valid IPv4 or IPv6 address." ) end opts.on( '-T', '--target ADDRESS1,ADDRESS2', 'Target IP addresses, if not specified the whole subnet will be targeted.' ) do |v| self.targets = v end opts.on( '--ignore ADDRESS1,ADDRESS2', 'Ignore these addresses if found while searching for targets.' ) do |v| self.ignore = v end opts.on( '--no-discovery', "Do not actively search for hosts, just use the current ARP cache, default to #{'false'.yellow}." ) do @discovery = false end opts.on( '--no-target-nbns', 'Disable target NBNS hostname resolution.' ) do @no_target_nbns = true end opts.on( '--packet-throttle NUMBER', 'Number of seconds ( can be a decimal number ) to wait between each packet to be sent.' ) do |v| @packet_throttle = v.to_f raise BetterCap::Error, "Invalid packet throttle value specified." if @packet_throttle <= 0.0 end opts.on( '--check-updates', 'Will check if any update is available and then exit.' ) do @check_updates = true end opts.on( '-R', '--rainbows', 'Rainbow output, because that\'s a really helpful thing to have (requires the "lolize" gem to be installed).' ) do begin require 'lolize/auto' rescue LoadError raise BetterCap::Error, "GEM lolize not found, please install it in order to use this option" end end opts.on( '-h', '--help', 'Display the available options.') do puts opts puts "\nFor examples & docs please visit " + "https://bettercap.org/".bold exit end opts.separator "" opts.separator "LOGGING:".bold opts.separator "" opts.on( '-O', '--log LOG_FILE', 'Log all messages into a file, if not specified the log messages will be only print into the shell.' ) do |v| @logfile = v end opts.on( '--log-timestamp', 'Enable logging with timestamps for each line, disabled by default.' ) do = true end opts.on( '-D', '--debug', 'Enable debug logging.' ) do @debug = true end opts.on( '--silent', "Suppress every message which is not an error or a warning, default to #{'false'.yellow}." ) do @silent = true end end |
#validate! ⇒ Object
148 149 150 151 |
# File 'lib/bettercap/options/core_options.rb', line 148 def validate! raise BetterCap::Error, 'This software must run as root.' unless Process.uid == 0 raise BetterCap::Error, 'No default interface found, please specify one with the -I argument.' if @iface.nil? end |