Skip to content

Commit 8d62799

Browse files
committed
Add Archive and GitArchive output formats
1 parent b63b583 commit 8d62799

File tree

5 files changed

+194
-9
lines changed

5 files changed

+194
-9
lines changed

lib/ronin/recon/output_formats.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
require_relative 'output_formats/svg'
2424
require_relative 'output_formats/png'
2525
require_relative 'output_formats/pdf'
26+
require_relative 'output_formats/archive'
27+
require_relative 'output_formats/git_archive'
2628

2729
require 'ronin/core/output_formats'
2830

@@ -35,15 +37,17 @@ module Recon
3537
module OutputFormats
3638
include Core::OutputFormats
3739

38-
register :txt, '.txt', TXT
39-
register :csv, '.csv', CSV
40-
register :json, '.json', JSON
41-
register :ndjson, '.ndjson', NDJSON
42-
register :dir, '', Dir
43-
register :dot, '.dot', Dot
44-
register :svg, '.svg', SVG
45-
register :png, '.png', PNG
46-
register :pdf, '.pdf', PDF
40+
register :txt, '.txt', TXT
41+
register :csv, '.csv', CSV
42+
register :json, '.json', JSON
43+
register :ndjson, '.ndjson', NDJSON
44+
register :dir, '', Dir
45+
register :dot, '.dot', Dot
46+
register :svg, '.svg', SVG
47+
register :png, '.png', PNG
48+
register :pdf, '.pdf', PDF
49+
register :web_archive, '', Archive
50+
register :web_git_archive, '', GitArchive
4751
end
4852
end
4953
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-recon - A micro-framework and tool for performing reconnaissance.
4+
#
5+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6+
#
7+
# ronin-recon is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-recon is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
require 'ronin/web/spider/archive'
22+
23+
module Ronin
24+
module Recon
25+
module OutputFormats
26+
#
27+
# Represents a web archive directory.
28+
#
29+
class Archive
30+
31+
#
32+
# Initializes new archive.
33+
#
34+
# @param [String] root
35+
# The path to the root directory.
36+
#
37+
def initialize(root)
38+
@archive = Ronin::Web::Spider::Archive.new(root)
39+
end
40+
41+
#
42+
# Writes a new URL to it's specific file.
43+
#
44+
# @param [Value] value
45+
# The value to write.
46+
#
47+
def <<(value)
48+
if Values::URL === value
49+
@archive.write(value.uri, value.body)
50+
end
51+
end
52+
53+
end
54+
end
55+
end
56+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-recon - A micro-framework and tool for performing reconnaissance.
4+
#
5+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6+
#
7+
# ronin-recon is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-recon is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
require 'ronin/web/spider/git_archive'
22+
23+
module Ronin
24+
module Recon
25+
module OutputFormats
26+
#
27+
# Represents a web archive directory that is backed by Git.
28+
#
29+
class GitArchive
30+
31+
#
32+
# Initializes new Git repository.
33+
#
34+
# @param [String] root
35+
# The path to the root directory.
36+
#
37+
def initialize(root)
38+
@git_archive = Ronin::Web::Spider::GitArchive.new(root)
39+
@git_archive.init unless @git_archive.git?
40+
end
41+
42+
#
43+
# Writes a new URL to it's specific file in Git archive.
44+
#
45+
# @param [Value] value
46+
# The value to write.
47+
#
48+
def <<(value)
49+
if Values::URL === value
50+
@git_archive.write(value.uri, value.body)
51+
end
52+
end
53+
54+
end
55+
end
56+
end
57+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
require 'ronin/recon/output_formats/archive'
3+
require 'ronin/recon/values/url'
4+
require 'ronin/recon/values/domain'
5+
require 'tmpdir'
6+
7+
describe Ronin::Recon::OutputFormats::Archive do
8+
subject { described_class.new(path) }
9+
10+
let(:path) { Dir.mktmpdir('ronin-recon-output-archive') }
11+
12+
describe "#<<" do
13+
context "for Values::URL" do
14+
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
15+
let(:expected_path) { File.join(path,value.path) }
16+
17+
it "must create a new file with webpage" do
18+
subject << value
19+
20+
expect(File.exist?(expected_path)).to be(true)
21+
end
22+
end
23+
24+
context "for other values" do
25+
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }
26+
27+
it "must not create any files" do
28+
subject << value
29+
30+
expect(Dir.glob("#{path}/*")).to be_empty
31+
end
32+
end
33+
end
34+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
require 'ronin/recon/output_formats/git_archive'
3+
require 'ronin/recon/values/url'
4+
require 'ronin/recon/values/domain'
5+
require 'tmpdir'
6+
7+
describe Ronin::Recon::OutputFormats::GitArchive do
8+
subject { described_class.new(path) }
9+
10+
let(:path) { Dir.mktmpdir('ronin-recon-output-git-archive') }
11+
12+
describe "#<<" do
13+
context "for Values::URL" do
14+
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
15+
let(:expected_path) { File.join(path,value.path) }
16+
17+
it "must create a new file with webpage" do
18+
subject << value
19+
20+
expect(File.exist?(expected_path)).to be(true)
21+
end
22+
end
23+
24+
context "for other values" do
25+
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }
26+
27+
it "must not create any files" do
28+
subject << value
29+
30+
expect(Dir.glob("#{path}/*")).to be_empty
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)