Class: SSHScan::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_scan/result.rb

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



9
10
11
12
13
14
# File 'lib/ssh_scan/result.rb', line 9

def initialize()
  @version = SSHScan::VERSION
  @keys = nil
  @duplicate_host_key_ips = Set.new()
  @compliance = {}
end

Instance Method Details

#auth_methodsObject



184
185
186
# File 'lib/ssh_scan/result.rb', line 184

def auth_methods()
  @auth_methods || []
end

#auth_methods=(auth_methods) ⇒ Object



156
157
158
# File 'lib/ssh_scan/result.rb', line 156

def auth_methods=(auth_methods)
  @auth_methods = auth_methods
end


44
45
46
# File 'lib/ssh_scan/result.rb', line 44

def banner()
  @banner || SSHScan::Banner.new("")
end

#banner=(banner) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/ssh_scan/result.rb', line 56

def banner=(banner)
  unless banner.is_a?(SSHScan::Banner)
    raise ArgumentError, "Invalid attempt to set banner with a non-banner object"
  end

  @banner = banner
end

#compliance_policyObject



192
193
194
# File 'lib/ssh_scan/result.rb', line 192

def compliance_policy
  @compliance["policy"]
end

#compliance_recommendationsObject



204
205
206
# File 'lib/ssh_scan/result.rb', line 204

def compliance_recommendations
  @compliance["recommendations"]
end

#compliance_referencesObject



200
201
202
# File 'lib/ssh_scan/result.rb', line 200

def compliance_references
  @compliance["references"]
end

#compliant?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/ssh_scan/result.rb', line 196

def compliant?
  @compliance["compliant"]
end

#compression_algorithms_client_to_serverObject



112
113
114
# File 'lib/ssh_scan/result.rb', line 112

def compression_algorithms_client_to_server
  @hex_result_hash ? @hex_result_hash[:compression_algorithms_client_to_server] : []
end

#compression_algorithms_server_to_clientObject



116
117
118
# File 'lib/ssh_scan/result.rb', line 116

def compression_algorithms_server_to_client
  @hex_result_hash ? @hex_result_hash[:compression_algorithms_server_to_client] : []
end


84
85
86
# File 'lib/ssh_scan/result.rb', line 84

def cookie
  @cookie || ""
end

#dns_keysObject



168
169
170
# File 'lib/ssh_scan/result.rb', line 168

def dns_keys
  @dns_keys
end

#dns_keys=(dns_keys) ⇒ Object



172
173
174
# File 'lib/ssh_scan/result.rb', line 172

def dns_keys=(dns_keys)
  @dns_keys = dns_keys
end

#duplicate_host_key_ipsObject



180
181
182
# File 'lib/ssh_scan/result.rb', line 180

def duplicate_host_key_ips
  @duplicate_host_key_ips.to_a
end

#duplicate_host_key_ips=(duplicate_host_key_ips) ⇒ Object



176
177
178
# File 'lib/ssh_scan/result.rb', line 176

def duplicate_host_key_ips=(duplicate_host_key_ips)
  @duplicate_host_key_ips = duplicate_host_key_ips
end

#encryption_algorithms_client_to_serverObject



96
97
98
# File 'lib/ssh_scan/result.rb', line 96

def encryption_algorithms_client_to_server
  @hex_result_hash ? @hex_result_hash[:encryption_algorithms_client_to_server] : []
end

#encryption_algorithms_server_to_clientObject



100
101
102
# File 'lib/ssh_scan/result.rb', line 100

def encryption_algorithms_server_to_client
  @hex_result_hash ? @hex_result_hash[:encryption_algorithms_server_to_client] : []
end

#end_timeObject



152
153
154
# File 'lib/ssh_scan/result.rb', line 152

def end_time
  @end_time
end

#errorObject



226
227
228
# File 'lib/ssh_scan/result.rb', line 226

def error
  @error
end

#error=(error) ⇒ Object



214
215
216
# File 'lib/ssh_scan/result.rb', line 214

def error=(error)
  @error = error.to_s
end

#error?Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/ssh_scan/result.rb', line 222

def error?
  !@error.nil?
end

#gradeObject



234
235
236
# File 'lib/ssh_scan/result.rb', line 234

def grade
  @compliance["grade"] 
end

#grade=(grade) ⇒ Object



230
231
232
# File 'lib/ssh_scan/result.rb', line 230

def grade=(grade)
  @compliance["grade"] = grade
end

#hostnameObject



52
53
54
# File 'lib/ssh_scan/result.rb', line 52

def hostname()
  @hostname || ""
end

#hostname=(hostname) ⇒ Object



48
49
50
# File 'lib/ssh_scan/result.rb', line 48

def hostname=(hostname)
  @hostname = hostname
end

#ipObject



20
21
22
# File 'lib/ssh_scan/result.rb', line 20

def ip
  @ip
end

#ip=(ip) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ssh_scan/result.rb', line 24

def ip=(ip)
  unless ip.is_a?(String) && ip.ip_addr?
    raise ArgumentError, "Invalid attempt to set IP to a non-IP address value"
  end

  @ip = ip
end

#key_algorithmsObject



88
89
90
# File 'lib/ssh_scan/result.rb', line 88

def key_algorithms
  @hex_result_hash ? @hex_result_hash[:key_algorithms] : []
end

#keysObject



160
161
162
# File 'lib/ssh_scan/result.rb', line 160

def keys
  @keys || {}
end

#keys=(keys) ⇒ Object



164
165
166
# File 'lib/ssh_scan/result.rb', line 164

def keys=(keys)
  @keys = keys
end

#languages_client_to_serverObject



120
121
122
# File 'lib/ssh_scan/result.rb', line 120

