Class: Msf::Plugin::SessionNotifier::SessionNotifierCommandDispatcher

Inherits:
Object
  • Object
show all
Includes:
Ui::Console::CommandDispatcher
Defined in:
plugins/session_notifier.rb

Instance Attribute Summary collapse

Attributes included from Ui::Console::CommandDispatcher

#driver

Attributes included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #load_config, #log_error, #remove_lines

Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, #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

#initialize(driver) ⇒ SessionNotifierCommandDispatcher

Returns a new instance of SessionNotifierCommandDispatcher.


50
51
52
53
# File 'plugins/session_notifier.rb', line 50

def initialize(driver)
  super(driver)
  load_settings_from_config
end

Instance Attribute Details

#dingtalk_webhookObject (readonly)

Returns the value of attribute dingtalk_webhook


25
26
27
# File 'plugins/session_notifier.rb', line 25

def dingtalk_webhook
  @dingtalk_webhook
end

#maximum_ipObject (readonly)

Returns the value of attribute maximum_ip


24
25
26
# File 'plugins/session_notifier.rb', line 24

def maximum_ip
  @maximum_ip
end

#minimum_ipObject (readonly)

Returns the value of attribute minimum_ip


23
24
25
# File 'plugins/session_notifier.rb', line 23

def minimum_ip
  @minimum_ip
end

#sms_carrierObject (readonly)

Returns the value of attribute sms_carrier


16
17
18
# File 'plugins/session_notifier.rb', line 16

def sms_carrier
  @sms_carrier
end

#sms_clientObject (readonly)

Returns the value of attribute sms_client


15
16
17
# File 'plugins/session_notifier.rb', line 15

def sms_client
  @sms_client
end

#sms_numberObject (readonly)

Returns the value of attribute sms_number


17
18
19
# File 'plugins/session_notifier.rb', line 17

def sms_number
  @sms_number
end

#smtp_addressObject (readonly)

Returns the value of attribute smtp_address


18
19
20
# File 'plugins/session_notifier.rb', line 18

def smtp_address
  @smtp_address
end

#smtp_fromObject (readonly)

Returns the value of attribute smtp_from


22
23
24
# File 'plugins/session_notifier.rb', line 22

def smtp_from
  @smtp_from
end

#smtp_passwordObject (readonly)

Returns the value of attribute smtp_password


21
22
23
# File 'plugins/session_notifier.rb', line 21

def smtp_password
  @smtp_password
end

#smtp_portObject (readonly)

Returns the value of attribute smtp_port


19
20
21
# File 'plugins/session_notifier.rb', line 19

def smtp_port
  @smtp_port
end

#smtp_usernameObject (readonly)

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


163
164
165
166
# File 'plugins/session_notifier.rb', line 163

def cmd_restart_session_notifier(*args)
  cmd_stop_session_notifier(args)
  cmd_start_session_notifier(args)
end

#cmd_save_session_notifier_settings(*_args) ⇒ Object


126
127
128
129
# File 'plugins/session_notifier.rb', line 126

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


115
116
117
118
119
120
121
122
123
124
# File 'plugins/session_notifier.rb', line 115

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_maximum_ip(*args) ⇒ Object


104
105
106
107
108
109
110
111
112
113
# File 'plugins/session_notifier.rb', line 104

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


93
94
95
96
97
98
99
100
101
102
# File 'plugins/session_notifier.rb', line 93

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


89
90
91
# File 'plugins/session_notifier.rb', line 89

def cmd_set_session_mobile_carrier(*args)
  @sms_carrier = args[0].to_sym
end

#cmd_set_session_mobile_number(*args) ⇒ Object


80
81
82
83
84
85
86
87
# File 'plugins/session_notifier.rb', line 80

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_smtp_address(*args) ⇒ Object


55
56
57
# File 'plugins/session_notifier.rb', line 55

def cmd_set_session_smtp_address(*args)
  @smtp_address = args[0]
end

#cmd_set_session_smtp_from(*args) ⇒ Object


76
77
78
# File 'plugins/session_notifier.rb', line 76

def cmd_set_session_smtp_from(*args)
  @smtp_from = args[0]
end

#cmd_set_session_smtp_password(*args) ⇒ Object


72
73
74
# File 'plugins/session_notifier.rb', line 72

def cmd_set_session_smtp_password(*args)
  @smtp_password = args[0]
end

#cmd_set_session_smtp_port(*args) ⇒ Object


59
60
61
62
63
64
65
66
# File 'plugins/session_notifier.rb', line 59

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


68
69
70
# File 'plugins/session_notifier.rb', line 68

def cmd_set_session_smtp_username(*args)
  @smtp_username = args[0]
end

#cmd_start_session_notifier(*_args) ⇒ Object


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'plugins/session_notifier.rb', line 131

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.')
    elsif !dingtalk_webhook.nil?
      print_status('DingTalk 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


158
159
160
161
# File 'plugins/session_notifier.rb', line 158

def cmd_stop_session_notifier(*_args)
  framework.events.remove_session_subscriber(self)
  print_status('Session notification stopped.')
end

#commandsObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'plugins/session_notifier.rb', line 31

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

#nameObject


27
28
29
# File 'plugins/session_notifier.rb', line 27

def name
  'SessionNotifier'
end

#on_session_open(session) ⇒ Object


168
169
170
171
172
# File 'plugins/session_notifier.rb', line 168

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