Class: Arachni::Report
- Includes:
- Utilities
- Defined in:
- lib/arachni/report.rb
Overview
Instance Attribute Summary collapse
-
#finish_datetime ⇒ Time
The date and time when the scan finished.
- #options ⇒ Hash
-
#plugins ⇒ Hash
Plugin results.
-
#sitemap ⇒ Hash<String, Integer>
List of crawled URLs with their HTTP codes.
-
#start_datetime ⇒ Time
The date and time when the scan started.
- #version ⇒ String
Class Method Summary collapse
- .from_rpc_data(data) ⇒ DOM
- .load(file) ⇒ Report
-
.read_summary(report) ⇒ Hash
#summary associated with the given report.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#delta_time ⇒ String
‘#start_datetime - #finish_datetime` in `00:00:00` (`hours:minutes:seconds`) format.
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Report
constructor
A new instance of Report.
- #issue_by_digest(digest) ⇒ Issue
-
#issues ⇒ Array<Issue>
Logged issues.
-
#issues=(issues) ⇒ Array<Issue>
Logged issues.
- #issues_by_check(check) ⇒ Array<Issue>
-
#save(location = nil) ⇒ String
Absolute location of the report.
-
#summary ⇒ Hash
Summary data of the report.
-
#to_afr ⇒ String
Report serialized in the Arachni Framework Report format.
-
#to_h ⇒ Hash
(also: #to_hash)
Hash representation of ‘self`.
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
- #url ⇒ Object
Methods included from Utilities
#available_port, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #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.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/arachni/report.rb', line 41 def initialize( = {} ) .each { |k, v| send( "#{k}=", v ) } @version ||= Arachni::VERSION @plugins ||= {} @sitemap ||= {} self. ||= Options @issues ||= {} @start_datetime ||= Time.now @finish_datetime ||= Time.now end |
Instance Attribute Details
#finish_datetime ⇒ Time
Returns The date and time when the scan finished.
39 40 41 |
# File 'lib/arachni/report.rb', line 39 def finish_datetime @finish_datetime end |
#options ⇒ Hash
Returns Options#to_h.
23 24 25 |
# File 'lib/arachni/report.rb', line 23 def @options end |
#plugins ⇒ Hash
Returns Plugin results.
31 32 33 |
# File 'lib/arachni/report.rb', line 31 def plugins @plugins end |
#sitemap ⇒ Hash<String, Integer>
Returns List of crawled URLs with their HTTP codes.
27 28 29 |
# File 'lib/arachni/report.rb', line 27 def sitemap @sitemap end |
#start_datetime ⇒ Time
Returns The date and time when the scan started.
35 36 37 |
# File 'lib/arachni/report.rb', line 35 def start_datetime @start_datetime end |
Class Method Details
.from_rpc_data(data) ⇒ DOM
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/arachni/report.rb', line 256 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.
133 134 135 136 137 138 139 140 141 |
# File 'lib/arachni/report.rb', line 133 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.
116 117 118 119 120 121 122 123 124 |
# File 'lib/arachni/report.rb', line 116 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
277 278 279 |
# File 'lib/arachni/report.rb', line 277 def ==( other ) hash == other.hash end |
#delta_time ⇒ String
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.
63 64 65 |
# File 'lib/arachni/report.rb', line 63 def delta_time seconds_to_hms( (@finish_datetime || Time.now) - @start_datetime ) end |
#hash ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/arachni/report.rb', line 281 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
107 108 109 |
# File 'lib/arachni/report.rb', line 107 def issue_by_digest( digest ) @issues[digest] end |
#issues ⇒ Array<Issue>
Returns Logged issues.
100 101 102 |
# File 'lib/arachni/report.rb', line 100 def issues @issues.values end |
#issues=(issues) ⇒ Array<Issue>
Returns Logged issues.
80 81 82 83 84 85 86 |
# File 'lib/arachni/report.rb', line 80 def issues=( issues ) @issues = {} issues.each do |issue| @issues[issue.digest] = issue end self.issues end |
#issues_by_check(check) ⇒ Array<Issue>
92 93 94 95 96 |
# File 'lib/arachni/report.rb', line 92 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.
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/arachni/report.rb', line 148 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.( location ) end |
#summary ⇒ Hash
Returns Summary data of the report.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/arachni/report.rb', line 201 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, 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_afr ⇒ String
Returns Report serialized in the Arachni Framework Report format.
164 165 166 167 168 169 170 171 172 |
# File 'lib/arachni/report.rb', line 164 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_h ⇒ Hash Also known as: to_hash
Returns Hash representation of ‘self`.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/arachni/report.rb', line 176 def to_h h = { version: @version, 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_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/arachni/report.rb', line 231 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 |
#url ⇒ Object
54 55 56 |
# File 'lib/arachni/report.rb', line 54 def url @options[:url] end |