Class: Nexpose::Credential

Inherits:
Object
  • Object
show all
Includes:
Comparable, XMLUtils
Defined in:
lib/nexpose/creds.rb

Overview

Object that represents administrative credentials to be used during a scan. When retrieved from an existing site configuration the credentials will be returned as a security blob and can only be passed back as is during a Site Save operation. This object can only be used to create a new set of credentials.

Defined Under Namespace

Modules: ElevationType, Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XMLUtils

#make_xml, #parse_xml

Instance Attribute Details

#blobObject

Security blob for an existing set of credentials



13
14
15
# File 'lib/nexpose/creds.rb', line 13

def blob
  @blob
end

#headersObject

When using httpheaders, this represents the set of headers to pass with the authentication request.



28
29
30
# File 'lib/nexpose/creds.rb', line 28

def headers
  @headers
end

#hostObject

The host for these credentials. Can be Any.



17
18
19
# File 'lib/nexpose/creds.rb', line 17

def host
  @host
end

#html_formsObject

When using htmlforms, this represents the tho form to pass the authentication request to.



31
32
33
# File 'lib/nexpose/creds.rb', line 31

def html_forms
  @html_forms
end

#passwordObject

The password



23
24
25
# File 'lib/nexpose/creds.rb', line 23

def password
  @password
end

#portObject

The port on which to use these credentials.



19
20
21
# File 'lib/nexpose/creds.rb', line 19

def port
  @port
end

#priv_passwordObject

The password to use when escalating privileges (optional)



37
38
39
# File 'lib/nexpose/creds.rb', line 37

def priv_password
  @priv_password
end

#priv_typeObject

The type of privilege escalation to use (sudo/su)



33
34
35
# File 'lib/nexpose/creds.rb', line 33

def priv_type
  @priv_type
end

#priv_usernameObject

The userid to use when escalating privileges (optional)



35
36
37
# File 'lib/nexpose/creds.rb', line 35

def priv_username
  @priv_username
end

#realmObject

The realm for these credentials



25
26
27
# File 'lib/nexpose/creds.rb', line 25

def realm
  @realm
end

#serviceObject

The service for these credentials. Can be All.



15
16
17
# File 'lib/nexpose/creds.rb', line 15

def service
  @service
end

#useridObject

The user id or username



21
22
23
# File 'lib/nexpose/creds.rb', line 21

def userid
  @userid
end

Class Method Details

.for_service(service, user, password, realm = nil, host = nil, port = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/nexpose/creds.rb', line 39

def self.for_service(service, user, password, realm = nil, host = nil, port = nil)
  cred = new
  cred.service = service
  cred.userid = user
  cred.password = password
  cred.realm = realm
  cred.host = host
  cred.port = port
  cred
end

.parse(xml) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/nexpose/creds.rb', line 57

def self.parse(xml)
  cred = new
  cred.service = xml.attributes['service']
  cred.host = xml.attributes['host']
  cred.port = xml.attributes['port']
  cred.blob = xml.get_text
  cred
end

Instance Method Details

#<=>(other) ⇒ Object



92
93
94
# File 'lib/nexpose/creds.rb', line 92

def <=>(other)
  to_xml <=> other.to_xml
end

#add_privilege_credentials(type, username, password) ⇒ Object

Sets privilege escalation credentials. Type should be either sudo/su.



51
52
53
54
55
# File 'lib/nexpose/creds.rb', line 51

def add_privilege_credentials(type, username, password)
  @priv_type = type
  @priv_username = username
  @priv_password = password
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/nexpose/creds.rb', line 96

def eql?(other)
  to_xml == other.to_xml
end

#hashObject



100
101
102
# File 'lib/nexpose/creds.rb', line 100

def hash
  to_xml.hash
end

#to_xmlObject



66
67
68
# File 'lib/nexpose/creds.rb', line 66

def to_xml
  to_xml_elem.to_s
end

#to_xml_elemObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/nexpose/creds.rb', line 70

def to_xml_elem
  attributes = {}

  attributes['service'] = @service
  attributes['userid'] = @userid
  attributes['password'] = @password
  attributes['realm'] = @realm
  attributes['host'] = @host
  attributes['port'] = @port

  attributes['privilegeelevationtype'] = @priv_type if @priv_type
  attributes['privilegeelevationusername'] = @priv_username if @priv_username
  attributes['privilegeelevationpassword'] = @priv_password if @priv_password

  xml = make_xml('adminCredentials', attributes, blob)
  xml.add_element(@headers.to_xml_elem) if @headers
  xml.add_element(@html_forms.to_xml_elem) if @html_forms
  xml
end