CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/general/wall.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
def initialize(info = {})
8
super(
9
update_info(
10
info,
11
'Name' => 'Write Messages to Users',
12
'Description' => %q{
13
This module utilizes the wall(1) or write(1) utilities, as appropriate,
14
to send messages to users on the target system.
15
},
16
'License' => MSF_LICENSE,
17
'Author' => [
18
'Jon Hart <jon_hart[at]rapid7.com>' # original metasploit module
19
],
20
# TODO: is there a way to do this on Windows?
21
'Platform' => %w[linux osx unix],
22
'SessionTypes' => %w[shell meterpreter]
23
)
24
)
25
register_options(
26
[
27
OptString.new('MESSAGE', [false, 'The message to send', '']),
28
OptString.new('USERS', [
29
false, 'List of users to write(1) to, separated by commas. ' \
30
' wall(1)s to all users by default'
31
]),
32
OptBool.new('COWSAY', [true, 'Display MESSAGE in a ~cowsay way', false])
33
]
34
)
35
end
36
37
def users
38
datastore['USERS'] ? datastore['USERS'].split(/\s*,\s*/) : nil
39
end
40
41
def message
42
if datastore['MESSAGE'].blank?
43
text = "Hello from a metasploit session at #{Time.now}"
44
else
45
text = datastore['MESSAGE']
46
end
47
48
datastore['COWSAY'] ? Rex::Text.cowsay(text) : text
49
end
50
51
def run
52
if users
53
# this requires that the target user has write turned on
54
users.map { |user| cmd_exec("echo '#{message}' | write #{user}") }
55
else
56
# this will send the messages to all users, regardless of whether or
57
# not they have write turned on. If the session is root, the -n will disable
58
# the annoying banner
59
cmd_exec("echo '#{message}' | wall -n")
60
end
61
end
62
end
63
64