class Apullo::Fingerprint::SSH
Constants
- DEFAULT_OPTIONS
- DEFAULT_PORTS
Private Instance Methods
_scan(target, port: 22)
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 39 def _scan(target, port: 22) return nil unless target.host engine = SSHScan::ScanEngine.new dest = "#{target.host}:#{port}" result = engine.scan_target(dest, DEFAULT_OPTIONS) result.to_hash end
build_results()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 17 def build_results results = fingerprints results = results.merge(meta: { links: links }) unless results.empty? results end
censys_link()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 67 def censys_link uri = URI("https://censys.io/ipv4") fingerprint = fingerprints.dig("ecdsa-sha2-nistp256", "sha256") || fingerprints.dig("rsa", "sha256") return nil unless fingerprint uri.query = URI.encode_www_form(q: fingerprint.to_s) uri.to_s end
fingerprints()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 23 def fingerprints result = scan keys = result.dig("keys") || {} keys.map do |cipher, data| fingerprints = data.dig("fingerprints") || [] normalized_fingerprints = fingerprints.map do |hash, value| [hash, value.delete(":")] end.to_h [ cipher, normalized_fingerprints ] end.to_h end
links()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 76 def links { shodan: shodan_link, censys: censys_link } end
scan()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 48 def scan [target].product(DEFAULT_PORTS).each do |target, port| result = _scan(target, port: port) keys = result.dig("keys") || {} return result unless keys.empty? end {} end
shodan_link()
click to toggle source
# File lib/apullo/fingerprints/ssh.rb, line 57 def shodan_link uri = URI("https://www.shodan.io/search") fingerprint = fingerprints.dig("rsa", "md5") || fingerprints.dig("ecdsa-sha2-nistp256", "md5") return nil unless fingerprint fingerprint = fingerprint.to_s.chars.each_slice(2).map(&:join).join(":") uri.query = URI.encode_www_form(query: "port:22 #{fingerprint}") uri.to_s end