Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/misc/wol.rb
Views: 11784
##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(update_info(info,10'Name' => 'UDP Wake-On-Lan (WOL)',11'Description' => %q{12This module will turn on a remote machine with a network card that13supports wake-on-lan (or MagicPacket). In order to use this, you must14know the machine's MAC address in advance. The current default MAC15address is just an example of how your input should look like.1617The password field is optional. If present, it should be in this hex18format: 001122334455, which is translated to "0x001122334455" in binary.19Note that this should be either 4 or 6 bytes long.20},21'License' => MSF_LICENSE,22'Author' => [ 'sinn3r' ]23))2425deregister_udp_options2627register_options(28[29OptString.new("MAC", [true, 'Specify a MAC address', '00:90:27:85:cf:01']),30OptString.new("PASSWORD", [false, 'Specify a four or six-byte password']),31OptBool.new("IPV6", [false, 'Use IPv6 broadcast', false])32])33end3435#36# Convert the MAC option to binary format37#38def get_mac_addr39mac = datastore['MAC']40if mac !~ /^([0-9a-zA-Z]{2}\:){5}[0-9a-zA-Z]{2}$/41print_error("Invalid MAC address format")42return nil43end4445bin_mac = ''46mac.split(':').each do |group|47bin_mac << [group].pack('H*')48end4950bin_mac51end5253#54# Supply a password to go with the WOL packet (SecureON)55#56def parse_password57return "" if datastore['PASSWORD'].nil?5859dataset = [ datastore['PASSWORD'] ].pack('H*').unpack('C*')6061# According to Wireshark wiki, this must be either 4 or 6 bytes62if dataset.length == 4 or dataset.length == 663pass = ''64dataset.each do |group|65pass << group.to_i66end6768return pass69else70print_error("Bad password format or length: #{dataset.inspect}")71end7273nil74end7576def wol_rhost77datastore['IPV6'] ? "ff:ff:ff:ff:ff:ff" : "255.255.255.255"78end7980def wol_rport81982end8384def run85# If the MAC is bad, no point to continue86mac = get_mac_addr87return if mac.nil?8889# If there's a password, use it90pass = parse_password91return if pass.nil?9293# Craft the WOL packet94wol_pkt = "\xff" * 6 #Sync stream (magic packet)95wol_pkt << mac * 16 #Mac address96wol_pkt << pass if not pass.empty?9798# Send out the packet99print_status("Sending WOL packet...")100connect_udp( true, {101'RHOST' => wol_rhost,102'RPORT' => wol_rport103})104udp_sock.put(wol_pkt)105disconnect_udp106end107end108109=begin110http://wiki.wireshark.org/WakeOnLAN111112Test:113udp && eth.addr == ff:ff:ff:ff:ff:ff114=end115116117