Files
metasploit-gs/modules/auxiliary/admin/misc/wol.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
2.9 KiB
Ruby
Raw Normal View History

2012-04-21 03:29:49 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-04-21 03:29:49 -05:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2012-04-21 03:29:49 -05:00
include Msf::Exploit::Remote::Udp
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
def initialize(info = {})
super(update_info(info,
'Name' => 'UDP Wake-On-Lan (WOL)',
'Description' => %q{
This module will turn on a remote machine with a network card that
supports wake-on-lan (or MagicPacket). In order to use this, you must
know the machine's MAC address in advance. The current default MAC
address is just an example of how your input should look like.
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
The password field is optional. If present, it should be in this hex
format: 001122334455, which is translated to "0x001122334455" in binary.
Note that this should be either 4 or 6 bytes long.
},
'License' => MSF_LICENSE,
2012-04-25 15:54:42 -05:00
'Author' => [ 'sinn3r' ]
2012-04-21 03:29:49 -05:00
))
2013-08-30 16:28:54 -05:00
2019-03-05 04:43:37 -06:00
deregister_udp_options
2012-04-21 03:29:49 -05:00
register_options(
[
OptString.new("MAC", [true, 'Specify a MAC address', '00:90:27:85:cf:01']),
OptString.new("PASSWORD", [false, 'Specify a four or six-byte password']),
OptBool.new("IPV6", [false, 'Use IPv6 broadcast', false])
])
2012-04-21 03:29:49 -05:00
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
#
# Convert the MAC option to binary format
#
def get_mac_addr
mac = datastore['MAC']
if mac !~ /^([0-9a-zA-Z]{2}\:){5}[0-9a-zA-Z]{2}$/
print_error("Invalid MAC address format")
return nil
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
bin_mac = ''
mac.split(':').each do |group|
bin_mac << [group].pack('H*')
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
bin_mac
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
#
# Supply a password to go with the WOL packet (SecureON)
#
def parse_password
return "" if datastore['PASSWORD'].nil?
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
dataset = [ datastore['PASSWORD'] ].pack('H*').unpack('C*')
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
# According to Wireshark wiki, this must be either 4 or 6 bytes
if dataset.length == 4 or dataset.length == 6
pass = ''
dataset.each do |group|
pass << group.to_i
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
return pass
else
print_error("Bad password format or length: #{dataset.inspect}")
end
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
nil
end
2013-08-30 16:28:54 -05:00
def wol_rhost
datastore['IPV6'] ? "ff:ff:ff:ff:ff:ff" : "255.255.255.255"
end
def wol_rport
9
end
2012-04-21 03:29:49 -05:00
def run
# If the MAC is bad, no point to continue
mac = get_mac_addr
return if mac.nil?
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
# If there's a password, use it
pass = parse_password
return if pass.nil?
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
# Craft the WOL packet
wol_pkt = "\xff" * 6 #Sync stream (magic packet)
wol_pkt << mac * 16 #Mac address
wol_pkt << pass if not pass.empty?
2013-08-30 16:28:54 -05:00
2012-04-21 03:29:49 -05:00
# Send out the packet
print_status("Sending WOL packet...")
connect_udp( true, {
'RHOST' => wol_rhost,
'RPORT' => wol_rport
})
2012-04-21 03:29:49 -05:00
udp_sock.put(wol_pkt)
disconnect_udp
end
end
=begin
http://wiki.wireshark.org/WakeOnLAN
Test:
udp && eth.addr == ff:ff:ff:ff:ff:ff
=end