Skip to content

Commit

Permalink
Add Archive and GitArchive output formats
Browse files Browse the repository at this point in the history
  • Loading branch information
AI-Mozi committed Aug 30, 2024
1 parent b63b583 commit 5d844e0
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/ronin/recon/output_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
require_relative 'output_formats/svg'
require_relative 'output_formats/png'
require_relative 'output_formats/pdf'
require_relative 'output_formats/archive'
require_relative 'output_formats/git_archive'

require 'ronin/core/output_formats'

Expand All @@ -35,15 +37,17 @@ module Recon
module OutputFormats
include Core::OutputFormats

register :txt, '.txt', TXT
register :csv, '.csv', CSV
register :json, '.json', JSON
register :ndjson, '.ndjson', NDJSON
register :dir, '', Dir
register :dot, '.dot', Dot
register :svg, '.svg', SVG
register :png, '.png', PNG
register :pdf, '.pdf', PDF
register :txt, '.txt', TXT
register :csv, '.csv', CSV
register :json, '.json', JSON
register :ndjson, '.ndjson', NDJSON
register :dir, '', Dir
register :dot, '.dot', Dot
register :svg, '.svg', SVG
register :png, '.png', PNG
register :pdf, '.pdf', PDF
register :archive, '', Archive
register :git_archive, '', GitArchive
end
end
end
46 changes: 46 additions & 0 deletions lib/ronin/recon/output_formats/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 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 'ronin/web/spider/archive'

module Ronin
module Recon
module OutputFormats
#
# Represents a web archive directory.
#
class Archive < Ronin::Web::Spider::Archive

#
# Writes a new URL to it's specific file.
#
# @param [Value] value
# The value to write.
#
def <<(value)
if Values::URL === value
write(value.uri, value.body)
end
end

end
end
end
end
58 changes: 58 additions & 0 deletions lib/ronin/recon/output_formats/git_archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 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 'ronin/web/spider/git_archive'

module Ronin
module Recon
module OutputFormats
#
# Represents a web archive directory that is backed by Git.
#
class GitArchive < Ronin::Web::Spider::GitArchive

#
# Initializes new Git repository.
#
# @param [String] root
# The path to the root directory.
#
def initialize(root)
super(root)

init unless git?
end

#
# Writes a new URL to it's specific file in Git archive.
#
# @param [Value] value
# The value to write.
#
def <<(value)
if Values::URL === value
write(value.uri, value.body)
end
end

end
end
end
end
38 changes: 38 additions & 0 deletions spec/output_formats/archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'
require 'ronin/recon/output_formats/archive'
require 'ronin/recon/values/url'
require 'ronin/recon/values/domain'
require 'tmpdir'

describe Ronin::Recon::OutputFormats::Archive do
subject { described_class.new(path) }

let(:path) { Dir.mktmpdir('ronin-recon-output-archive') }

it "must inherit from Ronin::Web::Spider::Archive" do
expect(described_class).to be < Ronin::Web::Spider::Archive
end

describe "#<<" do
context "for Values::URL" do
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
let(:expected_path) { File.join(path,value.path) }

it "must create a new file with webpage" do
subject << value

expect(File.exist?(expected_path)).to be(true)
end
end

context "for other values" do
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }

it "must not create any files" do
subject << value

expect(Dir.glob("#{path}/*")).to be_empty
end
end
end
end
38 changes: 38 additions & 0 deletions spec/output_formats/git_archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'
require 'ronin/recon/output_formats/git_archive'
require 'ronin/recon/values/url'
require 'ronin/recon/values/domain'
require 'tmpdir'

describe Ronin::Recon::OutputFormats::GitArchive do
subject { described_class.new(path) }

let(:path) { Dir.mktmpdir('ronin-recon-output-git-archive') }

it "must inherit from Ronin::Web::Spider::GitArchive" do
expect(described_class).to be < Ronin::Web::Spider::GitArchive
end

describe "#<<" do
context "for Values::URL" do
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
let(:expected_path) { File.join(path,value.path) }

it "must create a new file with webpage" do
subject << value

expect(File.exist?(expected_path)).to be(true)
end
end

context "for other values" do
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }

it "must not create any files" do
subject << value

expect(Dir.glob("#{path}/*")).to be_empty
end
end
end
end

0 comments on commit 5d844e0

Please sign in to comment.