PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/auxiliary/scanner/discovery/ipv6_multicast_ping.rb

https://bitbucket.org/jrossi/metasploit
Ruby | 88 lines | 59 code | 20 blank | 9 comment | 10 complexity | 1e76d610b90f0012c34548b3ab13b45e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. ##
  2. # $Id$
  3. ##
  4. require 'msf/core'
  5. class Metasploit3 < Msf::Auxiliary
  6. include Msf::Exploit::Remote::Capture
  7. include Msf::Exploit::Remote::Ipv6
  8. include Msf::Auxiliary::Report
  9. def initialize
  10. super(
  11. 'Name' => 'IPv6 Link Local/Node Local Ping Discovery',
  12. 'Version' => '$Revision$',
  13. 'Description' => %q{
  14. Send a ICMPv6 ping request to all default multicast addresses, and wait to see who responds.
  15. },
  16. 'Author' => 'wuntee',
  17. 'License' => MSF_LICENSE,
  18. 'References' =>
  19. [
  20. ['URL','http://wuntee.blogspot.com/2010/12/ipv6-ping-host-discovery-metasploit.html']
  21. ]
  22. )
  23. deregister_options('SNAPLEN', 'FILTER', 'RHOST', 'PCAPFILE')
  24. end
  25. def listen_for_ping_response(opts = {})
  26. hosts = {}
  27. timeout = opts['TIMEOUT'] || datastore['TIMEOUT']
  28. prefix = opts['PREFIX'] || datastore['PREFIX']
  29. max_epoch = ::Time.now.to_i + timeout
  30. while(::Time.now.to_i < max_epoch)
  31. pkt = capture.next()
  32. next if not pkt
  33. eth = Racket::L2::Ethernet.new(pkt)
  34. next if not eth.ethertype.eql?(Racket::L2::Ethernet::ETHERTYPE_IPV6)
  35. ipv6 = Racket::L3::IPv6.new(eth.payload)
  36. next if not ipv6.nhead == 0x3a
  37. icmpv6 = Racket::L4::ICMPv6.new(ipv6.payload)
  38. next if not icmpv6.type == Racket::L4::ICMPv6Generic::ICMPv6_TYPE_ECHO_REPLY
  39. icmpv6 = Racket::L4::ICMPv6EchoReply.new(ipv6.payload)
  40. host_addr = Racket::L3::Misc.long2ipv6(ipv6.src_ip)
  41. host_mac = eth.src_mac
  42. if(!hosts[host_addr].eql?(host_mac))
  43. hosts[host_addr] = host_mac
  44. print_status(" |*| #{host_addr} => #{host_mac}")
  45. # report_host(:mac => host_mac, :host => host_addr)
  46. end
  47. end
  48. return(hosts)
  49. end
  50. def run
  51. # Start caputre
  52. open_pcap({'FILTER' => "icmp6"})
  53. # Send ping
  54. print_status("Sending multicast pings...")
  55. dmac = "33:33:00:00:00:01"
  56. # Figure out our source address by the link-local interface
  57. shost = ipv6_link_address
  58. ping6("FF01::1", {"DMAC" => dmac, "SHOST" => shost, "WAIT" => false})
  59. ping6("FF01::2", {"DMAC" => dmac, "SHOST" => shost, "WAIT" => false})
  60. ping6("FF02::1", {"DMAC" => dmac, "SHOST" => shost, "WAIT" => false})
  61. ping6("FF02::2", {"DMAC" => dmac, "SHOST" => shost, "WAIT" => false})
  62. # Listen for host advertisments
  63. print_status("Listening for responses...")
  64. listen_for_ping_response()
  65. # Close capture
  66. close_pcap()
  67. end
  68. end