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

Constant Summary collapse

DEFAULT_PORTS =
{ 'cvs' => 2401,
'ftp' => 21,
'http' => 80,
'as400' => 449,
'notes' => 1352,
'tds' => 1433,
'sybase' => 5000,
'cifs' => 445,
'cifshash' => 445,
'oracle' => 1521,
'pop' => 110,
'postgresql' => 5432,
'remote execution' => 512,
'snmp' => 161,
'snmpv3' => 161,
'ssh' => 22,
'ssh-key' => 22,
'telnet' => 23,
'mysql' => 3306,
'db2' => 50000 }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XMLUtils

#make_xml, #parse_xml

Instance Attribute Details

#auth_typeObject

The authentication type to use with SNMP v3 credentials



60
61
62
# File 'lib/nexpose/creds.rb', line 60

def auth_type
  @auth_type
end

#blobObject

Security blob for an existing set of credentials



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

def blob
  @blob
end

#headersObject

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



49
50
51
# File 'lib/nexpose/creds.rb', line 49

def headers
  @headers
end

#hostObject

The host for these credentials.



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

def host
  @host
end

#html_formsObject

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



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

def html_forms
  @html_forms
end

#passwordObject

The password



44
45
46
# File 'lib/nexpose/creds.rb', line 44

def password
  @password
end

#portObject

The port on which to use these credentials.



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

def port
  @port
end

#priv_passwordObject

The password to use when escalating privileges (optional)



58
59
60
# File 'lib/nexpose/creds.rb', line 58

def priv_password
  @priv_password
end

#priv_typeObject

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



54
55
56
# File 'lib/nexpose/creds.rb', line 54

def priv_type
  @priv_type
end

#priv_usernameObject

The userid to use when escalating privileges (optional)



56
57
58
# File 'lib/nexpose/creds.rb', line 56

def priv_username
  @priv_username
end

#privacy_passwordObject

The privacy/encryption pass phrase to use with SNMP v3 credentials



64
65
66
# File 'lib/nexpose/creds.rb', line 64

def privacy_password
  @privacy_password
end

#privacy_typeObject

The privacy/encryption type to use with SNMP v3 credentials



62
63
64
# File 'lib/nexpose/creds.rb', line 62

def privacy_type
  @privacy_type
end

#realmObject

The realm for these credentials



46
47
48
# File 'lib/nexpose/creds.rb', line 46

def realm
  @realm
end

#serviceObject

The service for these credentials.



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

def service
  @service
end

#useridObject

The user id or username



42
43
44
# File 'lib/nexpose/creds.rb', line 42

def userid
  @userid
end

Class Method Details

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



66
67
68
69
70
71
72
73
74
75
# File 'lib/nexpose/creds.rb', line 66

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



90
91
92
93
94
95
96
97
# File 'lib/nexpose/creds.rb', line 90

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



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

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.



78
79
80
81
82
# File 'lib/nexpose/creds.rb', line 78

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

#add_snmpv3_credentials(auth_type, privacy_type, privacy_password) ⇒ Object



84
85
86
87
88
# File 'lib/nexpose/creds.rb', line 84

def add_snmpv3_credentials(auth_type, privacy_type, privacy_password)
  @auth_type = auth_type
  @privacy_type = privacy_type
  @privacy_password = privacy_password
end

#as_xmlObject Also known as: to_xml_elem



103
104
105
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 103

def as_xml
  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
  
  attributes['snmpv3authtype'] = @auth_type if @auth_type
  attributes['snmpv3privtype'] = @privacy_type if @privacy_type
  attributes['snmpv3privpassword'] = @privacy_password if @privacy_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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  to_xml.hash
end

#to_xmlObject



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

def to_xml
  to_xml_elem.to_s
end