From c7172b7cf6ffc3c5cc08df09b428bc10697219ac Mon Sep 17 00:00:00 2001 From: audiblelblink Date: Wed, 8 Apr 2020 17:33:44 -0400 Subject: [PATCH 01/23] adds ability to specify bind address --- lib/extend-http.rb | 6 +++--- lib/target.rb | 2 +- whatweb | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index b85f5a49c..ae5bb6bdf 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -20,11 +20,11 @@ class ExtendedHTTP < Net::HTTP #:nodoc: # Creates a new Net::HTTP object for the specified server address, # without opening the TCP connection or initializing the HTTP session. # The +address+ should be a DNS hostname or IP address. - def initialize(address, port = nil) + def initialize(address, port = nil, local_host = nil, local_port = nil) @address = address @port = (port || HTTP.default_port) - @local_host = nil - @local_port = nil + @local_host = local_host + @local_port = local_port @curr_http_version = HTTPVersion @keep_alive_timeout = 2 @last_communicated = nil diff --git a/lib/target.rb b/lib/target.rb index efce08599..cf92ba0f9 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -266,7 +266,7 @@ def open_url(options) if $USE_PROXY == true http = ExtendedHTTP::Proxy($PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS).new(@uri.host, @uri.port) else - http = ExtendedHTTP.new(@uri.host, @uri.port) + http = ExtendedHTTP.new(@uri.host, @uri.port, $local_host, $local_port) end # set timeouts diff --git a/whatweb b/whatweb index 667fa937e..a19079339 100755 --- a/whatweb +++ b/whatweb @@ -82,6 +82,7 @@ HTTP OPTIONS: \t\t\t\t`never', `http-only', `meta-only', `same-site', \t\t\t\tor `always'. Default: #{$FOLLOW_REDIRECT}. --max-redirects=NUM\t\tMaximum number of redirects. Default: 10. + --bind=IP, -b IP\t\tIP address of the interface on which to bind AUTHENTICATION: --user, -u=\tHTTP basic authentication. @@ -324,6 +325,7 @@ opts = GetoptLong.new( ['-U', '--user-agent', GetoptLong::REQUIRED_ARGUMENT], ['-a', '--aggression', GetoptLong::REQUIRED_ARGUMENT], ['-t', '--max-threads', GetoptLong::REQUIRED_ARGUMENT], + ['-b', '--bind', GetoptLong::REQUIRED_ARGUMENT], ['--follow-redirect', GetoptLong::REQUIRED_ARGUMENT], ['--max-redirects', GetoptLong::REQUIRED_ARGUMENT], ['--proxy', GetoptLong::REQUIRED_ARGUMENT], @@ -356,6 +358,9 @@ begin exit when '-p', '--plugins' plugin_selection = arg + when '-b', '--bind' + $local_host = arg + $local_port = 61000 when '-I', '--info-plugins' PluginSupport.load_plugins PluginSupport.plugin_info(arg.split(',')) @@ -636,3 +641,4 @@ logging_list.each(&:close) Plugin.shutdown_all # pp $PLUGIN_TIMES.sort_by {|x,y|y } + From 9622462d54ffa4550e9d7771afc95a85d06e6947 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 22:32:16 +1000 Subject: [PATCH 02/23] Updated Usage for bind interface --- whatweb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/whatweb b/whatweb index a19079339..c691ebc3d 100755 --- a/whatweb +++ b/whatweb @@ -82,7 +82,6 @@ HTTP OPTIONS: \t\t\t\t`never', `http-only', `meta-only', `same-site', \t\t\t\tor `always'. Default: #{$FOLLOW_REDIRECT}. --max-redirects=NUM\t\tMaximum number of redirects. Default: 10. - --bind=IP, -b IP\t\tIP address of the interface on which to bind AUTHENTICATION: --user, -u=\tHTTP basic authentication. @@ -156,6 +155,11 @@ PERFORMANCE & STABILITY: --wait=SECONDS\t\tWait SECONDS between connections. \t\t\t\tThis is useful when using a single thread. +NETWORK INTERFACE: + --interface=INTERFACE\t\tUse specified network interface. + --source-port=PORT\t\tSpecify source TCP port to use. + --source-addr=ADDRESS\t\tSpecify source IP address to use. + HELP & MISCELLANEOUS: --short-help\t\t\tShort usage help. --help, -h\t\t\tComplete usage help. From aa3e5ce4b4607d0d125bc92f148a56b8cc04d9d6 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 22:41:47 +1000 Subject: [PATCH 03/23] Add requirement for socket library --- lib/whatweb.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/whatweb.rb b/lib/whatweb.rb index ced48a2e5..ac1d69a4a 100644 --- a/lib/whatweb.rb +++ b/lib/whatweb.rb @@ -30,6 +30,7 @@ require 'open-uri' require 'digest/md5' require 'openssl' # required for Ruby version ~> 2.4 +require 'socket' require 'pp' From 2f0fdcee8ec0629a21b3827f3c6e99feffe5ed24 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 23:06:33 +1000 Subject: [PATCH 04/23] Add --interface, --source-port, --source-address to optargs --- whatweb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/whatweb b/whatweb index c691ebc3d..d87d0e649 100755 --- a/whatweb +++ b/whatweb @@ -329,7 +329,9 @@ opts = GetoptLong.new( ['-U', '--user-agent', GetoptLong::REQUIRED_ARGUMENT], ['-a', '--aggression', GetoptLong::REQUIRED_ARGUMENT], ['-t', '--max-threads', GetoptLong::REQUIRED_ARGUMENT], - ['-b', '--bind', GetoptLong::REQUIRED_ARGUMENT], + ['--interface', GetoptLong::REQUIRED_ARGUMENT], + ['--source-port', GetoptLong::REQUIRED_ARGUMENT], + ['--source-address', GetoptLong::REQUIRED_ARGUMENT], ['--follow-redirect', GetoptLong::REQUIRED_ARGUMENT], ['--max-redirects', GetoptLong::REQUIRED_ARGUMENT], ['--proxy', GetoptLong::REQUIRED_ARGUMENT], From 2f88cc2c076b572da1215c83b3d6a5b2a79f63d5 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 23:07:11 +1000 Subject: [PATCH 05/23] Add opt handling for --interface, --source-port, --source-address --- whatweb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/whatweb b/whatweb index d87d0e649..95af99423 100755 --- a/whatweb +++ b/whatweb @@ -364,9 +364,21 @@ begin exit when '-p', '--plugins' plugin_selection = arg - when '-b', '--bind' + + when '--interface' + # TO DO + $interface = arg + + when '--source-port' + $local_port = arg.to_i + raise "Source port must be betwen 0 and 65535\n" unless (0..65535).include? $local_port + + when '--source-address' $local_host = arg - $local_port = 61000 + valid_ip_addresses = Socket.ip_address_list.map { |x| x.ip_address.split("%").first }.uniq + raise "Valid IP address must be specified\n" unless valid_ip_addresses.include? $local_host + $local_port = 61000 unless $local_port + when '-I', '--info-plugins' PluginSupport.load_plugins PluginSupport.plugin_info(arg.split(',')) From 8d8c408cfc5988fc95897a75884f33f310201346 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 23:28:53 +1000 Subject: [PATCH 06/23] network interface validation, and auto selection of IP address --- whatweb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/whatweb b/whatweb index 95af99423..c45df1091 100755 --- a/whatweb +++ b/whatweb @@ -366,8 +366,25 @@ begin plugin_selection = arg when '--interface' - # TO DO - $interface = arg + $interface = arg.downcase + valid_interfaces = Socket.getifaddrs.map(&:name).uniq + raise "Valid network interface must be specified\n" unless valid_interfaces.include? $interface + + + number_of_ips_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? }.compact.size + + # NOT WORKING YET + case number_of_ips_on_interface + when 0 + raise "No IP addresses to use on $interface" + when 1 + # ok use it + Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? }.map(&:addr) + when > 1 + # select IPv4 + Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? and x.addr.ipv4? }.map(&:addr) + end + when '--source-port' $local_port = arg.to_i From 17479000114282f83957cc800ba0b06e6b682c4d Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 23:29:34 +1000 Subject: [PATCH 07/23] Updated CHA update changelog and enable debugging --- CHANGELOG.md | 2 ++ lib/whatweb.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d87b56d42..ef81eaa55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Version 0.5.3 - ## MISC * #314 Makefile now allows supports the PREFIX environment variable. Thanks @bfontaine +## FEATURES +* #303 Added ability to select network interface. Thanks @audibleblink. Version 0.5.2 - June 9, 2020 diff --git a/lib/whatweb.rb b/lib/whatweb.rb index ac1d69a4a..810d532cc 100644 --- a/lib/whatweb.rb +++ b/lib/whatweb.rb @@ -55,7 +55,7 @@ Dir["#{File.expand_path(File.dirname(__FILE__))}/logging/*.rb"].each {|file| require file } # Output options -$WWDEBUG = false # raise exceptions in plugins, etc +$WWDEBUG = true # raise exceptions in plugins, etc $verbose = 0 # $VERBOSE is reserved in ruby $use_colour = 'auto' $QUIET = false From a7035da71e98e7563c6aeccaa79734c514f08ab9 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Tue, 4 Aug 2020 23:32:36 +1000 Subject: [PATCH 08/23] when --interface --- whatweb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/whatweb b/whatweb index c45df1091..3c9b654a0 100755 --- a/whatweb +++ b/whatweb @@ -380,9 +380,11 @@ begin when 1 # ok use it Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? }.map(&:addr) - when > 1 + when 2 # select IPv4 Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? and x.addr.ipv4? }.map(&:addr) + when > 2 + raise "Too many IP addreses for this inteface.\n" end From 8d67fce3b6b9e48301cae4e76dc13ec0ff183960 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 22:12:19 +1000 Subject: [PATCH 09/23] finding the IP address for any given interface. not working. --- whatweb | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/whatweb b/whatweb index 3c9b654a0..d7bb3fe60 100755 --- a/whatweb +++ b/whatweb @@ -367,32 +367,46 @@ begin when '--interface' $interface = arg.downcase + valid_interfaces = Socket.getifaddrs.map(&:name).uniq raise "Valid network interface must be specified\n" unless valid_interfaces.include? $interface + pp "Valid interfaces: #{valid_interfaces}" if $verbose > 2 + + # unless the user has already selected this manually + pp $local_host + unless $local_host + pp "in" + + # choose the IP address to use + number_of_ips_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? }.compact.size + number_of_ipv4s_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv4? }.compact.size + number_of_ipv6s_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv6? }.compact.size + + tmp_addr = if number_of_ips_on_interface == 0 + raise "No IP addresses were found for #{$interface} interface." + elsif number_of_ipv4s_on_interface > 0 + Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv4? }.map(&:addr).first.ip_address - number_of_ips_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? }.compact.size - - # NOT WORKING YET - case number_of_ips_on_interface - when 0 - raise "No IP addresses to use on $interface" - when 1 - # ok use it - Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? }.map(&:addr) - when 2 - # select IPv4 - Socket.getifaddrs.select { |x| x.name == "en0" and x.addr.ip? and x.addr.ipv4? }.map(&:addr) - when > 2 - raise "Too many IP addreses for this inteface.\n" + elsif number_of_ipv6s_on_interface > 0 + Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv6? }.map(&:addr).first.ip_address.split("%").first + + elsif number_of_ipv4s_on_interface == 0 and number_of_ipv6s_on_interface == 0 + raise "No IPv4 or IPv6 addresses were found for #{$interface} interface." + end + + $local_host = tmp_addr end + pp "IP address: #{$local_host}" if $verbose > 2 when '--source-port' $local_port = arg.to_i raise "Source port must be betwen 0 and 65535\n" unless (0..65535).include? $local_port when '--source-address' + raise "Specify source address or the interface, but not both." if $local_host + $local_host = arg valid_ip_addresses = Socket.ip_address_list.map { |x| x.ip_address.split("%").first }.uniq raise "Valid IP address must be specified\n" unless valid_ip_addresses.include? $local_host From ca6916e0f47fc10bc0a5c09b0f0869d6580fe3c5 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 22:39:43 +1000 Subject: [PATCH 10/23] Adding debugging output --- lib/extend-http.rb | 3 +++ lib/target.rb | 1 + lib/whatweb.rb | 3 +++ whatweb | 5 ++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index ae5bb6bdf..f8c23f84c 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -21,6 +21,9 @@ class ExtendedHTTP < Net::HTTP #:nodoc: # without opening the TCP connection or initializing the HTTP session. # The +address+ should be a DNS hostname or IP address. def initialize(address, port = nil, local_host = nil, local_port = nil) + + puts "hi from ExtendedHTTP.initialize address: #{address}, port: #{port}, local_host: #{local_host}, local_port: #{local_port}" + @address = address @port = (port || HTTP.default_port) @local_host = local_host diff --git a/lib/target.rb b/lib/target.rb index cf92ba0f9..7a561287a 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -266,6 +266,7 @@ def open_url(options) if $USE_PROXY == true http = ExtendedHTTP::Proxy($PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS).new(@uri.host, @uri.port) else + puts "hi from open_url $local_host: #{$local_host} and $local_port: #{$local_port}" http = ExtendedHTTP.new(@uri.host, @uri.port, $local_host, $local_port) end diff --git a/lib/whatweb.rb b/lib/whatweb.rb index 810d532cc..a731a714c 100644 --- a/lib/whatweb.rb +++ b/lib/whatweb.rb @@ -79,6 +79,9 @@ $BASIC_AUTH_USER = nil $BASIC_AUTH_PASS = nil +#$local_host = nil +#$local_post = nil + # Ruby Version Compatability if Gem::Version.new(RUBY_VERSION) < Gem::Version.new(2.0) raise('Unsupported version of Ruby. WhatWeb requires Ruby 2.0 or later.') diff --git a/whatweb b/whatweb index d7bb3fe60..5946d7761 100755 --- a/whatweb +++ b/whatweb @@ -396,8 +396,8 @@ begin end $local_host = tmp_addr + $local_port = 61000 unless $local_port end - pp "IP address: #{$local_host}" if $verbose > 2 when '--source-port' @@ -603,6 +603,9 @@ rescue StandardError, GetoptLong::Error => err exit end +# check interfaces +pp "local_host: #{$local_host}, local_port: #{$local_port}" + # sanity check # Disable colours in Windows environments when set to auto if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ $use_colour = false unless $use_colour == 'always' From 4b9cf0fd7cf2d17c795671e9299a516c8350442d Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 23:16:49 +1000 Subject: [PATCH 11/23] More debugging, set variables to nil --- lib/extend-http.rb | 6 +++++- lib/whatweb.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index f8c23f84c..282282a84 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -22,12 +22,16 @@ class ExtendedHTTP < Net::HTTP #:nodoc: # The +address+ should be a DNS hostname or IP address. def initialize(address, port = nil, local_host = nil, local_port = nil) - puts "hi from ExtendedHTTP.initialize address: #{address}, port: #{port}, local_host: #{local_host}, local_port: #{local_port}" + puts "hi from ExtendedHTTP.initialize address: #{address}, port: #{port}, local_host: #{local_host.inspect}, local_port: #{local_port.inspect}" + # pry.binding @address = address @port = (port || HTTP.default_port) @local_host = local_host @local_port = local_port + + puts "hi again from ExtendedHTTP.initialize @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" + @curr_http_version = HTTPVersion @keep_alive_timeout = 2 @last_communicated = nil diff --git a/lib/whatweb.rb b/lib/whatweb.rb index a731a714c..9d81f4aca 100644 --- a/lib/whatweb.rb +++ b/lib/whatweb.rb @@ -79,8 +79,8 @@ $BASIC_AUTH_USER = nil $BASIC_AUTH_PASS = nil -#$local_host = nil -#$local_post = nil +$local_host = nil +$local_post = nil # Ruby Version Compatability if Gem::Version.new(RUBY_VERSION) < Gem::Version.new(2.0) From 70234d71d92d650f05319adc85b40f9268e0bb36 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 23:34:27 +1000 Subject: [PATCH 12/23] Changed initialize arguments --- lib/extend-http.rb | 9 +++------ lib/target.rb | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index 282282a84..c02ad81f0 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -20,15 +20,12 @@ class ExtendedHTTP < Net::HTTP #:nodoc: # Creates a new Net::HTTP object for the specified server address, # without opening the TCP connection or initializing the HTTP session. # The +address+ should be a DNS hostname or IP address. - def initialize(address, port = nil, local_host = nil, local_port = nil) + def initialize(address, port = nil) - puts "hi from ExtendedHTTP.initialize address: #{address}, port: #{port}, local_host: #{local_host.inspect}, local_port: #{local_port.inspect}" - - # pry.binding @address = address @port = (port || HTTP.default_port) - @local_host = local_host - @local_port = local_port + @local_host = $local_host + @local_port = $local_port puts "hi again from ExtendedHTTP.initialize @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" diff --git a/lib/target.rb b/lib/target.rb index 7a561287a..03cee2d23 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -200,6 +200,7 @@ def open if is_file? open_file else + puts "hi from Target.open " open_url(@http_options) end From dadf943d2bb8e067cc26cf081faa1c1fd03bed8c Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 23:44:03 +1000 Subject: [PATCH 13/23] move @local_host and @local_port into connect --- lib/extend-http.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index c02ad81f0..d47cfe9fa 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -24,10 +24,6 @@ def initialize(address, port = nil) @address = address @port = (port || HTTP.default_port) - @local_host = $local_host - @local_port = $local_port - - puts "hi again from ExtendedHTTP.initialize @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" @curr_http_version = HTTPVersion @keep_alive_timeout = 2 @@ -76,6 +72,12 @@ def connect conn_port = port end + @local_host = $local_host + @local_port = $local_port + + puts "hi again from ExtendedHTTP.connect @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" + + D "opening connection to #{conn_address}:#{conn_port}..." s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do TCPSocket.open(conn_address, conn_port, @local_host, @local_port) From 7cba3f4b28b54d30e2d6e81a8e69ad1acc61cfd9 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 23:52:19 +1000 Subject: [PATCH 14/23] raise better error --- lib/extend-http.rb | 3 ++- lib/target.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index d47cfe9fa..daeb13f63 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -77,10 +77,11 @@ def connect puts "hi again from ExtendedHTTP.connect @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" - D "opening connection to #{conn_address}:#{conn_port}..." s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do TCPSocket.open(conn_address, conn_port, @local_host, @local_port) + # TCPSocket.open(conn_address, conn_port, '127.0.0.1', '11111') + end s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) D 'opened' diff --git a/lib/target.rb b/lib/target.rb index 03cee2d23..62c089780 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -319,8 +319,8 @@ def open_url(options) puts @uri.to_s + " [#{status}]" if $verbose > 1 rescue StandardError => err + pp err raise err - end end From 8f65416137a8dea5b49348283c817f089ed486e5 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Wed, 5 Aug 2020 23:56:32 +1000 Subject: [PATCH 15/23] move setting local_host and local_port after creating ExtendedHTTP object in Target.open_url --- lib/extend-http.rb | 4 ++-- lib/target.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index daeb13f63..6c6c434ba 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -72,8 +72,8 @@ def connect conn_port = port end - @local_host = $local_host - @local_port = $local_port +# @local_host = $local_host +# @local_port = $local_port puts "hi again from ExtendedHTTP.connect @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" diff --git a/lib/target.rb b/lib/target.rb index 62c089780..dd3990563 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -268,7 +268,9 @@ def open_url(options) http = ExtendedHTTP::Proxy($PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS).new(@uri.host, @uri.port) else puts "hi from open_url $local_host: #{$local_host} and $local_port: #{$local_port}" - http = ExtendedHTTP.new(@uri.host, @uri.port, $local_host, $local_port) + http = ExtendedHTTP.new(@uri.host, @uri.port) + http.local_host = $local_host + http.local_port = $local_port end # set timeouts From e969865899a239a626f096865bb52f0da776095e Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 16:58:52 +1000 Subject: [PATCH 16/23] Improve debugging output --- whatweb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/whatweb b/whatweb index 5946d7761..d05d96077 100755 --- a/whatweb +++ b/whatweb @@ -370,12 +370,10 @@ begin valid_interfaces = Socket.getifaddrs.map(&:name).uniq raise "Valid network interface must be specified\n" unless valid_interfaces.include? $interface - pp "Valid interfaces: #{valid_interfaces}" if $verbose > 2 + pp "Found valid interfaces: #{valid_interfaces}" if $verbose > 2 # unless the user has already selected this manually - pp $local_host unless $local_host - pp "in" # choose the IP address to use number_of_ips_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? }.compact.size @@ -395,10 +393,11 @@ begin raise "No IPv4 or IPv6 addresses were found for #{$interface} interface." end - $local_host = tmp_addr $local_port = 61000 unless $local_port + pp "IP address auto-selected from interface: #{$local_host}" if $verbose > 2 + else + pp "IP address already selected by user: #{$local_host}" if $verbose > 2 end - pp "IP address: #{$local_host}" if $verbose > 2 when '--source-port' $local_port = arg.to_i From ab0a05f1f0d5ce5e71d77c0bf64e07bf2d7bfccd Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 16:59:06 +1000 Subject: [PATCH 17/23] Lose tmpaddr variable, and just set local_host directly --- whatweb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whatweb b/whatweb index d05d96077..6a7bbbe70 100755 --- a/whatweb +++ b/whatweb @@ -380,7 +380,7 @@ begin number_of_ipv4s_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv4? }.compact.size number_of_ipv6s_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv6? }.compact.size - tmp_addr = if number_of_ips_on_interface == 0 + $local_host = if number_of_ips_on_interface == 0 raise "No IP addresses were found for #{$interface} interface." elsif number_of_ipv4s_on_interface > 0 From 4d69f7b7fad551fc36eb980170a92bc71bb9360d Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 21:24:49 +1000 Subject: [PATCH 18/23] Improve error messages for --interface --- whatweb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/whatweb b/whatweb index 6a7bbbe70..5479b802a 100755 --- a/whatweb +++ b/whatweb @@ -369,7 +369,7 @@ begin $interface = arg.downcase valid_interfaces = Socket.getifaddrs.map(&:name).uniq - raise "Valid network interface must be specified\n" unless valid_interfaces.include? $interface + raise "Network interface #{$interface} is not valid.\n" unless valid_interfaces.include? $interface pp "Found valid interfaces: #{valid_interfaces}" if $verbose > 2 # unless the user has already selected this manually @@ -381,7 +381,7 @@ begin number_of_ipv6s_on_interface = Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv6? }.compact.size $local_host = if number_of_ips_on_interface == 0 - raise "No IP addresses were found for #{$interface} interface." + raise "No IP addresses were found for the #{$interface} interface." elsif number_of_ipv4s_on_interface > 0 Socket.getifaddrs.select { |x| x.name == $interface and x.addr.ip? and x.addr.ipv4? }.map(&:addr).first.ip_address From 6c57d4496dd9a805b8bc7f6d6396a148571c56eb Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 21:25:17 +1000 Subject: [PATCH 19/23] Remove hard-coded local_port of 61000 --- whatweb | 1 - 1 file changed, 1 deletion(-) diff --git a/whatweb b/whatweb index 5479b802a..9873a32f0 100755 --- a/whatweb +++ b/whatweb @@ -393,7 +393,6 @@ begin raise "No IPv4 or IPv6 addresses were found for #{$interface} interface." end - $local_port = 61000 unless $local_port pp "IP address auto-selected from interface: #{$local_host}" if $verbose > 2 else pp "IP address already selected by user: #{$local_host}" if $verbose > 2 From baf8e90ee92a52411f7a542089b58e95514dc1e6 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 21:30:49 +1000 Subject: [PATCH 20/23] remove debugging output --- lib/extend-http.rb | 5 ----- lib/target.rb | 2 -- whatweb | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/extend-http.rb b/lib/extend-http.rb index 6c6c434ba..7fd7acbc5 100644 --- a/lib/extend-http.rb +++ b/lib/extend-http.rb @@ -72,11 +72,6 @@ def connect conn_port = port end -# @local_host = $local_host -# @local_port = $local_port - - puts "hi again from ExtendedHTTP.connect @local_host: #{@local_host.inspect}, @local_port: #{@local_port.inspect}" - D "opening connection to #{conn_address}:#{conn_port}..." s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do TCPSocket.open(conn_address, conn_port, @local_host, @local_port) diff --git a/lib/target.rb b/lib/target.rb index dd3990563..cd6aab2b2 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -200,7 +200,6 @@ def open if is_file? open_file else - puts "hi from Target.open " open_url(@http_options) end @@ -267,7 +266,6 @@ def open_url(options) if $USE_PROXY == true http = ExtendedHTTP::Proxy($PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS).new(@uri.host, @uri.port) else - puts "hi from open_url $local_host: #{$local_host} and $local_port: #{$local_port}" http = ExtendedHTTP.new(@uri.host, @uri.port) http.local_host = $local_host http.local_port = $local_port diff --git a/whatweb b/whatweb index 9873a32f0..c9fb5a069 100755 --- a/whatweb +++ b/whatweb @@ -602,7 +602,7 @@ rescue StandardError, GetoptLong::Error => err end # check interfaces -pp "local_host: #{$local_host}, local_port: #{$local_port}" +pp "local_host: #{$local_host}, local_port: #{$local_port}" if $verbose > 2 # sanity check # Disable colours in Windows environments when set to auto if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ From ea597dc1578a04571e8c94ce77cb852e5e63683c Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 21:31:12 +1000 Subject: [PATCH 21/23] Only pass local_port if it's set --- lib/target.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/target.rb b/lib/target.rb index cd6aab2b2..77e9e09b5 100644 --- a/lib/target.rb +++ b/lib/target.rb @@ -268,7 +268,7 @@ def open_url(options) else http = ExtendedHTTP.new(@uri.host, @uri.port) http.local_host = $local_host - http.local_port = $local_port + http.local_port = $local_port if $local_port end # set timeouts From e707c532dddcea5d71bd552cea528813b66a8ace Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 21:31:21 +1000 Subject: [PATCH 22/23] Remove default of local port 61000 --- whatweb | 1 - 1 file changed, 1 deletion(-) diff --git a/whatweb b/whatweb index c9fb5a069..c7527612d 100755 --- a/whatweb +++ b/whatweb @@ -408,7 +408,6 @@ begin $local_host = arg valid_ip_addresses = Socket.ip_address_list.map { |x| x.ip_address.split("%").first }.uniq raise "Valid IP address must be specified\n" unless valid_ip_addresses.include? $local_host - $local_port = 61000 unless $local_port when '-I', '--info-plugins' PluginSupport.load_plugins From 1079c55dcb20dde3451faf56706e7ef8a4d490d3 Mon Sep 17 00:00:00 2001 From: urbanadventurer Date: Thu, 6 Aug 2020 22:59:42 +1000 Subject: [PATCH 23/23] Show interface in debug messages --- whatweb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whatweb b/whatweb index c7527612d..73974d432 100755 --- a/whatweb +++ b/whatweb @@ -601,7 +601,7 @@ rescue StandardError, GetoptLong::Error => err end # check interfaces -pp "local_host: #{$local_host}, local_port: #{$local_port}" if $verbose > 2 +pp "interface: $interface, local_host: #{$local_host}, local_port: #{$local_port}" if $verbose > 2 # sanity check # Disable colours in Windows environments when set to auto if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/