Class: Nexpose::AdminCredentials

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XMLUtils

#make_xml, #parse_xml

Constructor Details

#initialize(isblob = false) ⇒ AdminCredentials

Returns a new instance of AdminCredentials.



40
41
42
# File 'lib/nexpose/creds.rb', line 40

def initialize(isblob = false)
  @isblob = isblob
end

Instance Attribute Details

#headersObject

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



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

def headers
  @headers
end

#hostObject

The host for these credentials. Can be Any.



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

def host
  @host
end

#html_formsObject

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



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

def html_forms
  @html_forms
end

#isblobObject

Designates if this object contains user defined credentials or a security blob



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

def isblob
  @isblob
end

#passwordObject

The password



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

def password
  @password
end

#portObject

The port on which to use these credentials.



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

def port
  @port
end

#priv_passwordObject

The password to use when escalating privileges (optional)



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

def priv_password
  @priv_password
end

#priv_typeObject

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



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

def priv_type
  @priv_type
end

#priv_usernameObject

The userid to use when escalating privileges (optional)



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

def priv_username
  @priv_username
end

#realmObject

The realm for these credentials



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

def realm
  @realm
end

#securityblobObject

Security blob for an existing set of credentials



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

def securityblob
  @securityblob
end

#serviceObject

The service for these credentials. Can be All.



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

def service
  @service
end

#useridObject

The user id or username



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

def userid
  @userid
end

Class Method Details

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



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

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

Instance Method Details

#<=>(other) ⇒ Object



129
130
131
# File 'lib/nexpose/creds.rb', line 129

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/nexpose/creds.rb', line 133

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

#hashObject



137
138
139
# File 'lib/nexpose/creds.rb', line 137

def hash
  to_xml.hash
end

#set_blob(securityblob) ⇒ Object

Credentials fetched from the API are encrypted into a securityblob. If you want to use those credentials on a different site, copy the blob into the credential.



88
89
90
91
# File 'lib/nexpose/creds.rb', line 88

def set_blob(securityblob)
  @isblob = true
  @securityblob = securityblob
end

#set_credentials(service, host, port, userid, password, realm) ⇒ Object

Sets the credentials information for this object.



45
46
47
48
49
50
51
52
53
54
# File 'lib/nexpose/creds.rb', line 45

def set_credentials(service, host, port, userid, password, realm)
  @isblob = false
  @securityblob = nil
  @service = service
  @host = host
  @port = port
  @userid = userid
  @password = password
  @realm = realm
end

#set_headers(headers) ⇒ Object

Add Headers to credentials for httpheaders.



94
95
96
# File 'lib/nexpose/creds.rb', line 94

def set_headers(headers)
  @headers = headers
end

#set_host(host) ⇒ Object



81
82
83
# File 'lib/nexpose/creds.rb', line 81

def set_host(host)
  @host = host
end

#set_html_forms(html_forms) ⇒ Object



98
99
100
# File 'lib/nexpose/creds.rb', line 98

def set_html_forms(html_forms)
  @html_forms = html_forms
end

#set_privilege_credentials(type, username, password) ⇒ Object

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



69
70
71
72
73
# File 'lib/nexpose/creds.rb', line 69

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

#set_service(service) ⇒ Object

The name of the service. Possible values are outlined in the Nexpose API docs.



77
78
79
# File 'lib/nexpose/creds.rb', line 77

def set_service(service)
  @service = service
end

#to_xmlObject



102
103
104
# File 'lib/nexpose/creds.rb', line 102

def to_xml
  to_xml_elem.to_s
end

#to_xml_elemObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/nexpose/creds.rb', line 106

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

  data = isblob ? securityblob : ''
  xml = make_xml('adminCredentials', attributes, data)
  xml.add_element(@headers.to_xml_elem) if @headers
  xml.add_element(@html_forms.to_xml_elem) if @html_forms
  xml
end