Skip to content

Commit c086226

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

File tree

5 files changed

+195
-9
lines changed

5 files changed

+195
-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 :archive, '', Archive
50+
register :git_archive, '', GitArchive
4751
end
4852
end
4953
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 < Ronin::Web::Spider::Archive
30+
31+
#
32+
# Writes a new URL to it's specific file.
33+
#
34+
# @param [Value] value
35+
# The value to write.
36+
#
37+
def <<(value)
38+
if Values::URL === value
39+
write(value.uri, value.body)
40+
end
41+
end
42+
43+
end
44+
end
45+
end
46+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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/recon/values/url'
22+
23+
require 'ronin/web/spider/git_archive'
24+
25+
module Ronin
26+
module Recon
27+
module OutputFormats
28+
#
29+
# Represents a web archive directory that is backed by Git.
30+
#
31+
class GitArchive < Ronin::Web::Spider::GitArchive
32+
33+
#
34+
# Initializes new Git repository.
35+
#
36+
# @param [String] root
37+
# The path to the root directory.
38+
#
39+
def initialize(root)
40+
super(root)
41+
42+
init unless git?
43+
end
44+
45+
#
46+
# Writes a new URL to it's specific file in Git archive.
47+
#
48+
# @param [Value] value
49+
# The value to write.
50+
#
51+
def <<(value)
52+
if Values::URL === value
53+
write(value.uri, value.body)
54+
end
55+
end
56+
57+
end
58+
end
59+
end
60+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
it "must inherit from Ronin::Web::Spider::Archive" do
13+
expect(described_class).to be < Ronin::Web::Spider::Archive
14+
end
15+
16+
describe "#<<" do
17+
context "for Values::URL" do
18+
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
19+
let(:expected_path) { File.join(path,value.path) }
20+
21+
it "must create a new file with webpage" do
22+
subject << value
23+
24+
expect(File.exist?(expected_path)).to be(true)
25+
end
26+
end
27+
28+
context "for other values" do
29+
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }
30+
31+
it "must not create any files" do
32+
subject << value
33+
34+
expect(Dir.glob("#{path}/*")).to be_empty
35+
end
36+
end
37+
end
38+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
it "must inherit from Ronin::Web::Spider::GitArchive" do
13+
expect(described_class).to be < Ronin::Web::Spider::GitArchive
14+
end
15+
16+
describe "#<<" do
17+
context "for Values::URL" do
18+
let(:value) { Ronin::Recon::Values::URL.new('https://www.example.com/foo.html') }
19+
let(:expected_path) { File.join(path,value.path) }
20+
21+
it "must create a new file with webpage" do
22+
subject << value
23+
24+
expect(File.exist?(expected_path)).to be(true)
25+
end
26+
end
27+
28+
context "for other values" do
29+
let(:value) { Ronin::Recon::Values::Domain.new('example.com') }
30+
31+
it "must not create any files" do
32+
subject << value
33+
34+
expect(Dir.glob("#{path}/*")).to be_empty
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)