Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #390 from mozilla/unset_errors
Browse files Browse the repository at this point in the history
Reset error register when falling back to IPv4
  • Loading branch information
Jonathan Claudius authored Jun 15, 2017
2 parents ef3e0d0 + 533d4bf commit fc1c1cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/ssh_scan/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def banner
@server_banner
end

def close()
begin
unless @sock.nil?
@sock.close
end
rescue
@sock = nil
end
return true
end

def connect()
@error = nil

Expand Down
4 changes: 4 additions & 0 deletions lib/ssh_scan/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def error=(error)
@error = error.to_s
end

def unset_error
@error = nil
end

def error?
!@error.nil?
end
Expand Down
9 changes: 7 additions & 2 deletions lib/ssh_scan/scan_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,34 @@ def scan_target(socket, opts)
client = SSHScan::Client.new(
target.resolve_fqdn_as_ipv4.to_s, port, timeout
)
client.connect()
client.connect
result.set_client_attributes(client)
kex_result = client.get_kex_result()
client.close
result.set_kex_result(kex_result) unless kex_result.nil?
result.error = client.error if client.error?
# If it does resolve as IPv6, we're try IPv6
else
client = SSHScan::Client.new(
target.resolve_fqdn_as_ipv6.to_s, port, timeout
)
client.connect()
client.connect
result.set_client_attributes(client)
kex_result = client.get_kex_result()
client.close
result.set_kex_result(kex_result) unless kex_result.nil?
result.error = client.error if client.error?

# If resolves as IPv6, but somehow we get an client error, fall-back to IPv4
if result.error?
result.unset_error
client = SSHScan::Client.new(
target.resolve_fqdn_as_ipv4.to_s, port, timeout
)
client.connect()
result.set_client_attributes(client)
kex_result = client.get_kex_result()
client.close
result.set_kex_result(kex_result) unless kex_result.nil?
result.error = client.error if client.error?
end
Expand All @@ -69,6 +73,7 @@ def scan_target(socket, opts)
client.connect()
result.set_client_attributes(client)
kex_result = client.get_kex_result()
client.close

unless kex_result.nil?
result.set_kex_result(kex_result)
Expand Down

0 comments on commit fc1c1cb

Please sign in to comment.