From 777b7f25ece1b1c01a69a635ce6c9331361af916 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Mon, 27 Feb 2017 08:51:51 +0100 Subject: [PATCH] Removed IPv6 specific options, use of IPv6 is automatically detected now. --- lib/bettercap/options/core_options.rb | 36 ++++++++++++++++---------- lib/bettercap/options/spoof_options.rb | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/bettercap/options/core_options.rb b/lib/bettercap/options/core_options.rb index dea28dba..f9e63e98 100644 --- a/lib/bettercap/options/core_options.rb +++ b/lib/bettercap/options/core_options.rb @@ -81,23 +81,13 @@ def parse!( ctx, opts ) 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 - raise BetterCap::Error, "The specified gateway '#{v}' is not a valid IPv4 address." unless Network::Validator.is_ip?(v) - end - - opts.on( '--gateway6 ADDRESS', 'Manually specify the IPv6 gateway address, if not specified the current gateway will be retrieved and used. ' ) do |v| - @gateway = v - raise BetterCap::Error, "The specified gateway '#{v}' is not a valid IPv6 address." unless Network::Validator.is_ipv6?(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( '-t', '--target6 ADDRESS1,ADDRESS2', 'Target IPv6 addresses.' ) do |v| - @use_ipv6 = true - self.targets = v - end - opts.on( '--ignore ADDRESS1,ADDRESS2', 'Ignore these addresses if found while searching for targets.' ) do |v| self.ignore = v end @@ -160,6 +150,16 @@ def validate! raise BetterCap::Error, 'No default interface found, please specify one with the -I argument.' if @iface.nil? end + 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 + # Return true if active host discovery is enabled, otherwise false. def discovery? ( @discovery and @targets.nil? ) @@ -171,8 +171,12 @@ def targets=(value) @targets = [] value.split(",").each do |t| - if Network::Validator.is_ip?(t) or Network::Validator.is_mac?(t) or Network::Validator.is_ipv6?(t) + if Network::Validator.is_ip?(t) or Network::Validator.is_mac?(t) + @targets << Network::Target.new(t) + + elsif Network::Validator.is_ipv6?(t) @targets << Network::Target.new(t) + @use_ipv6 = true elsif Network::Validator.is_range?(t) Network::Validator.each_in_range( t ) do |address| @@ -195,7 +199,7 @@ def targets=(value) # or more invalid IP addresses are specified. def ignore=(value) @ignore = value.split(",") - valid = @ignore.select { |target| Network::Validator.is_ip?(target) } + valid = @ignore.select { |target| ( Network::Validator.is_ip?(target) or Network::Validator.is_ipv6?(target) ) } raise BetterCap::Error, "Invalid ignore addresses specified." if valid.empty? @@ -204,6 +208,12 @@ def ignore=(value) Logger.warn "Not a valid address: #{target}" end + valid.each do |target| + if Network::Validator.is_ipv6?(target) + @use_ipv6 = true + end + end + @ignore = valid Logger.warn "Ignoring #{valid.join(", ")} ." diff --git a/lib/bettercap/options/spoof_options.rb b/lib/bettercap/options/spoof_options.rb index d9253660..493f14e2 100644 --- a/lib/bettercap/options/spoof_options.rb +++ b/lib/bettercap/options/spoof_options.rb @@ -33,7 +33,7 @@ def parse!( ctx, opts ) opts.separator "SPOOFING:".bold opts.separator "" - opts.on( '-S', '--spoofer NAME', "Spoofer module to use, available: #{Spoofers::Base.available.map{|x| x.yellow }.join(', ')} - default: #{@spoofer.yellow}." ) do |v| + opts.on( '-S', '--spoofer NAME', "Spoofer module to use, available: #{Spoofers::Base.available.map{|x| x.yellow }.join(', ')} - default: #{@spoofer.yellow} for IPv4 and #{'NDP'.yellow} for IPv6." ) do |v| @spoofer = v end