PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/auxiliary/admin/misc/wol.rb

https://github.com/Jonono2/metasploit-framework
Ruby | 118 lines | 99 code | 7 blank | 12 comment | 2 complexity | c23375705f8ef7351d4d465c6d529aef MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, GPL-3.0, LGPL-2.1, GPL-2.0
  1. ##
  2. # This module requires Metasploit: http//metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5. require 'msf/core'
  6. class Metasploit3 < Msf::Auxiliary
  7. include Msf::Exploit::Remote::Udp
  8. def initialize(info = {})
  9. super(update_info(info,
  10. 'Name' => 'UDP Wake-On-Lan (WOL)',
  11. 'Description' => %q{
  12. This module will turn on a remote machine with a network card that
  13. supports wake-on-lan (or MagicPacket). In order to use this, you must
  14. know the machine's MAC address in advance. The current default MAC
  15. address is just an example of how your input should look like.
  16. The password field is optional. If present, it should be in this hex
  17. format: 001122334455, which is translated to "0x001122334455" in binary.
  18. Note that this should be either 4 or 6 bytes long.
  19. },
  20. 'License' => MSF_LICENSE,
  21. 'Author' => [ 'sinn3r' ]
  22. ))
  23. register_options(
  24. [
  25. OptString.new("MAC", [true, 'Specify a MAC address', '00:90:27:85:cf:01']),
  26. OptString.new("PASSWORD", [false, 'Specify a four or six-byte password']),
  27. OptBool.new("IPV6", [false, 'Use IPv6 broadcast', false])
  28. ], self.class)
  29. deregister_options('RHOST', 'RPORT')
  30. end
  31. #
  32. # Convert the MAC option to binary format
  33. #
  34. def get_mac_addr
  35. mac = datastore['MAC']
  36. if mac !~ /^([0-9a-zA-Z]{2}\:){5}[0-9a-zA-Z]{2}$/
  37. print_error("Invalid MAC address format")
  38. return nil
  39. end
  40. bin_mac = ''
  41. mac.split(':').each do |group|
  42. bin_mac << [group].pack('H*')
  43. end
  44. bin_mac
  45. end
  46. #
  47. # Supply a password to go with the WOL packet (SecureON)
  48. #
  49. def parse_password
  50. return "" if datastore['PASSWORD'].nil?
  51. dataset = [ datastore['PASSWORD'] ].pack('H*').unpack('C*')
  52. # According to Wireshark wiki, this must be either 4 or 6 bytes
  53. if dataset.length == 4 or dataset.length == 6
  54. pass = ''
  55. dataset.each do |group|
  56. pass << group.to_i
  57. end
  58. return pass
  59. else
  60. print_error("Bad password format or length: #{dataset.inspect}")
  61. end
  62. nil
  63. end
  64. def wol_rhost
  65. datastore['IPV6'] ? "ff:ff:ff:ff:ff:ff" : "255.255.255.255"
  66. end
  67. def wol_rport
  68. 9
  69. end
  70. def run
  71. # If the MAC is bad, no point to continue
  72. mac = get_mac_addr
  73. return if mac.nil?
  74. # If there's a password, use it
  75. pass = parse_password
  76. return if pass.nil?
  77. # Craft the WOL packet
  78. wol_pkt = "\xff" * 6 #Sync stream (magic packet)
  79. wol_pkt << mac * 16 #Mac address
  80. wol_pkt << pass if not pass.empty?
  81. # Send out the packet
  82. print_status("Sending WOL packet...")
  83. connect_udp( true, {
  84. 'RHOST' => wol_rhost,
  85. 'RPORT' => wol_rport
  86. })
  87. udp_sock.put(wol_pkt)
  88. disconnect_udp
  89. end
  90. end
  91. =begin
  92. http://wiki.wireshark.org/WakeOnLAN
  93. Test:
  94. udp && eth.addr == ff:ff:ff:ff:ff:ff
  95. =end