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, #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, #update_prompt

Constructor Details

#initialize(driver) ⇒ SessionNotifierCommandDispatcher

Returns a new instance of SessionNotifierCommandDispatcher.


45
46
47
48
# File 'plugins/session_notifier.rb', line 45

def initialize(driver)
  super(driver)
  load_settings_from_config
end

Instance Attribute Details

#maximum_ipObject (readonly)

Returns the value of attribute maximum_ip


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

def maximum_ip
  @maximum_ip
end

#minimum_ipObject (readonly)

Returns the value of attribute minimum_ip


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

def minimum_ip
  @minimum_ip
end

#sms_carrierObject (readonly)

Returns the value of attribute sms_carrier


13
14
15
# File 'plugins/session_notifier.rb', line 13

def sms_carrier
  @sms_carrier
end

#sms_clientObject (readonly)

Returns the value of attribute sms_client


12
13
14
# File 'plugins/session_notifier.rb', line 12

def sms_client
  @sms_client
end

#sms_numberObject (readonly)

Returns the value of attribute sms_number


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

def sms_number
  @sms_number
end

#smtp_addressObject (readonly)

Returns the value of attribute smtp_address


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

def smtp_address
  @smtp_address
end

#smtp_fromObject (readonly)

Returns the value of attribute smtp_from


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

def smtp_from
  @smtp_from
end

#smtp_passwordObject (readonly)

Returns the value of attribute smtp_password


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

def smtp_password
  @smtp_password
end

#smtp_portObject (readonly)

Returns the value of attribute smtp_port


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

def smtp_port
  @smtp_port
end

#smtp_usernameObject (readonly)

Returns the value of attribute smtp_username


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

def smtp_username
  @smtp_username
end

Instance Method Details

#cmd_restart_session_notifier(*args) ⇒ Object


144
145
146
147
# File 'plugins/session_notifier.rb', line 144

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

#cmd_save_session_notifier_settings(*args) ⇒ Object


110
111
112
113
# File 'plugins/session_notifier.rb', line 110

def cmd_save_session_notifier_settings(*args)
  save_settings_to_config
  print_status("Session Notifier settings saved in config file.")
end

#cmd_set_session_maximum_ip(*args) ⇒ Object


99
100
101
102
103
104
105
106
107
108
# File 'plugins/session_notifier.rb', line 99

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


88
89
90
91
92
93
94
95
96
97
# File 'plugins/session_notifier.rb', line 88

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


84
85
86
# File 'plugins/session_notifier.rb', line 84

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

#cmd_set_session_mobile_number(*args) ⇒ Object


75
76
77
78
79
80
81
82
# File 'plugins/session_notifier.rb', line 75

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


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

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

#cmd_set_session_smtp_from(*args) ⇒ Object


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

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

#cmd_set_session_smtp_password(*args) ⇒ Object


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

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

#cmd_set_session_smtp_port(*args) ⇒ Object


54
55
56
57
58
59
60
61
# File 'plugins/session_notifier.rb', line 54

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


63
64
65
# File 'plugins/session_notifier.rb', line 63

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

#cmd_start_session_notifier(*args) ⇒ Object


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'plugins/session_notifier.rb', line 115

def cmd_start_session_notifier(*args)
  if is_session_notifier_subscribed?
    print_status('You already have an active session notifier.')
    return
  end

  begin
    validate_settings!
    self.framework.events.add_session_subscriber(self)
    smtp = Rex::Proto::Sms::Model::Smtp.new(
      address: self.smtp_address,
      port: self.smtp_port,
      username: self.smtp_username,
      password: self.smtp_password,
      login_type: :login,
      from: self.smtp_from
    )
    @sms_client = Rex::Proto::Sms::Client.new(carrier: self.sms_carrier, smtp_server: smtp)
    print_status("Session notification started.")
  rescue Msf::Plugin::SessionNotifier::Exception, Rex::Proto::Sms::Exception => e
    print_error(e.message)
  end
end

#cmd_stop_session_notifier(*args) ⇒ Object


139
140
141
142
# File 'plugins/session_notifier.rb', line 139

def cmd_stop_session_notifier(*args)
  self.framework.events.remove_session_subscriber(self)
  print_status("Session notification stopped.")
end

#commandsObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'plugins/session_notifier.rb', line 27

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


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

def name
  'SessionNotifier'
end

#on_session_open(session) ⇒ Object


149
150
151
152
153
# File 'plugins/session_notifier.rb', line 149

def on_session_open(session)
  subject = "You have a new #{session.type} session!"
  msg = "#{session.tunnel_peer} (#{session.session_host}) #{session.info ? "\"#{session.info.to_s}\"" : nil}"
  notify_session(session, subject, msg)
end