@@ -31,41 +31,42 @@ def initialize(info = {})
31
31
# advanced option is set to true.
32
32
#
33
33
def on_session ( session )
34
- super
35
-
36
- # Defer the session initialization to the Session Manager scheduler
37
- framework . sessions . schedule Proc . new {
38
-
39
- # Configure unicode encoding before loading stdapi
40
- session . encode_unicode = datastore [ 'EnableUnicodeEncoding' ]
41
-
42
- session . init_ui ( self . user_input , self . user_output )
43
-
44
- valid = true
45
-
46
- session . tlv_enc_key = session . core . negotiate_tlv_encryption
47
-
48
- if datastore [ 'AutoVerifySession' ]
49
- if not session . is_valid_session? ( datastore [ 'AutoVerifySessionTimeout' ] . to_i )
50
- print_error ( "Meterpreter session #{ session . sid } is not valid and will be closed" )
51
- valid = false
34
+ init_session = Proc . new do
35
+ # Configure unicode encoding before loading stdapi
36
+ session . encode_unicode = datastore [ 'EnableUnicodeEncoding' ]
37
+
38
+ session . init_ui ( self . user_input , self . user_output )
39
+
40
+ print_good ( "negotiating tlv encryption" )
41
+ session . tlv_enc_key = session . core . negotiate_tlv_encryption
42
+ print_good ( "negotiated tlv encryption" )
43
+
44
+ if datastore [ 'AutoVerifySession' ]
45
+ if ! session . is_valid_session? ( datastore [ 'AutoVerifySessionTimeout' ] . to_i )
46
+ print_error ( "Meterpreter session #{ session . sid } is not valid and will be closed" )
47
+ # Terminate the session without cleanup if it did not validate
48
+ session . skip_cleanup = true
49
+ session . kill
50
+ return nil
51
+ end
52
52
end
53
- end
53
+ print_good ( "negotiated tlv encryption" )
54
54
55
- if valid
56
55
# always make sure that the new session has a new guid if it's not already known
57
56
guid = session . session_guid
58
57
if guid == '00000000-0000-0000-0000-000000000000'
59
58
guid = SecureRandom . uuid
60
59
session . core . set_session_guid ( guid )
61
60
session . session_guid = guid
62
- # TODO: New statgeless session, do some account in the DB so we can track it later.
61
+ # TODO: New stageless session, do some account in the DB so we can track it later.
63
62
else
64
63
# TODO: This session was either staged or previously known, and so we shold do some accounting here!
65
64
end
66
65
67
- if datastore [ 'AutoLoadStdapi' ]
66
+ # Call registered on_session callbacks
67
+ super
68
68
69
+ if datastore [ 'AutoLoadStdapi' ]
69
70
session . load_stdapi
70
71
71
72
if datastore [ 'AutoSystemInfo' ]
@@ -91,16 +92,9 @@ def on_session(session)
91
92
end
92
93
end
93
94
94
- # Terminate the session without cleanup if it did not validate
95
- if not valid
96
- session . skip_cleanup = true
97
- session . kill
98
- end
99
-
100
- }
101
-
95
+ # Defer the session initialization to the Session Manager scheduler
96
+ framework . sessions . schedule init_session
102
97
end
103
-
104
98
end
105
99
end
106
100
end
0 commit comments