Class: Vulnerability

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
models/vulnerability.rb

Overview

A single vulnerability found as part of a Test

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from DataMapper::Resource

#make_dirty

Class Method Details

+ (Array<Vulnerability>) allWithFlags(selectedFlags, params = {})

Get vulns on Tests that are on apps with any of the given flags and match given parameters. This method passes through to Vulnerability.all with additional parameters to properly filter by flag

Parameters:

  • selectedFlags (Array)

    Array of flag IDs to filter by

  • params (Hash) (defaults to: {})

    Additional params to pass to Vulnerability.all

Returns:



124
125
126
127
128
129
130
# File 'models/vulnerability.rb', line 124

def self.allWithFlags(selectedFlags, params={})
	if(selectedFlags.include?(-1))
		return all(params)
	else
		return all({Vulnerability.test.application.flags.id => selectedFlags}.merge(params))
	end
end

+ (Array<Vulnerability>) countWitFlags(selectedFlags, params = {})

Count Vulnerability objects that have the given flags and match given parameters. This method passes through to Vulnerability.count with additional parameters to properly filter by flag

Parameters:

  • selectedFlags (Array<Integer>)

    Flags to filter by

  • params (Hash) (defaults to: {})

    Additional params to pass to Vulnerability.count

Returns:

  • (Array<Vulnerability>)

    Number of matching Vulnerability objects



138
139
140
# File 'models/vulnerability.rb', line 138

def self.countWitFlags(selectedFlags, params={})
	return allWithFlags(selectedFlags, params.merge({:fields => [:id]})).size
end

+ (DateTime) created_at(repository = nil)

