From 97b1171d1231e8917cd6e93d27ba07922725eb0a Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Tue, 24 Oct 2023 14:59:05 +0200 Subject: [PATCH 1/3] move `cert_enum` and `cert_grab` to `SSL` namespace --- lib/ronin/recon/builtin/{net => ssl}/cert_enum.rb | 4 ++-- lib/ronin/recon/builtin/{net => ssl}/cert_grab.rb | 4 ++-- spec/builtin/{net => ssl}/cert_enum_spec.rb | 4 ++-- spec/builtin/{net => ssl}/cert_grab_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename lib/ronin/recon/builtin/{net => ssl}/cert_enum.rb (98%) rename lib/ronin/recon/builtin/{net => ssl}/cert_grab.rb (97%) rename spec/builtin/{net => ssl}/cert_enum_spec.rb (95%) rename spec/builtin/{net => ssl}/cert_grab_spec.rb (93%) diff --git a/lib/ronin/recon/builtin/net/cert_enum.rb b/lib/ronin/recon/builtin/ssl/cert_enum.rb similarity index 98% rename from lib/ronin/recon/builtin/net/cert_enum.rb rename to lib/ronin/recon/builtin/ssl/cert_enum.rb index 7177e6e..36c45ff 100644 --- a/lib/ronin/recon/builtin/net/cert_enum.rb +++ b/lib/ronin/recon/builtin/ssl/cert_enum.rb @@ -25,14 +25,14 @@ module Ronin module Recon - module Net + module SSL # # A recon worker that enumerates over the host names within the SSL/TLS # certificate. # class CertEnum < Worker - register 'net/cert_enum' + register 'ssl/cert_enum' accepts Cert diff --git a/lib/ronin/recon/builtin/net/cert_grab.rb b/lib/ronin/recon/builtin/ssl/cert_grab.rb similarity index 97% rename from lib/ronin/recon/builtin/net/cert_grab.rb rename to lib/ronin/recon/builtin/ssl/cert_grab.rb index 0c5de43..458f05a 100644 --- a/lib/ronin/recon/builtin/net/cert_grab.rb +++ b/lib/ronin/recon/builtin/ssl/cert_grab.rb @@ -24,14 +24,14 @@ module Ronin module Recon - module Net + module SSL # # A recon worker that grabs the SSL/TLS certificate from open ports that # use SSL/TLS. # class CertGrab < Worker - register 'net/cert_grab' + register 'ssl/cert_grab' accepts OpenPort diff --git a/spec/builtin/net/cert_enum_spec.rb b/spec/builtin/ssl/cert_enum_spec.rb similarity index 95% rename from spec/builtin/net/cert_enum_spec.rb rename to spec/builtin/ssl/cert_enum_spec.rb index 6cfb567..679bc25 100644 --- a/spec/builtin/net/cert_enum_spec.rb +++ b/spec/builtin/ssl/cert_enum_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -require 'ronin/recon/builtin/net/cert_enum' +require 'ronin/recon/builtin/ssl/cert_enum' -describe Ronin::Recon::Net::CertEnum do +describe Ronin::Recon::SSL::CertEnum do describe "#process" do context "when there are values in cert" do context "with subject alt names" do diff --git a/spec/builtin/net/cert_grab_spec.rb b/spec/builtin/ssl/cert_grab_spec.rb similarity index 93% rename from spec/builtin/net/cert_grab_spec.rb rename to spec/builtin/ssl/cert_grab_spec.rb index 6bb76fa..2a4e878 100644 --- a/spec/builtin/net/cert_grab_spec.rb +++ b/spec/builtin/ssl/cert_grab_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -require 'ronin/recon/builtin/net/cert_grab' +require 'ronin/recon/builtin/ssl/cert_grab' -describe Ronin::Recon::Net::CertGrab do +describe Ronin::Recon::SSL::CertGrab do describe "#process" do context "when there are certificates in the open port" do let(:port) { Ronin::Recon::Values::OpenPort.new("93.184.216.34", 443, service: 'http', ssl: true) } From 67d342fec88a5c377f510496b6d613e63c6925ae Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Fri, 27 Oct 2023 15:33:34 +0200 Subject: [PATCH 2/3] move cert_sh to ssl directory --- lib/ronin/recon/builtin/{net => ssl}/cert_sh.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/ronin/recon/builtin/{net => ssl}/cert_sh.rb (100%) diff --git a/lib/ronin/recon/builtin/net/cert_sh.rb b/lib/ronin/recon/builtin/ssl/cert_sh.rb similarity index 100% rename from lib/ronin/recon/builtin/net/cert_sh.rb rename to lib/ronin/recon/builtin/ssl/cert_sh.rb From 2bbc60de723cd239e673fc80051a69e99b5c0117 Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Sun, 29 Oct 2023 17:59:51 +0100 Subject: [PATCH 3/3] add `Retry` mixin --- lib/ronin/recon/builtin/ssl/cert_sh.rb | 14 ++++--- lib/ronin/recon/mixins/retry.rb | 54 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 lib/ronin/recon/mixins/retry.rb diff --git a/lib/ronin/recon/builtin/ssl/cert_sh.rb b/lib/ronin/recon/builtin/ssl/cert_sh.rb index 12943aa..d1f7553 100644 --- a/lib/ronin/recon/builtin/ssl/cert_sh.rb +++ b/lib/ronin/recon/builtin/ssl/cert_sh.rb @@ -21,6 +21,7 @@ require 'ronin/recon/worker' require 'async/http/internet/instance' +require 'ronin/recon/mixins/retry' module Ronin module Recon @@ -29,6 +30,7 @@ module SSL # A recon worker that returns host from each domains certificate # class CertSh < Worker + include Mixins::Retry register 'net/cert_sh' @@ -58,12 +60,14 @@ def process(domain) internet = Async::HTTP::Internet.instance path = "https://crt.sh/?dNSName=#{domain}&exclude=expired&output=json" - response = internet.get(path) - certs = JSON.parse(response.read, symbolize_names: true) + retry_on_timeout do + response = internet.get(path) + certs = JSON.parse(response.read, symbolize_names: true) - certs.each do |cert| - if (common_name = cert[:common_name]) - yield Host.new(common_name) + certs.each do |cert| + if (common_name = cert[:common_name]) + yield Host.new(common_name) + end end end end diff --git a/lib/ronin/recon/mixins/retry.rb b/lib/ronin/recon/mixins/retry.rb new file mode 100644 index 0000000..8926961 --- /dev/null +++ b/lib/ronin/recon/mixins/retry.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true +# +# ronin-recon - A micro-framework and tool for performing reconnaissance. +# +# Copyright (c) 2023 Hal Brodigan (postmodern.mod3@gmail.com) +# +# ronin-recon is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ronin-recon is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with ronin-recon. If not, see . +# + +require 'async/http' +require 'set' + +module Ronin + module Recon + module Mixins + # + # Mixin which adds method for retrying HTTP requests + # + # @api public + # + module Retry + # + # Retry code given in block if connection times out + # + def retry_on_timeout(limit: 3, &block) + retries = 0 + + begin + block.call + rescue Errno::ETIMEDOUT => e + sleep(1) + retries += 1 + if retries > limit + raise(e) + else + retry + end + end + end + end + end + end +end