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 Archive and GitArchive output formats #173

Draft
wants to merge 1 commit into
base: 0.2.0
Choose a base branch
from
Draft
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
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 :web_archive, '', Archive
register :web_git_archive, '', GitArchive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename classes to WebArchive and GitArchive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file-exts can be omitted now that they are optional.

end
end
end
56 changes: 56 additions & 0 deletions lib/ronin/recon/output_formats/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan ([email protected])
#
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename class to WebArchive.


#
# Initializes new archive.
#
# @param [String] root
# The path to the root directory.
#
def initialize(root)
@archive = Ronin::Web::Spider::Archive.new(root)
end

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

end
end
end
end
57 changes: 57 additions & 0 deletions lib/ronin/recon/output_formats/git_archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan ([email protected])
#
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename class to WebGitArchive.


#
# Initializes new Git repository.
#
# @param [String] root
# The path to the root directory.
#
def initialize(root)
@git_archive = Ronin::Web::Spider::GitArchive.new(root)
@git_archive.init unless @git_archive.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
@git_archive.write(value.uri, value.body)
end
end

end
end
end
end
34 changes: 34 additions & 0 deletions spec/output_formats/archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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') }

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
34 changes: 34 additions & 0 deletions spec/output_formats/git_archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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') }

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
Loading