Returns Date/Time Vulnerability created (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability created (DM Handled)



17
# File 'models/vulnerability.rb', line 17

property :created_at, 		DateTime

+ (String) custom(repository = nil)

Returns Name of Vulnerability class if custom vulnerability

Returns:

  • (String)

    Name of Vulnerability class if custom vulnerability



16
# File 'models/vulnerability.rb', line 16

property :custom,			String, :length => 100

+ (Integer) cweOverride(repository = nil)

Returns CWE mapping of this vulnerability (overrides VulnType cwe_mapping)

Returns:

  • (Integer)

    CWE mapping of this vulnerability (overrides VulnType cwe_mapping)



22
# File 'models/vulnerability.rb', line 22

property :cweOverride,		Integer

+ (Boolean) falsepos(repository = nil)

Returns True if this vuln is marked as a false positive

Returns:

  • (Boolean)

    True if this vuln is marked as a false positive



20
# File 'models/vulnerability.rb', line 20

property :falsepos,			Boolean, :default => false

+ (Integer) id(repository = nil)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/vulnerability.rb', line 13

property :id,				Serial

+ (Integer) priorityOverride(repository = nil)

Returns Priority of this vulnerability (overrides VulnType priority)

Returns:

  • (Integer)

    Priority of this vulnerability (overrides VulnType priority)



21
# File 'models/vulnerability.rb', line 21

property :priorityOverride,	Integer

+ (Boolean) starred(repository = nil)

Returns True if this Vulnerability is starred (flagged as worth saving/teaching from)

Returns:

  • (Boolean)

    True if this Vulnerability is starred (flagged as worth saving/teaching from)



23
# File 'models/vulnerability.rb', line 23

property :starred,			Boolean, :default => false

+ (Test) test(repository = nil)

Returns Test this Vulnerability belongs to

Returns:

  • (Test)

    Test this Vulnerability belongs to



25
# File 'models/vulnerability.rb', line 25

belongs_to :test

+ (Integer) test_id(repository = nil)

Returns ID of Test the Vulnerability belongs to

Returns:

  • (Integer)

    ID of Test the Vulnerability belongs to



14
# File 'models/vulnerability.rb', line 14

property :test_id,			Integer

+ (DateTime) updated_at(repository = nil)

Returns Date/Time Vulnerability last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability last updated (DM Handled)



18
# File 'models/vulnerability.rb', line 18

property :updated_at, 		DateTime

+ (Boolean) verified(repository = nil)

Returns True if this vuln is verified

Returns:

  • (Boolean)

    True if this vuln is verified



19
# File 'models/vulnerability.rb', line 19

property :verified,			Boolean, :default => true

+ (Integer) vulntype(repository = nil)

Returns ID of VulnType this Vulnerability uses. 0 = Custom vulnerability

Returns:

  • (Integer)

    ID of VulnType this Vulnerability uses. 0 = Custom vulnerability



15
# File 'models/vulnerability.rb', line 15

property :vulntype, 		Integer

Instance Method Details

- (DateTime) created_at

Returns Date/Time Vulnerability created (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability created (DM Handled)



17
# File 'models/vulnerability.rb', line 17

property :created_at, 		DateTime

- (DateTime) created_at=(value)

Returns Date/Time Vulnerability created (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability created (DM Handled)



17
# File 'models/vulnerability.rb', line 17

property :created_at, 		DateTime

- (String) custom

Returns Name of Vulnerability class if custom vulnerability

Returns:

  • (String)

    Name of Vulnerability class if custom vulnerability



16
# File 'models/vulnerability.rb', line 16

property :custom,			String, :length => 100

- (String) custom=(value)

Returns Name of Vulnerability class if custom vulnerability

Returns:

  • (String)

    Name of Vulnerability class if custom vulnerability



16
# File 'models/vulnerability.rb', line 16

property :custom,			String, :length => 100

Returns Link to CWE definition on Mitre's website if CWE-mapping exists

Returns:

  • (String)

    Link to CWE definition on Mitre's website if CWE-mapping exists



110
111
112
113
114
115
116
# File 'models/vulnerability.rb', line 110

def cwe_link
	if(self.cwe_mapping.nil? || self.cwe_mapping <= 0)
		return nil
	else
		return "https://cwe.mitre.org/data/definitions/#{self.cwe_mapping}.html"
	end
end

- (Integer) cwe_mapping

Get cwe_mapping of this vulnerability - either VulnType's or overridden cwe_mapping on this Vulnerability

Returns:

  • (Integer)

    CWE mapping



100
101
102
103
104
105
106
# File 'models/vulnerability.rb', line 100

def cwe_mapping
	if(self.vulntype == 0 || !self.cweOverride.nil?)
		return self.cweOverride
	else
		return self.vtobj.cwe_mapping
	end
end

- (Integer) cweOverride

Returns CWE mapping of this vulnerability (overrides VulnType cwe_mapping)

Returns:

  • (Integer)

    CWE mapping of this vulnerability (overrides VulnType cwe_mapping)



22
# File 'models/vulnerability.rb', line 22

property :cweOverride,		Integer

- (Integer) cweOverride=(value)

Returns CWE mapping of this vulnerability (overrides VulnType cwe_mapping)

Returns:

  • (Integer)

    CWE mapping of this vulnerability (overrides VulnType cwe_mapping)



22
# File 'models/vulnerability.rb', line 22

property :cweOverride,		Integer

- (Array<String>) descriptor

Get locations this vulnerability was found in. Locations are any URL or FILE sections on the Vulnerability

Returns:

  • (Array<String>)

    Vulnerability locations



77
78
79
80
81
82
83
84
# File 'models/vulnerability.rb', line 77

def descriptor
	dses = []
	self.sections.each do |s|
		dses << Rack::Utils.escape_html(s.body) if s.type == SECT_TYPE::URL || s.type == SECT_TYPE::FILE
	end

	dses.join ", "
end

- (Boolean) falsepos

Returns True if this vuln is marked as a false positive

Returns:

  • (Boolean)

    True if this vuln is marked as a false positive



20
# File 'models/vulnerability.rb', line 20

property :falsepos,			Boolean, :default => false

- (Boolean) falsepos=(value)

Returns True if this vuln is marked as a false positive

Returns:

  • (Boolean)

    True if this vuln is marked as a false positive



20
# File 'models/vulnerability.rb', line 20

property :falsepos,			Boolean, :default => false

- (Integer) id

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/vulnerability.rb', line 13

property :id,				Serial

- (Integer) id=(value)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/vulnerability.rb', line 13

property :id,				Serial

- (Integer) priorityOverride

Returns Priority of this vulnerability (overrides VulnType priority)

Returns:

  • (Integer)

    Priority of this vulnerability (overrides VulnType priority)



21
# File 'models/vulnerability.rb', line 21

property :priorityOverride,	Integer

- (Integer) priorityOverride=(value)

Returns Priority of this vulnerability (overrides VulnType priority)

Returns:

  • (Integer)

    Priority of this vulnerability (overrides VulnType priority)



21
# File 'models/vulnerability.rb', line 21

property :priorityOverride,	Integer

- (Boolean) starred

Returns True if this Vulnerability is starred (flagged as worth saving/teaching from)

Returns:

  • (Boolean)

    True if this Vulnerability is starred (flagged as worth saving/teaching from)



23
# File 'models/vulnerability.rb', line 23

property :starred,			Boolean, :default => false

- (Boolean) starred=(value)

Returns True if this Vulnerability is starred (flagged as worth saving/teaching from)

Returns:

  • (Boolean)

    True if this Vulnerability is starred (flagged as worth saving/teaching from)



23
# File 'models/vulnerability.rb', line 23

property :starred,			Boolean, :default => false

- (String) status_icon

Get HTML for icon representing status (verified, unverified, false positive) of this Vulnerability

Returns:

  • (String)

    HTML for status icon



49
50
51
52
53
# File 'models/vulnerability.rb', line 49

def status_icon
	return '<i class="fa fa-check" rel="tooltip" title="Vuln Verified" style="color:#009933;"></i>' if  (verified && !falsepos)
	return '<i class="fa fa-question" rel="tooltip" title="UNVERIFIED Vuln" style="color:#B40404;"></i>' if !verified
	return '<i class="fa fa-bug" rel="tooltip" title="False Positive" style="color:#8A6D3B;"></i>' if falsepos
end

- (String) status_text

Get HTML for formatted status text (verified, unverified, false positive) of this Vulnerability

Returns:

  • (String)

    HTML for status text



58
59
60
61
62
# File 'models/vulnerability.rb', line 58

def status_text
	return '<span style="color:#009933;">Verified Vuln</span>' if (verified && !falsepos)
	return '<span style="color:#B40404;">Unverified Vuln</span>' if !verified
	return '<span style="color:#8A6D3B;">False Positive</span>' if falsepos
end

- (Test) test

Returns Test this Vulnerability belongs to

Returns:

  • (Test)

    Test this Vulnerability belongs to



25
# File 'models/vulnerability.rb', line 25

belongs_to :test

- (Test) test=(resource)

Returns Test this Vulnerability belongs to

Returns:

  • (Test)

    Test this Vulnerability belongs to



25
# File 'models/vulnerability.rb', line 25

belongs_to :test

- (Integer) test_id

Returns ID of Test the Vulnerability belongs to

Returns:

  • (Integer)

    ID of Test the Vulnerability belongs to



14
# File 'models/vulnerability.rb', line 14

property :test_id,			Integer

- (Integer) test_id=(value)

Returns ID of Test the Vulnerability belongs to

Returns:

  • (Integer)

    ID of Test the Vulnerability belongs to



14
# File 'models/vulnerability.rb', line 14

property :test_id,			Integer

- (String) type_html

Get HTML of Vulnerability type description to use in generated reports

Returns:

  • (String)

    HTML description of Vulnerability type



67
68
69
70
71
72
# File 'models/vulnerability.rb', line 67

def type_html
	return nil if(vulntype == 0) 

	vt = VulnType.get(vulntype)
	return vt.html
end

- (String) type_str

Get Vulnerability type name (e.g. Stored XSS). Returns VulnType label if not custom, otherwise custom Vulnerability name. If the VulnType has no label, return the VulnType name

Returns:

  • (String)

    Vulnerability type name



39
40
41
42
43
44
# File 'models/vulnerability.rb', line 39

def type_str
	return custom if vulntype == 0

	vt = VulnType.get(vulntype)
	return (vt.label.nil? || vt.label.strip.empty?) ? vt.name : vt.label
end

- (DateTime) updated_at

Returns Date/Time Vulnerability last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability last updated (DM Handled)



18
# File 'models/vulnerability.rb', line 18

property :updated_at, 		DateTime

- (DateTime) updated_at=(value)

Returns Date/Time Vulnerability last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time Vulnerability last updated (DM Handled)



18
# File 'models/vulnerability.rb', line 18

property :updated_at, 		DateTime

- (Boolean) verified

Returns True if this vuln is verified

Returns:

  • (Boolean)

    True if this vuln is verified



19
# File 'models/vulnerability.rb', line 19

property :verified,			Boolean, :default => true

- (Boolean) verified=(value)

Returns True if this vuln is verified

Returns:

  • (Boolean)

    True if this vuln is verified



19
# File 'models/vulnerability.rb', line 19

property :verified,			Boolean, :default => true

- (VulnType) vtobj

Get the VulnType object that this Vulnerability uses

Returns:



31
32
33
# File 'models/vulnerability.rb', line 31

def vtobj
	return VulnType.get(self.vulntype)
end

- (VULN_PRIORITY) vuln_priority

Get priority of this vulnerability - either VulnType's priority or overridden priority level for this Vulnerability.

Returns:



89
90
91
92
93
94
95
# File 'models/vulnerability.rb', line 89

def vuln_priority
	vtPri = VulnType.get(vulntype).priority unless vulntype == 0

	return priorityOverride if(!priorityOverride.nil?)
	return VULN_PRIORITY::NONE if ((vulntype == 0 && priorityOverride.nil?) || vtPri.nil?)
	return vtPri
end

- (Integer) vulntype

Returns ID of VulnType this Vulnerability uses. 0 = Custom vulnerability

Returns:

  • (Integer)

    ID of VulnType this Vulnerability uses. 0 = Custom vulnerability



15
# File 'models/vulnerability.rb', line 15

property :vulntype, 		Integer

- (Integer) vulntype=(value)

Returns ID of VulnType this Vulnerability uses. 0 = Custom vulnerability

Returns:

  • (Integer)

    ID of VulnType this Vulnerability uses. 0 = Custom vulnerability



15
# File 'models/vulnerability.rb', line 15

property :vulntype, 		Integer