|
| 1 | +# frozen_string_literal: true |
| 2 | +# |
| 3 | +# ronin-recon - A micro-framework and tool for performing reconnaissance. |
| 4 | +# |
| 5 | +# Copyright (c) 2023 Hal Brodigan (postmodern.mod3@gmail.com) |
| 6 | +# |
| 7 | +# ronin-recon is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published |
| 9 | +# by the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# ronin-recon is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +require 'ronin/recon/worker' |
| 22 | + |
| 23 | +require 'async/http/internet/instance' |
| 24 | + |
| 25 | +module Ronin |
| 26 | + module Recon |
| 27 | + module Net |
| 28 | + # |
| 29 | + # A recon worker that grabs the SSL/TLS certificate from open ports that |
| 30 | + # use SSL/TLS. |
| 31 | + # |
| 32 | + class CertSh < Worker |
| 33 | + |
| 34 | + register 'net/cert_sh' |
| 35 | + |
| 36 | + accepts Domain |
| 37 | + |
| 38 | + summary 'Returns host from each domains certificate.' |
| 39 | + |
| 40 | + description <<~DESC |
| 41 | + Returns host from each domains certificate. |
| 42 | + DESC |
| 43 | + |
| 44 | + # |
| 45 | + # Returns host from each domains certificate. |
| 46 | + # |
| 47 | + # @param [Values::Domain] domain |
| 48 | + # The domain value to check. |
| 49 | + # |
| 50 | + # @yield [host] |
| 51 | + # If the domain has certificates, then a host value will be |
| 52 | + # yielded. |
| 53 | + # |
| 54 | + # @yieldparam [Values::Host] host |
| 55 | + # The host from certificate. |
| 56 | + # |
| 57 | + def process(host) |
| 58 | + Async do |
| 59 | + internet = Async::HTTP::Internet.instance |
| 60 | + path = "https://crt.sh/?dNSName=#{host}&exclude=expired&output=json" |
| 61 | + |
| 62 | + response = internet.get(path) |
| 63 | + certs = JSON.parse(response.read, symbolize_names: true) |
| 64 | + |
| 65 | + certs.each do |cert| |
| 66 | + if cert[:common_name] |
| 67 | + yield Host.new(name: cert[:common_name]) |
| 68 | + end |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments