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,
'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

#blobObject

Security blob for an existing set of credentials



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

def blob
  @blob
end

#headersObject

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



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

def headers
  @headers
end

#hostObject

The host for these credentials. Can be Any.



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

def host
  @host
end

#html_formsObject

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



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

def html_forms
  @html_forms
end

#passwordObject

The password



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

def password
  @password
end

#portObject

The port on which to use these credentials.



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

def port
  @port
end

#priv_passwordObject

The password to use when escalating privileges (optional)



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

def priv_password
  @priv_password
end

#priv_typeObject

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



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

def priv_type
  @priv_type
end

#priv_usernameObject

The userid to use when escalating privileges (optional)



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

def priv_username
  @priv_username
end

#realmObject

The realm for these credentials



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

def realm
  @realm
end

#serviceObject

The service for these credentials. Can be All.



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

def service
  @service
end

#useridObject

The user id or username



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

def userid
  @userid
end

Class Method Details

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



59
60
61
62
63
64
65
66
67
68
# File 'lib/nexpose/creds.rb', line 59

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



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

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



113
114
115
# File 'lib/nexpose/creds.rb', line 113

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.



71
72
73
74
75
# File 'lib/nexpose/creds.rb', line 71

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

#as_xmlObject Also known as: to_xml_elem



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/nexpose/creds.rb', line 90

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

  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)


117
118
119
# File 'lib/nexpose/creds.rb', line 117

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

#hashObject



121
122
123
# File 'lib/nexpose/creds.rb', line 121

def hash
  to_xml.hash
end

#to_xmlObject



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

def to_xml
  to_xml_elem.to_s
end