Class: Msf::Plugin::SessionNotifier::SessionNotifierCommandDispatcher
Instance Attribute Summary collapse
#driver
#shell, #tab_complete_items
Instance Method Summary
collapse
#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #load_config, #log_error, #remove_lines
#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt
Constructor Details
Returns a new instance of SessionNotifierCommandDispatcher.
56
57
58
59
|
# File 'plugins/session_notifier.rb', line 56
def initialize(driver)
super(driver)
load_settings_from_config
end
|
Instance Attribute Details
#dingtalk_webhook ⇒ Object
Returns the value of attribute dingtalk_webhook.
25
26
27
|
# File 'plugins/session_notifier.rb', line 25
def dingtalk_webhook
@dingtalk_webhook
end
|
#gotify_address ⇒ Object
Returns the value of attribute gotify_address.
26
27
28
|
# File 'plugins/session_notifier.rb', line 26
def gotify_address
@gotify_address
end
|
#gotify_sslcert_path ⇒ Object
Returns the value of attribute gotify_sslcert_path.
27
28
29
|
# File 'plugins/session_notifier.rb', line 27
def gotify_sslcert_path
@gotify_sslcert_path
end
|
#maximum_ip ⇒ Object
Returns the value of attribute maximum_ip.
24
25
26
|
# File 'plugins/session_notifier.rb', line 24
def maximum_ip
@maximum_ip
end
|
#minimum_ip ⇒ Object
Returns the value of attribute minimum_ip.
23
24
25
|
# File 'plugins/session_notifier.rb', line 23
def minimum_ip
@minimum_ip
end
|
#serverjang_webhook ⇒ Object
Returns the value of attribute serverjang_webhook.
28
29
30
|
# File 'plugins/session_notifier.rb', line 28
def serverjang_webhook
@serverjang_webhook
end
|
#sms_carrier ⇒ Object
Returns the value of attribute sms_carrier.
16
17
18
|
# File 'plugins/session_notifier.rb', line 16
def sms_carrier
@sms_carrier
end
|
#sms_client ⇒ Object
Returns the value of attribute sms_client.
15
16
17
|
# File 'plugins/session_notifier.rb', line 15
def sms_client
@sms_client
end
|
#sms_number ⇒ Object
Returns the value of attribute sms_number.
17
18
19
|
# File 'plugins/session_notifier.rb', line 17
def sms_number
@sms_number
end
|
#smtp_address ⇒ Object
Returns the value of attribute smtp_address.
18
19
20
|
# File 'plugins/session_notifier.rb', line 18
def smtp_address
@smtp_address
end
|
#smtp_from ⇒ Object
Returns the value of attribute smtp_from.
22
23
24
|
# File 'plugins/session_notifier.rb', line 22
def smtp_from
@smtp_from
end
|
#smtp_password ⇒ Object
Returns the value of attribute smtp_password.
21
22
23
|
# File 'plugins/session_notifier.rb', line 21
def smtp_password
@smtp_password
end
|
#smtp_port ⇒ Object
Returns the value of attribute smtp_port.
19
20
21
|
# File 'plugins/session_notifier.rb', line 19
def smtp_port
@smtp_port
end
|
#smtp_username ⇒ Object
Returns the value of attribute smtp_username.
20
21
22
|
# File 'plugins/session_notifier.rb', line 20
def smtp_username
@smtp_username
end
|
Instance Method Details
#cmd_restart_session_notifier(*args) ⇒ Object
210
211
212
213
|
# File 'plugins/session_notifier.rb', line 210
def cmd_restart_session_notifier(*args)
cmd_stop_session_notifier(args)
cmd_start_session_notifier(args)
end
|
#cmd_save_session_notifier_settings(*_args) ⇒ Object
166
167
168
169
|
# File 'plugins/session_notifier.rb', line 166
def cmd_save_session_notifier_settings(*_args)
save_settings_to_config
print_status('Session Notifier settings saved in config file.')
end
|
#cmd_set_session_dingtalk_webhook(*args) ⇒ Object
144
145
146
147
148
149
150
151
152
153
|
# File 'plugins/session_notifier.rb', line 144
def cmd_set_session_dingtalk_webhook(*args)
webhook_url = args[0]
if webhook_url.blank?
@dingtalk_webhook = nil
elsif !(webhook_url =~ URI::DEFAULT_PARSER.make_regexp).nil?
@dingtalk_webhook = webhook_url
else
print_error('Invalid webhook_url')
end
end
|
#cmd_set_session_gotify_address(*args) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'plugins/session_notifier.rb', line 121
def cmd_set_session_gotify_address(*args)
webhook_url = args[0]
if webhook_url.blank?
@gotify_address = nil
elsif !(webhook_url =~ URI::DEFAULT_PARSER.make_regexp).nil?
@gotify_address = webhook_url
else
@gotify_address = nil
print_error('Invalid gotify_address')
end
end
|
#cmd_set_session_gotify_sslcert_path(*args) ⇒ Object
133
134
135
136
137
138
139
140
141
142
|
# File 'plugins/session_notifier.rb', line 133
def cmd_set_session_gotify_sslcert_path(*args)
cert_path = args[0]
if !cert_path.blank? && ::File.file?(cert_path) && ::File.readable?(cert_path)
@gotify_sslcert_path = cert_path
print_status("Set Gotify ssl_mode ON! Your cert path is #{gotify_sslcert_path}")
else
@gotify_sslcert_path = nil
print_status('Set Gotify ssl_mode OFF!')
end
end
|
#cmd_set_session_maximum_ip(*args) ⇒ Object
110
111
112
113
114
115
116
117
118
119
|
# File 'plugins/session_notifier.rb', line 110
def cmd_set_session_maximum_ip(*args)
ip = args[0]
if ip.blank?
@maximum_ip = nil
elsif Rex::Socket.self.dotted_ip?(ip)
@maximum_ip = IPAddr.new(ip)
else
print_error('Invalid IP format')
end
end
|
#cmd_set_session_minimum_ip(*args) ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'plugins/session_notifier.rb', line 99
def cmd_set_session_minimum_ip(*args)
ip = args[0]
if ip.blank?
@minimum_ip = nil
elsif Rex::Socket.dotted_ip?(ip)
@minimum_ip = IPAddr.new(ip)
else
print_error('Invalid IP format')
end
end
|
#cmd_set_session_mobile_carrier(*args) ⇒ Object
95
96
97
|
# File 'plugins/session_notifier.rb', line 95
def cmd_set_session_mobile_carrier(*args)
@sms_carrier = args[0].to_sym
end
|
#cmd_set_session_mobile_number(*args) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'plugins/session_notifier.rb', line 86
def cmd_set_session_mobile_number(*args)
num = args[0]
if num =~ /^\d{10}$/
@sms_number = args[0]
else
print_error('Invalid phone format. It should be a 10-digit number that looks like: XXXXXXXXXX')
end
end
|
#cmd_set_session_serverjang_webhook(*args) ⇒ Object
155
156
157
158
159
160
161
162
163
164
|
# File 'plugins/session_notifier.rb', line 155
def cmd_set_session_serverjang_webhook(*args)
webhook_url = args[0]
if webhook_url.blank?
@serverjang_webhook = nil
elsif !(webhook_url =~ URI::DEFAULT_PARSER.make_regexp).nil?
@serverjang_webhook = webhook_url
else
print_error('Invalid webhook_url')
end
end
|
#cmd_set_session_smtp_address(*args) ⇒ Object
61
62
63
|
# File 'plugins/session_notifier.rb', line 61
def cmd_set_session_smtp_address(*args)
@smtp_address = args[0]
end
|
#cmd_set_session_smtp_from(*args) ⇒ Object
82
83
84
|
# File 'plugins/session_notifier.rb', line 82
def cmd_set_session_smtp_from(*args)
@smtp_from = args[0]
end
|
#cmd_set_session_smtp_password(*args) ⇒ Object
78
79
80
|
# File 'plugins/session_notifier.rb', line 78
def cmd_set_session_smtp_password(*args)
@smtp_password = args[0]
end
|
#cmd_set_session_smtp_port(*args) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'plugins/session_notifier.rb', line 65
def cmd_set_session_smtp_port(*args)
port = args[0]
if port =~ /^\d+$/
@smtp_port = args[0]
else
print_error('Invalid port setting. Must be a number.')
end
end
|
#cmd_set_session_smtp_username(*args) ⇒ Object
74
75
76
|
# File 'plugins/session_notifier.rb', line 74
def cmd_set_session_smtp_username(*args)
@smtp_username = args[0]
end
|
#cmd_start_session_notifier(*_args) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'plugins/session_notifier.rb', line 171
def cmd_start_session_notifier(*_args)
if session_notifier_subscribed?
print_status('You already have an active session notifier.')
return
end
begin
framework.events.add_session_subscriber(self)
if validate_sms_settings?
smtp = Rex::Proto::Sms::Model::Smtp.new(
address: smtp_address,
port: smtp_port,
username: smtp_username,
password: smtp_password,
login_type: :login,
from: smtp_from
)
@sms_client = Rex::Proto::Sms::Client.new(carrier: sms_carrier, smtp_server: smtp)
print_status('Session notification started.')
end
if !dingtalk_webhook.nil?
print_status('DingTalk notification started.')
end
if !gotify_address.nil?
print_status('Gotify notification started.')
end
if !serverjang_webhook.nil?
print_status('ServerJang notification started.')
end
rescue Msf::Plugin::SessionNotifier::Exception, Rex::Proto::Sms::Exception => e
print_error(e.message)
end
end
|
#cmd_stop_session_notifier(*_args) ⇒ Object
205
206
207
208
|
# File 'plugins/session_notifier.rb', line 205
def cmd_stop_session_notifier(*_args)
framework.events.remove_session_subscriber(self)
print_status('Session notification stopped.')
end
|
#commands ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'plugins/session_notifier.rb', line 34
def commands
{
'set_session_smtp_address' => 'Set the SMTP address for the session notifier',
'set_session_smtp_port' => 'Set the SMTP port for the session notifier',
'set_session_smtp_username' => 'Set the SMTP username',
'set_session_smtp_password' => 'Set the SMTP password',
'set_session_smtp_from' => 'Set the from field of SMTP',
'set_session_mobile_number' => 'Set the 10-digit mobile number you want to notify',
'set_session_mobile_carrier' => 'Set the mobile carrier of the phone',
'set_session_minimum_ip' => 'Set the minimum session IP range you want to be notified for',
'set_session_maximum_ip' => 'Set the maximum session IP range you want to be notified for',
'set_session_dingtalk_webhook' => 'Set the DingTalk webhook for the session notifier (keyword: session).',
'set_session_gotify_address' => 'Set the Gotify address for the session notifier',
'set_session_gotify_sslcert_path' => 'Set the path to load your Gotify SSL cert (if you want to use HTTPS)',
'set_session_serverjang_webhook' => 'Set the ServerJiang webhook for the session notifier (keyword: session).',
'save_session_notifier_settings' => 'Save all the session notifier settings to framework',
'start_session_notifier' => 'Start notifying sessions',
'stop_session_notifier' => 'Stop notifying sessions',
'restart_session_notifier' => 'Restart notifying sessions'
}
end
|
#name ⇒ Object
30
31
32
|
# File 'plugins/session_notifier.rb', line 30
def name
'SessionNotifier'
end
|
#on_session_open(session) ⇒ Object
215
216
217
218
219
|
# File 'plugins/session_notifier.rb', line 215
def on_session_open(session)
subject = "You have a new #{session.type} session!"
msg = "#{session.tunnel_peer} (#{session.session_host}) #{session.info ? "\"#{session.info}\"" : nil}"
notify_session(session, subject, msg)
end
|