Class: Gobuster::OutputFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gobuster/output_file.rb

Overview

Parses an output file created by gobuster -o ....

Example

require 'gobuster/output_file'

output_file = Gobuster::OutputFile.new('/path/to/file.txt')
output_file.each do |object|
  p object
end

Constant Summary collapse

PARSERS =

Mapping of formats to parsers.

{
  dir:  Parsers::Dir,
  dns:  Parsers::DNS,
  fuzz: Parsers::Fuzz,
  s3:   Parsers::S3
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format:) ⇒ OutputFile

Initializes the output file.



59
60
61
62
63
64
65
66
# File 'lib/gobuster/output_file.rb', line 59

def initialize(path, format: )
  @path   = File.expand_path(path)
  @format = format

  @parser = PARSERS.fetch(format) do
    raise(ArgumentError,"unrecognized file type: #{@path.inspect}")
  end
end

Instance Attribute Details

#format:dir, ... (readonly)

The format of the output file.



41
42
43
# File 'lib/gobuster/output_file.rb', line 41

def format
  @format
end

#parserParsers::Dir, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The parser for the output file format.



48
49
50
# File 'lib/gobuster/output_file.rb', line 48

def parser
  @parser
end

#pathString (readonly)

The path to the output file.



36
37
38
# File 'lib/gobuster/output_file.rb', line 36

def path
  @path
end

Instance Method Details

#each {|object| ... } ⇒ Enumerator

Parses the contents of the output file.

Yields:

  • (object)

    The given block will be passed each parsed object.

Yield Parameters:



80
81
82
83
84
85
86
# File 'lib/gobuster/output_file.rb', line 80

def each(&block)
  return enum_for(__method__) unless block

  File.open(@path) do |file|
    @parser.parse(file,&block)
  end
end

#to_sString

Converts the output file to a String.



94
95
96
# File 'lib/gobuster/output_file.rb', line 94

def to_s
  @path
end