@@ -8,43 +8,70 @@ module LoginScanner
8
8
class Result
9
9
include ActiveModel ::Validations
10
10
11
- # @!attribute [r] access_level
11
+ # @!attribute access_level
12
12
# @return [String] the access level gained
13
- attr_reader :access_level
14
- # @!attribute [r] credential
13
+ attr_accessor :access_level
14
+ # @!attribute credential
15
15
# @return [Credential] the Credential object the result is for
16
- attr_reader :credential
17
- # @!attribute [r] proof
18
- # @return [String,nil] the proof that the lgoin was successful
19
- attr_reader :proof
20
- # @!attribute [r] status
16
+ attr_accessor :credential
17
+ # @!attribute host
18
+ # @return [String] the addess of the target host for this result
19
+ attr_accessor :host
20
+ # @!attribute port
21
+ # @return [Fixnum] the port number of the service for this result
22
+ attr_accessor :port
23
+ # @!attribute proof
24
+ # @return [String,nil] the proof that the login was successful
25
+ attr_accessor :proof
26
+ # @!attribute protocol
27
+ # @return [String] the transport protocol used for this result (tcp/udp)
28
+ attr_accessor :protocol
29
+ # @!attribute service_name
30
+ # @return [String] the name to give the service for this result
31
+ attr_accessor :service_name
32
+ # @!attribute status
21
33
# @return [String] the status of the attempt. Should be a member of `Metasploit::Model::Login::Status::ALL`
22
- attr_reader :status
34
+ attr_accessor :status
23
35
24
36
validates :status ,
25
37
inclusion : {
26
38
in : Metasploit ::Model ::Login ::Status ::ALL
27
39
}
28
40
29
- # @param [Hash] opts The options hash for the initializer
30
- # @option opts [String] :private The private credential component
31
- # @option opts [String] :proof The proof that the login was successful
32
- # @option opts [String] :public The public credential component
33
- # @option opts [String] :realm The realm credential component
34
- # @option opts [String] :status The status code returned
35
- def initialize ( opts = { } )
36
- @access_level = opts . fetch ( :access_level , nil )
37
- @credential = opts . fetch ( :credential )
38
- @proof = opts . fetch ( :proof , nil )
39
- @status = opts . fetch ( :status )
41
+ # @param attributes [Hash{Symbol => String,nil}]
42
+ def initialize ( attributes = { } )
43
+ attributes . each do |attribute , value |
44
+ public_send ( "#{ attribute } =" , value )
45
+ end
46
+ end
47
+
48
+ def inspect
49
+ "#<#{ self . class } #{ credential . public } :#{ credential . private } @#{ credential . realm } #{ status } >"
40
50
end
41
51
42
52
def success?
43
53
status == Metasploit ::Model ::Login ::Status ::SUCCESSFUL
44
54
end
45
55
46
- def inspect
47
- "#<#{ self . class } #{ credential . public } :#{ credential . private } @#{ credential . realm } #{ status } >"
56
+ # This method takes all the data inside the Result object
57
+ # and spits out a hash compatible with #create_credential
58
+ # and #create_credential_login.
59
+ #
60
+ # @return [Hash] the hash to use with #create_credential and #create_credential_login
61
+ def to_h
62
+ result_hash = credential . to_h
63
+ result_hash . merge! (
64
+ access_level : access_level ,
65
+ address : host ,
66
+ last_attempted_at : DateTime . now ,
67
+ origin_type : :service ,
68
+ port : port ,
69
+ proof : proof ,
70
+ protocol : protocol ,
71
+ service_name : service_name ,
72
+ status : status
73
+ )
74
+ result_hash . delete_if { |k , v | v . nil? }
48
75
end
49
76
50
77
end
0 commit comments