-
Notifications
You must be signed in to change notification settings - Fork 115
/
growl.rb
216 lines (187 loc) · 6.34 KB
/
growl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
204
205
206
207
208
209
210
211
212
213
214
215
# Copyright (c) 2011, Carlos Perez <carlos_perez[at]darkoperator.com
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list of conditions and
# the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'ruby-growl'
module Msf
class Plugin::Growl < Msf::Plugin
include Msf::SessionEvent
if not defined?(Growl_yaml)
Growl_yaml = "#{Msf::Config.get_config_root}/growl.yaml"
end
# Initialize the Plug-In
def initialize(framework, opts)
super
add_console_dispatcher(GrowlCommandDispatcher)
end
# Cleanup when the Plug-In unloads
def cleanup
self.framework.events.remove_session_subscriber(self)
remove_console_dispatcher('growl')
end
def name
"growl"
end
# Sets the description of the Plug-In
def desc
"Automatically send Twitter Direct Message when sessions are created and closed"
end
# CommandDispacher Class for the Plug-In
class GrowlCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
@host = nil
@password = nil
@source = nil
@sticky = true
# Sets what is done when a session is opened
def on_session_open(session)
print_status("Session received Sending Message to #{@host}")
send_message("Source: #{@source} Session: #{session.sid} IP: #{session.tunnel_peer} Platform:#{session.platform} Type: #{session.type}")
return
end
# Sets what is done when a session is closed
def on_session_close(session,reason = "")
print_status("Session: #{session.sid} Type: #{session.type} is shutting down")
send_message("Source: #{@source} Session: #{session.sid} Type: #{session.type} is shutting down")
return
end
# Sets the name of the Plug-In
def name
"growl"
end
# Method for sending a message
def send_message(message)
@g.notify("Session Notification","Metasploit", message,0,@sticky)
return
end
# Method for reading the YAML File
def read_settings
read = nil
if File.exist?(Growl_yaml)
ldconfig = YAML.load_file("#{Growl_yaml}")
@host = ldconfig['host']
@password = ldconfig['password']
@source = ldconfig['source']
@sticky = ldconfig['sticky']
read = true
else
print_error("You must create a YAML File with the options")
print_error("as: #{Growl_yaml}")
return read
end
return read
end
# Method that defines the commands of the plugin
def commands
{
'growl_help' => "Displays help",
'growl_start' => "Start Growl Plugin after saving settings.",
'growl_save' => "Save Settings to YAML File #{Growl_yaml}.",
'growl_set_host' => "Sets host to send message to.",
'growl_set_password' => "Sets password to use.",
'growl_set_source' => "Sets the source name shown in the messages.",
'growl_set_sticky' => "Sets true or false if the message will be sticky.",
'growl_show_parms' => "Shows currently set parameters."
}
end
# Help Command
def cmd_growl_help
puts "Help"
end
# Re-Read YAML file and set Growl Configuration
def cmd_growl_start
print_status "Starting to monitor sessions to Growl on"
if read_settings()
self.framework.events.add_session_subscriber(self)
@g = Growl.new(@host,@source,["Session Notification"],nil,@password)
print_good("Growl Plugin Started, Monitoring Sessions")
else
print_error("Could not set Growl settings.")
end
end
# Save Parameters to text file
def cmd_growl_save
print_status("Saving paramters to config file")
if @host and @password and @sticky and @source
config = {'host' => @host, 'password' => @password,
'sticky' => @sticky, 'source' => @source
}
File.open(Growl_yaml, 'w') do |out|
YAML.dump(config, out)
end
print_good("All parameters saved to #{Growl_yaml}")
else
print_error("You have not provided all the parameters!")
end
end
# Set Host to send message to
def cmd_growl_set_host(*args)
if args.length > 0
print_status("Setting the host to #{args[0]}")
@host = args[0]
else
print_error("Please provide a value")
end
end
# Set Growl Password
def cmd_growl_set_password(*args)
if args.length > 0
print_status("Setting the password to #{args[0]}")
@password = args[0]
else
print_error("Please provide a value")
end
end
# Set if message will be sticky or not
def cmd_growl_set_sticky(*args)
if args.length > 0
print_status("Setting sticky to #{args[0]}")
case args[0].downcase
when "true"
@sticky = true
when "false"
@sticky = false
else
print_error("Please Specify true or false")
end
else
print_error("Please provide a value")
end
end
# Show parameters that will be used
def cmd_growl_show_parms
print_status("Parameters:")
print_good("host #{@host}")
print_good("password #{@password}")
print_good("sticky #{@sticky}")
print_good("source #{@source}")
end
# Set the source name that will be shown in the messages
def cmd_growl_set_source(*args)
if args.length > 0
print_status("Setting the source to #{args[0]}")
@source = args[0]
else
print_error("Please provide a value")
end
end
end
end
end