metasploit-framework/modules/post/multi/general/wall.rb

62 lines
1.9 KiB
Ruby
Raw Normal View History

2015-11-11 17:15:32 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Post
2015-11-11 17:15:32 +00:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Write Messages to Users',
'Description' => %q{
This module utilizes the wall(1) or write(1) utilities, as appropriate,
to send messages to users on the target system.
},
'License' => MSF_LICENSE,
2015-11-11 19:54:46 +00:00
'Author' => [
'Jon Hart <jon_hart[at]rapid7.com>' # original metasploit module
],
2015-11-11 17:15:32 +00:00
# TODO: is there a way to do this on Windows?
'Platform' => %w(linux osx unix),
'SessionTypes' => %w(shell meterpreter)
)
)
register_options(
[
2015-11-11 19:54:46 +00:00
OptString.new('MESSAGE', [false, 'The message to send', '']),
2015-11-11 17:15:32 +00:00
OptString.new('USERS', [false, 'List of users to write(1) to, separated by commas. ' \
2015-11-11 19:54:46 +00:00
' wall(1)s to all users by default']),
OptBool.new('COWSAY', [true, 'Display MESSAGE in a ~cowsay way', false])
2015-11-11 17:15:32 +00:00
], self.class)
end
def users
datastore['USERS'] ? datastore['USERS'].split(/\s*,\s*/) : nil
end
def message
2015-11-11 19:54:46 +00:00
if datastore['MESSAGE'].blank?
text = "Hello from a metasploit session at #{Time.now}"
else
text = datastore['MESSAGE']
end
2015-11-13 19:49:50 +00:00
datastore['COWSAY'] ? Rex::Text.cowsay(text) : text
2015-11-11 17:15:32 +00:00
end
def run
if users
2015-11-11 19:54:46 +00:00
# this requires that the target user has write turned on
2015-11-11 17:15:32 +00:00
users.map { |user| cmd_exec("echo '#{message}' | write #{user}") }
else
2015-11-11 19:54:46 +00:00
# this will send the messages to all users, regardless of whether or
# not they have write turned on. If the session is root, the -n will disable
# the annoying banner
cmd_exec("echo '#{message}' | wall -n")
2015-11-11 17:15:32 +00:00
end
end
end