def languages_client_to_server
  @hex_result_hash ? @hex_result_hash[:languages_client_to_server] : []
end

#languages_server_to_clientObject



124
125
126
# File 'lib/ssh_scan/result.rb', line 124

def languages_server_to_client
  @hex_result_hash ? @hex_result_hash[:languages_server_to_client] : []
end

#mac_algorithms_client_to_serverObject



104
105
106
# File 'lib/ssh_scan/result.rb', line 104

def mac_algorithms_client_to_server
  @hex_result_hash ? @hex_result_hash[:mac_algorithms_client_to_server] : []
end

#mac_algorithms_server_to_clientObject



108
109
110
# File 'lib/ssh_scan/result.rb', line 108

def mac_algorithms_server_to_client
  @hex_result_hash ? @hex_result_hash[:mac_algorithms_server_to_client] : []
end

#os_guess_commonObject



68
69
70
# File 'lib/ssh_scan/result.rb', line 68

def os_guess_common
  self.banner.os_guess.common
end

#os_guess_cpeObject



72
73
74
# File 'lib/ssh_scan/result.rb', line 72

def os_guess_cpe
  self.banner.os_guess.cpe
end

#portObject



32
33
34
# File 'lib/ssh_scan/result.rb', line 32

def port
  @port
end

#port=(port) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/ssh_scan/result.rb', line 36

def port=(port)
  unless port.is_a?(Integer) && port > 0 && port <= 65535
    raise ArgumentError, "Invalid attempt to set port to a non-port value"
  end

  @port = port
end

#scan_durationObject



144
145
146
147
148
149
150
# File 'lib/ssh_scan/result.rb', line 144

def scan_duration
  if start_time.nil? || end_time.nil?
    return nil
  end

  end_time - start_time
end

#server_host_key_algorithmsObject



92
93
94
# File 'lib/ssh_scan/result.rb', line 92

def server_host_key_algorithms
  @hex_result_hash ? @hex_result_hash[:server_host_key_algorithms] : []
end

#set_client_attributes(client) ⇒ Object



208
209
210
211
212
# File 'lib/ssh_scan/result.rb', line 208

def set_client_attributes(client)
  self.ip = client.ip
  self.port = client.port || 22
  self.banner = client.banner || SSHScan::Banner.new("")
end

#set_compliance=(compliance) ⇒ Object



188
189
190
# File 'lib/ssh_scan/result.rb', line 188

def set_compliance=(compliance)
  @compliance = compliance
end

#set_end_timeObject



140
141
142
# File 'lib/ssh_scan/result.rb', line 140

def set_end_time
  @end_time = Time.now
end

#set_kex_result(kex_result) ⇒ Object



128
129
130
# File 'lib/ssh_scan/result.rb', line 128

def set_kex_result(kex_result)
  @hex_result_hash = kex_result.to_hash
end

#set_start_timeObject



132
133
134
# File 'lib/ssh_scan/result.rb', line 132

def set_start_time
  @start_time = Time.now
end

#ssh_lib_guess_commonObject



76
77
78
# File 'lib/ssh_scan/result.rb', line 76

def ssh_lib_guess_common
  self.banner.ssh_lib_guess.common
end

#ssh_lib_guess_cpeObject



80
81
82
# File 'lib/ssh_scan/result.rb', line 80

def ssh_lib_guess_cpe
  self.banner.ssh_lib_guess.cpe
end

#ssh_versionObject



64
65
66
# File 'lib/ssh_scan/result.rb', line 64

def ssh_version
  self.banner.ssh_version
end

#start_timeObject



136
137
138
# File 'lib/ssh_scan/result.rb', line 136

def start_time
  @start_time
end

#to_hashObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/ssh_scan/result.rb', line 238

def to_hash
  hashed_object = {
  	"ssh_scan_version" => self.version,
  	"ip" => self.ip,
    "hostname" => self.hostname,
  	"port" => self.port,
  	"server_banner" => self.banner.to_s,
  	"ssh_version" => self.ssh_version,
  	"os" => self.os_guess_common,
  	"os_cpe" => self.os_guess_cpe,
  	"ssh_lib" => self.ssh_lib_guess_common,
  	"ssh_lib_cpe" => self.ssh_lib_guess_cpe,
  	"key_algorithms" => self.key_algorithms,
  	"encryption_algorithms_client_to_server" => self.encryption_algorithms_client_to_server,
  	"encryption_algorithms_server_to_client" => self.encryption_algorithms_server_to_client,
  	"mac_algorithms_client_to_server" => self.mac_algorithms_client_to_server,
  	"mac_algorithms_server_to_client" => self.mac_algorithms_server_to_client,
  	"compression_algorithms_client_to_server" => self.compression_algorithms_client_to_server,
  	"compression_algorithms_server_to_client" => self.compression_algorithms_server_to_client,
  	"languages_client_to_server" => self.languages_client_to_server,
  	"languages_server_to_client" => self.languages_server_to_client,
  	"auth_methods" => self.auth_methods,
    "keys" => self.keys,
    "dns_keys" => self.dns_keys,
    "duplicate_host_key_ips" => self.duplicate_host_key_ips.uniq,
  	"compliance" => @compliance,
    "start_time" => self.start_time,
    "end_time" => self.end_time,
    "scan_duration_seconds" => self.scan_duration,
  }

  if self.error?
    hashed_object["error"] = self.error
  end

  hashed_object
end

#to_jsonObject



276
277
278
# File 'lib/ssh_scan/result.rb', line 276

def to_json
  self.to_hash.to_json
end

#unset_errorObject



218
219
220
# File 'lib/ssh_scan/result.rb', line 218

def unset_error
  @error = nil
end

#versionObject



16
17
18
# File 'lib/ssh_scan/result.rb', line 16

def version
  @version
end