PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/Jonono2/metasploit-framework
Ruby | 105 lines | 76 code | 17 blank | 12 comment | 10 complexity | 220e536784d52bc8c371107e288e88a5 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::Capture
  8. include Msf::Exploit::Remote::Ipv6
  9. include Msf::Auxiliary::Report
  10. def initialize
  11. super(
  12. 'Name' => 'IPv6 Link Local/Node Local Ping Discovery',
  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_bytes = capture.next()
  32. Kernel.select(nil,nil,nil,0.1)
  33. next if not pkt_bytes
  34. p = PacketFu::Packet.parse(pkt_bytes)
  35. # Don't bother checking if it's an echo reply, since Neighbor Solicitations
  36. # and any other response is just as good.
  37. next unless p.is_ipv6?
  38. host_addr = p.ipv6_saddr
  39. host_mac = p.eth_saddr
  40. next if host_mac == @smac
  41. unless hosts[host_addr] == host_mac
  42. hosts[host_addr] = host_mac
  43. print_status(" |*| #{host_addr} => #{host_mac}")
  44. end
  45. end
  46. return hosts
  47. end
  48. def smac
  49. smac = datastore['SMAC']
  50. smac ||= get_mac(@interface) if @netifaces
  51. smac ||= ipv6_mac
  52. smac
  53. end
  54. def run
  55. # Start capture
  56. open_pcap({'FILTER' => "icmp6"})
  57. @netifaces = true
  58. if not netifaces_implemented?
  59. print_error("WARNING : Pcaprub is not uptodate, some functionality will not be available")
  60. @netifaces = false
  61. end
  62. @interface = datastore['INTERFACE'] || Pcap.lookupdev
  63. # Send ping
  64. print_status("Sending multicast pings...")
  65. dmac = "33:33:00:00:00:01"
  66. @smac = smac
  67. # Figure out our source address by the link-local interface
  68. shost = ipv6_link_address
  69. # m-1-k-3: added some more multicast addresses from wikipedia: https://en.wikipedia.org/wiki/Multicast_address#IPv6
  70. ping6("FF01::1", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #node-local all nodes
  71. ping6("FF01::2", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #node-local all routers
  72. ping6("FF02::1", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #All nodes on the local network segment
  73. ping6("FF02::2", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #All routers on the local network segment
  74. ping6("FF02::5", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #OSPFv3 AllSPF routers
  75. ping6("FF02::6", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #OSPFv3 AllDR routers
  76. ping6("FF02::9", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #RIP routers
  77. ping6("FF02::a", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #EIGRP routers
  78. ping6("FF02::d", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #PIM routers
  79. ping6("FF02::16", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #MLDv2 reports (defined in RFC 3810)
  80. ping6("ff02::1:2", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #All DHCP servers and relay agents on the local network site (defined in RFC 3315)
  81. ping6("ff05::1:3", {"DMAC" => dmac, "SHOST" => shost, "SMAC" => @smac, "WAIT" => false}) #All DHCP servers on the local network site (defined in RFC 3315)
  82. # Listen for host advertisments
  83. print_status("Listening for responses...")
  84. listen_for_ping_response()
  85. # Close capture
  86. close_pcap()
  87. end
  88. end