WebRTC ip泄露 笔记

puppeteer WebRTC
创建时间:2022-03-17 16:58:27

目录

获取ip代码

function findIP(onNewIP) { var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var pc = new myPeerConnection({iceServers: [{urls: "stun:stun.l.google.com:19302"}]}), noop = function() {}, localIPs = {}, ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g, key; function ipIterate(ip) { if (!localIPs[ip]) onNewIP(ip); localIPs[ip] = true; } pc.createDataChannel(""); pc.createOffer(function(sdp) { sdp.sdp.split('\n').forEach(function(line) { if (line.indexOf('candidate') < 0) return; line.match(ipRegex).forEach(ipIterate); }); pc.setLocalDescription(sdp, noop, noop); }, noop); pc.onicecandidate = function(ice) { if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return; ice.candidate.candidate.match(ipRegex).forEach(ipIterate); }; } function addIP(ip) { console.log('got ip: ', ip); return var li = document.createElement('li'); li.textContent = ip; document.getElementById("IPLeak").appendChild(li); } findIP(addIP);

来源:https://ip.voidsec.com/

puppeteer 中关闭

  1. 安装「WebRTC Leak Prevent」扩展
    how-can-i-disable-webrtc-local-ip-leak-with-puppeteer
  2. 启动参数设置
--disable-features=WebRtcHideLocalIpsWithMdns

puppeteer-chromium-disable-anonymize-local-ips-exposed-by-webrtc
3. 替换命令

await page.evaluateOnNewDocument( `navigator.mediaDevices.getUserMedia = navigator.webkitGetUserMedia = navigator.mozGetUserMedia = navigator.getUserMedia = webkitRTCPeerConnection = RTCPeerConnection = MediaStreamTrack = undefined;` );

puppeteer/issues/4149

浏览器如何关闭

Chrome 安装扩展禁用

安装「WebRTC Leak Prevent」扩展
将「IP handling policy」选项设置为「Disable non-proxied UDP (force proxy)」
点击「Apply Settings」以应用

Firefox 修改配置禁用

在浏览器地址栏输入「about:config」回车
搜索「media.peerconnection.enabled」字段
双击「media.peerconnection.enabled」首选项,使其值变为「false」

参考

https://ip.voidsec.com/
https://blog.csdn.net/whatday/article/details/103727717