Path: blob/master/modules/auxiliary/admin/misc/wol.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Udp78def initialize(info = {})9super(10update_info(11info,12'Name' => 'UDP Wake-On-Lan (WOL)',13'Description' => %q{14This module will turn on a remote machine with a network card that15supports wake-on-lan (or MagicPacket). In order to use this, you must16know the machine's MAC address in advance. The current default MAC17address is just an example of how your input should look like.1819The password field is optional. If present, it should be in this hex20format: 001122334455, which is translated to "0x001122334455" in binary.21Note that this should be either 4 or 6 bytes long.22},23'License' => MSF_LICENSE,24'Author' => [ 'sinn3r' ],25'Notes' => {26'Stability' => [CRASH_SAFE],27'SideEffects' => [],28'Reliability' => []29}30)31)3233deregister_udp_options3435register_options(36[37OptString.new('MAC', [true, 'Specify a MAC address', '00:90:27:85:cf:01']),38OptString.new('PASSWORD', [false, 'Specify a four or six-byte password']),39OptBool.new('IPV6', [false, 'Use IPv6 broadcast', false])40]41)42end4344#45# Convert the MAC option to binary format46#47def get_mac_addr48mac = datastore['MAC']49if mac !~ /^([0-9a-zA-Z]{2}:){5}[0-9a-zA-Z]{2}$/50print_error('Invalid MAC address format')51return nil52end5354bin_mac = ''55mac.split(':').each do |group|56bin_mac << [group].pack('H*')57end5859bin_mac60end6162#63# Supply a password to go with the WOL packet (SecureON)64#65def parse_password66return '' if datastore['PASSWORD'].nil?6768dataset = [ datastore['PASSWORD'] ].pack('H*').unpack('C*')6970# According to Wireshark wiki, this must be either 4 or 6 bytes71if (dataset.length == 4) || (dataset.length == 6)72pass = ''73dataset.each do |group|74pass << group.to_i75end7677return pass78else79print_error("Bad password format or length: #{dataset.inspect}")80end8182nil83end8485def wol_rhost86datastore['IPV6'] ? 'ff:ff:ff:ff:ff:ff' : '255.255.255.255'87end8889def wol_rport90991end9293def run94# If the MAC is bad, no point to continue95mac = get_mac_addr96return if mac.nil?9798# If there's a password, use it99pass = parse_password100return if pass.nil?101102# Craft the WOL packet103wol_pkt = "\xff" * 6 # Sync stream (magic packet)104wol_pkt << mac * 16 # Mac address105wol_pkt << pass if !pass.empty?106107# Send out the packet108print_status('Sending WOL packet...')109connect_udp(true, {110'RHOST' => wol_rhost,111'RPORT' => wol_rport112})113udp_sock.put(wol_pkt)114disconnect_udp115end116end117118=begin119http://wiki.wireshark.org/WakeOnLAN120121Test:122udp && eth.addr == ff:ff:ff:ff:ff:ff123=end124125126