Class: Arachni::AuditStore

Inherits:
Object show all
Defined in:
lib/arachni/audit_store.rb

Overview

Represents a finished audit session.

It holds information about the runtime environment, the results of the audit etc…

Author:

Constant Summary collapse

MODULE_NAMESPACE =
::Arachni::Modules
ORDER =
[
    Severity::HIGH,
    Severity::MEDIUM,
    Severity::LOW,
    Severity::INFORMATIONAL
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ AuditStore

Returns a new instance of AuditStore.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/arachni/audit_store.rb', line 86

def initialize( opts = {} )
    @plugins = {}
    @sitemap = []

    @issues  ||= []
    @options ||= Options

    # set instance variables from audit opts
    opts.each { |k, v| self.instance_variable_set( '@' + k.to_s, v ) }

    @options = prepare_options( @options )
    @issues  = self.class.sort( prepare_variations( @issues.deep_clone ) )

    @start_datetime  =  if @options['start_datetime']
        @options['start_datetime'].asctime
    else
        Time.now.asctime
    end

    @finish_datetime = if @options['finish_datetime']
        @options['finish_datetime'].asctime
    else
        Time.now.asctime
    end

    @delta_time = secs_to_hms( @options['delta_time'] )
end

Instance Attribute Details

#delta_timeString (readonly)

Returns how long the audit took.

Returns:

  • (String)

    how long the audit took



75
76
77
# File 'lib/arachni/audit_store.rb', line 75

def delta_time
  @delta_time
end

#finish_datetimeString (readonly)

Returns the date and time when the audit finished.

Returns:

  • (String)

    the date and time when the audit finished



70
71
72
# File 'lib/arachni/audit_store.rb', line 70

def finish_datetime
  @finish_datetime
end

#issuesArray<Issue> (readonly)

Returns the discovered issues.

Returns:



55
56
57
# File 'lib/arachni/audit_store.rb', line 55

def issues
  @issues
end

#optionsHash (readonly)

Returns the runtime arguments/options of the environment.

Returns:

  • (Hash)

    the runtime arguments/options of the environment



45
46
47
# File 'lib/arachni/audit_store.rb', line 45

def options
  @options
end

#pluginsHash (readonly)

Returns plugin results.

Returns:

  • (Hash)

    plugin results



60
61
62
# File 'lib/arachni/audit_store.rb', line 60

def plugins
  @plugins
end

#revisionString (readonly)

Returns the revision of the framework class.

Returns:

  • (String)

    the revision of the framework class



40
41
42
# File 'lib/arachni/audit_store.rb', line 40

def revision
  @revision
end

#sitemapArray (readonly)

Returns all the urls crawled.

Returns:

  • (Array)

    all the urls crawled



50
51
52
# File 'lib/arachni/audit_store.rb', line 50

def sitemap
  @sitemap
end

#start_datetimeString (readonly)

Returns the date and time when the audit started.

Returns:

  • (String)

    the date and time when the audit started



65
66
67
# File 'lib/arachni/audit_store.rb', line 65

def start_datetime
  @start_datetime
end

#versionString (readonly)

Returns the version of the framework.

Returns:

  • (String)

    the version of the framework



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

def version
  @version
end

Class Method Details

.load(file) ⇒ AuditStore

Loads and returns an AuditStore object from file

Parameters:

  • file (String)

    the file to load

Returns:



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

def self.load( file )
     begin
         r = YAML.load( IO.read( file ) )
         r.version
         r
     rescue Exception => e
         Marshal.load( File.binread( file ) )
     end
end

.sort(issues) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/arachni/audit_store.rb', line 176

def self.sort( issues )
    sorted = []
    issues.each do |issue|
        order = ORDER.rindex( issue.severity ) || ORDER.size
        sorted[order] ||= []
        sorted[order] << issue
    end
    sorted.flatten.compact
end

Instance Method Details

#==(other) ⇒ Object



168
169
170
# File 'lib/arachni/audit_store.rb', line 168

def ==( other )
    to_hash == other.to_hash
end

#hashObject



172
173
174
# File 'lib/arachni/audit_store.rb', line 172

def hash
    to_hash.hash
end

#save(file) ⇒ Object

Saves ‘self’ to file

Parameters:



136
137
138
139
140
141
142
# File 'lib/arachni/audit_store.rb', line 136

def save( file )
    begin
        File.open( file, 'w' ) { |f| f.write( YAML.dump( self ) ) }
    rescue
        File.open( file, 'wb' ) { |f| f.write( Marshal.dump( self ) ) }
    end
end

#to_hashHash Also known as: to_h

Returns ‘self’ and all objects in its instance vars as hashes

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/arachni/audit_store.rb', line 149

def to_hash
    hash = obj_to_hash( self ).deep_clone

    hash['issues'] = hash['issues'].map do |issue|
        issue.variations = issue.variations.map { |var| obj_to_hash( var ) }
        obj_to_hash( issue )
    end

    hash['plugins'].each do |plugin, results|
        next if !results[:options]

        hash['plugins'][plugin][:options] =
            hash['plugins'][plugin][:options].map { |opt| opt.to_h }
    end

    hash
end