Class: Arachni::Report

Inherits:
Object show all
Includes:
Utilities
Defined in:
lib/arachni/report.rb

Overview

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Constructor Details

#initialize(options = {}) ⇒ Report

Returns a new instance of Report.


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/arachni/report.rb', line 45

def initialize( options = {} )
    options.each { |k, v| send( "#{k}=", v ) }

    @version     ||= Arachni::VERSION
    @seed        ||= Arachni::Utilities.random_seed
    @plugins     ||= {}
    @sitemap     ||= {}
    self.options ||= Options
    @issues      ||= {}

    @start_datetime  ||= Time.now
    @finish_datetime ||= Time.now
end

Instance Attribute Details

#finish_datetimeTime

Returns The date and time when the scan finished.

Returns:

  • (Time)

    The date and time when the scan finished.


43
44
45
# File 'lib/arachni/report.rb', line 43

def finish_datetime
  @finish_datetime
end

#optionsHash

Returns Options#to_h.

Returns:


27
28
29
# File 'lib/arachni/report.rb', line 27

def options
  @options
end

#pluginsHash

Returns Plugin results.

Returns:

  • (Hash)

    Plugin results.


35
36
37
# File 'lib/arachni/report.rb', line 35

def plugins
  @plugins
end

#seedString

Returns Scan seed.

Returns:


23
24
25
# File 'lib/arachni/report.rb', line 23

def seed
  @seed
end

#sitemapHash<String, Integer>

Returns List of crawled URLs with their HTTP codes.

Returns:

  • (Hash<String, Integer>)

    List of crawled URLs with their HTTP codes.


31
32
33
# File 'lib/arachni/report.rb', line 31

def sitemap
  @sitemap
end

#start_datetimeTime

Returns The date and time when the scan started.

Returns:

  • (Time)

    The date and time when the scan started.


39
40
41
# File 'lib/arachni/report.rb', line 39

def start_datetime
  @start_datetime
end

#versionString

Returns VERSION.

Returns:


19
20
21
# File 'lib/arachni/report.rb', line 19

def version
  @version
end

Class Method Details

.from_rpc_data(data) ⇒ DOM

Parameters:

Returns:

  • (DOM)

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/arachni/report.rb', line 263

def self.from_rpc_data( data )
    data['start_datetime']  = Time.parse( data['start_datetime'] )
    data['finish_datetime'] = Time.parse( data['finish_datetime'] )

    data['issues'] = data['issues'].map { |i| Arachni::Issue.from_rpc_data( i ) }

    data['plugins'] = data['plugins'].inject({}) do |h, (k, v)|
        k    = k.to_sym
        h[k] = v.my_symbolize_keys(false)
        next h if !h[k][:options]

        h[k][:options] = v['options'].map do |option|
            klass = option['class'].split( '::' ).last.to_sym
            Component::Options.const_get( klass ).from_rpc_data( option )
        end
        h
    end

    new data
end

.load(file) ⇒ Report

Loads and a saved Arachni::Report object from file.

Parameters:

Returns:

  • (Report)

    Loaded instance.


138
139
140
141
142
143
144
145
146
# File 'lib/arachni/report.rb', line 138

def self.load( file )
    File.open( file, 'rb' ) do |f|
        f.seek -4, IO::SEEK_END
        summary_size = f.read( 4 ).unpack( 'N' ).first

        f.rewind
        from_rpc_data RPC::Serializer.load( f.read( f.size - summary_size ) )
    end
end

.read_summary(report) ⇒ Hash

Returns #summary associated with the given report.

Parameters:

  • report (String)

    Location of the report.

Returns:


121
122
123
124
125
126
127
128
129
# File 'lib/arachni/report.rb', line 121

def self.read_summary( report )
    File.open( report ) do |f|
        f.seek -4, IO::SEEK_END
        summary_size = f.read( 4 ).unpack( 'N' ).first

        f.seek -summary_size-4, IO::SEEK_END
        RPC::Serializer.load( f.read( summary_size ) )
    end
end

Instance Method Details

#==(other) ⇒ Object


284
285
286
# File 'lib/arachni/report.rb', line 284

def ==( other )
    hash == other.hash
end

#delta_timeString

Note:

If no #finish_datetime has been provided, it will use Time.now.

