Path: blob/master/modules/post/multi/general/wall.rb
19758 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6def initialize(info = {})7super(8update_info(9info,10'Name' => 'Write Messages to Users',11'Description' => %q{12This module utilizes the wall(1) or write(1) utilities, as appropriate,13to send messages to users on the target system.14},15'License' => MSF_LICENSE,16'Author' => [17'Jon Hart <jon_hart[at]rapid7.com>' # original metasploit module18],19# TODO: is there a way to do this on Windows?20'Platform' => %w[linux osx unix],21'SessionTypes' => %w[shell meterpreter],22'Notes' => {23'Stability' => [CRASH_SAFE],24'SideEffects' => [SCREEN_EFFECTS],25'Reliability' => []26}27)28)29register_options(30[31OptString.new('MESSAGE', [false, 'The message to send', '']),32OptString.new('USERS', [33false,34'List of users to write(1) to, separated by commas. wall(1)s to all users by default.'35]),36OptBool.new('COWSAY', [true, 'Display MESSAGE in a ~cowsay way', false])37]38)39end4041def users42datastore['USERS'] ? datastore['USERS'].split(/\s*,\s*/) : nil43end4445def message46if datastore['MESSAGE'].blank?47text = "Hello from a metasploit session at #{Time.now}"48else49text = datastore['MESSAGE']50end5152datastore['COWSAY'] ? Rex::Text.cowsay(text) : text53end5455def run56if users57# this requires that the target user has write turned on58users.map { |user| cmd_exec("echo '#{message}' | write #{user}") }59else60# this will send the messages to all users, regardless of whether or61# not they have write turned on. If the session is root, the -n will disable62# the annoying banner63cmd_exec("echo '#{message}' | wall -n")64end65end66end676869