Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Retry mixin #90

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
require 'ronin/recon/worker'

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

module Ronin
module Recon
module Net
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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'ronin/recon/builtin/net/cert_sh'
require 'ronin/recon/builtin/ssl/cert_sh'

describe Ronin::Recon::Net::CertSh do
describe Ronin::Recon::SSL::CertSh do
describe "#process" do
context "for domain with certificates" do
let(:domain) { Ronin::Recon::Values::Domain.new("example.com") }
Expand Down