Returns {#start_datetime} - {#finish_datetime} in 00:00:00 (hours:minutes:seconds) format.

Returns:

  • (String)

    {#start_datetime} - {#finish_datetime} in 00:00:00 (hours:minutes:seconds) format.


68
69
70
# File 'lib/arachni/report.rb', line 68

def delta_time
    seconds_to_hms( (@finish_datetime || Time.now) - @start_datetime )
end

#hashObject


288
289
290
291
292
293
294
# File 'lib/arachni/report.rb', line 288

def hash
    h = to_hash
    [:start_datetime, :finish_datetime, :delta_datetime].each do |k|
        h.delete k
    end
    h.hash
end

#issue_by_digest(digest) ⇒ Issue

Parameters:

Returns:


112
113
114
# File 'lib/arachni/report.rb', line 112

def issue_by_digest( digest )
    @issues[digest]
end

#issuesArray<Issue>

Returns Logged issues.

Returns:


105
106
107
# File 'lib/arachni/report.rb', line 105

def issues
    @issues.values
end

#issues=(issues) ⇒ Array<Issue>

Returns Logged issues.

Parameters:

Returns:


85
86
87
88
89
90
91
# File 'lib/arachni/report.rb', line 85

def issues=( issues )
    @issues = {}
    issues.each do |issue|
        @issues[issue.digest] = issue
    end
    self.issues
end

#issues_by_check(check) ⇒ Array<Issue>

Parameters:

  • check (String)

    Check shortname.

Returns:


97
98
99
100
101
# File 'lib/arachni/report.rb', line 97

def issues_by_check( check )
    @issues.map do |_, issue|
        issue if issue.check[:shortname] == check.to_s
    end.compact
end

#save(location = nil) ⇒ String

Returns Absolute location of the report.

Parameters:

  • location (String) (defaults to: nil)

    Location for the dumped report file.

Returns:

  • (String)

    Absolute location of the report.


153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/arachni/report.rb', line 153

def save( location = nil )
    default_filename = "#{URI(url).host} #{@finish_datetime.to_s.gsub( ':', '_' )}.afr"

    if !location
        location = default_filename
    elsif File.directory? location
        location += "/#{default_filename}"
    end

    IO.binwrite( location, to_afr )

    File.expand_path( location )
end

#summaryHash

Returns Summary data of the report.

Returns:

  • (Hash)

    Summary data of the report.


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/arachni/report.rb', line 207

def summary
    by_severity = Hash.new(0)
    @issues.each { |_, issue| by_severity[issue.severity.to_sym] += 1 }

    by_type = Hash.new(0)
    @issues.each { |_, issue| by_type[issue.name] += 1 }

    by_check = Hash.new(0)
    @issues.each { |_, issue| by_check[issue.check[:shortname]] += 1 }

    {
        version:         @version,
        seed:            @seed,
        url:             url,
        checks:          @options[:checks],
        plugins:         @options[:plugins].keys,
        issues: {
            total:       @issues.size,
            by_severity: by_severity,
            by_type:     by_type,
            by_check:    by_check
        },
        sitemap_size:    @sitemap.size,
        start_datetime:  @start_datetime.to_s,
        finish_datetime: @finish_datetime.to_s,
        delta_time:      delta_time
    }
end

#to_afrString

Returns Report serialized in the Arachni Framework Report format.

Returns:

  • (String)

    Report serialized in the Arachni Framework Report format.


169
170
171
172
173
174
175
176
177
# File 'lib/arachni/report.rb', line 169

def to_afr
    afr = RPC::Serializer.dump( self )

    # Append metadata to the end of the dump.
     = RPC::Serializer.dump( summary )
    afr << [, .size].pack( 'a*N' )

    afr
end

#to_hHash Also known as: to_hash

Returns Hash representation of self.

Returns:

  • (Hash)

    Hash representation of self.


181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/arachni/report.rb', line 181

def to_h
    h = {
        version:         @version,
        seed:            @seed,
        options:         Arachni::Options.hash_to_rpc_data( @options ),
        sitemap:         @sitemap,
        start_datetime:  @start_datetime.to_s,
        finish_datetime: @finish_datetime.to_s,
        delta_time:      delta_time,
        issues:          issues.map(&:to_h),
        plugins:         @plugins.dup
    }

    h[:plugins].each do |plugin, data|
        next if !data[:options]
        h[:plugins][plugin] = h[:plugins][plugin].dup
        h[:plugins][plugin][:options] = h[:plugins][plugin][:options].dup
        h[:plugins][plugin][:options] = data[:options].map(&:to_h)
    end

    h#.recode
end

#to_rpc_dataHash

Returns Data representing this instance that are suitable the RPC transmission.

Returns:

  • (Hash)

    Data representing this instance that are suitable the RPC transmission.


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/arachni/report.rb', line 238

def to_rpc_data
    data = {}
    instance_variables.each do |ivar|
        data[ivar.to_s.gsub('@','')] = instance_variable_get( ivar )
    end

    data['options'] = Arachni::Options.hash_to_rpc_data( data['options'] )

    data['plugins'].each do |plugin, d|
        next if !d[:options]

        data['plugins'] = data['plugins'].dup
        data['plugins'][plugin] = data['plugins'][plugin].dup
        data['plugins'][plugin][:options] = data['plugins'][plugin][:options].dup
        data['plugins'][plugin][:options] = d[:options].map(&:to_rpc_data)
    end

    data['issues']          = data['issues'].values.map(&:to_rpc_data)
    data['start_datetime']  = data['start_datetime'].to_s
    data['finish_datetime'] = data['finish_datetime'].to_s
    data
end

#urlObject


59
60
61
# File 'lib/arachni/report.rb', line 59

def url
    @options[:url]
end