Skip to content

Commit

Permalink
add Retry mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi committed Oct 29, 2023
1 parent 67d342f commit 2bbc60d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/ronin/recon/builtin/ssl/cert_sh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require 'ronin/recon/worker'

require 'async/http/internet/instance'
require 'ronin/recon/mixins/retry'

module Ronin
module Recon
Expand All @@ -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'

Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions lib/ronin/recon/mixins/retry.rb
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#

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

0 comments on commit 2bbc60d

Please sign in to comment.