V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
the13matrix
V2EX  ›  WebRTC

怎样禁用浏览器的WebRTC?这东西居然能读取本地IP!!

  •  1
     
  •   the13matrix · 2014-01-23 20:54:21 +08:00 · 28693 次点击
    这是一个创建于 3717 天前的主题,其中的信息可能已经有所发展或是发生改变。
    可以直接从本地读取IP。和ipconfig /all看到的IP一样。
    如果电脑直接播号上网,则获取到的就是公网IP。如果是家庭、学校、公司的内网,获取到的就是内网IP。如果系统里有虚拟网卡,虚拟网卡IP也加入列表。
    测试代码:(对Chrome和Firefox有效)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>获取内网IP</title>
    </head>
    <body>
    您的内网IP:
    <span id="list"></span>
    <script>
    // NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
    var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
    if (RTCPeerConnection) (function () {
    var rtc = new RTCPeerConnection({iceServers:[]});
    if (window.mozRTCPeerConnection) { // FF needs a channel/stream to proceed
    rtc.createDataChannel('', {reliable:false});
    };
    rtc.onicecandidate = function (evt) {
    if (evt.candidate) grepSDP(evt.candidate.candidate);
    };
    rtc.createOffer(function (offerDesc) {
    grepSDP(offerDesc.sdp);
    rtc.setLocalDescription(offerDesc);
    }, function (e) { console.warn("offer failed", e); });
    var addrs = Object.create(null);
    addrs["0.0.0.0"] = false;
    function updateDisplay(newAddr) {
    if (newAddr in addrs) return;
    else addrs[newAddr] = true;
    var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
    document.getElementById('list').innerHTML = displayAddrs.join(" or perhaps ") || "n/a";
    }
    function grepSDP(sdp) {
    var hosts = [];
    sdp.split('\r\n').forEach(function (line) { // c.f.http://tools.ietf.org/html/rfc4566#page-39
    if (~line.indexOf("a=candidate")) { //http://tools.ietf.org/html/rfc4566#section-5.13
    var parts = line.split(' '), //http://tools.ietf.org/html/rfc5245#section-15.1
    addr = parts[4],
    type = parts[7];
    if (type === 'host') updateDisplay(addr);
    } else if (~line.indexOf("c=")) { //http://tools.ietf.org/html/rfc4566#section-5.7
    var parts = line.split(' '),
    addr = parts[2];
    updateDisplay(addr);
    }
    });
    }
    })(); else {
    document.getElementById('list').innerHTML = "<code>ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2 | tail -n1</code>";
    document.getElementById('list').nextSibling.textContent = "In Chrome and Firefox your IP should display automatically, by the power of WebRTCskull.";
    }
    </script>
    </body>
    </html>
    建网站的朋友,可以用这个判断访客是内网用户还是公网。并且获取访客内网IP。
    不管你用了多少层匿名代理/VPN,这段代码都能直接提取本地IP。然后一个异步请求,就可以被服务端提取。浏览器无任何安全提示。
    第 1 条附言  ·  2014-01-24 06:07:31 +08:00
    感谢11楼提醒。
    公共测试地址放上来: http://net.ipcalf.com/
    17 条回复    2016-05-13 10:29:44 +08:00
    ihacku
        1
    ihacku  
       2014-01-23 22:20:54 +08:00
    chrome://flags/ 试试关掉里面相关的flag试试?
    notedit
        2
    notedit  
       2014-01-23 22:29:02 +08:00
    webrtc 启用的时候都要被授权 你可以点击deny
    the13matrix
        3
    the13matrix  
    OP
       2014-01-23 22:29:25 +08:00
    @ihacku 里面有停用webrtc,但显示:抱歉,此实验无法在您的平台上进行。
    只有android平台下的chrome支持关掉webrtc?
    the13matrix
        4
    the13matrix  
    OP
       2014-01-23 22:34:52 +08:00
    @notedit 上面那段读取本地IP的代码不用授权。你可以测试一下。
    airyland
        5
    airyland  
       2014-01-23 22:49:54 +08:00
    感谢楼主分享,亲测有效。原来可以这样获取。。
    initialdp
        6
    initialdp  
       2014-01-23 23:01:36 +08:00 via iPad
    不奇怪啊,webrtc本来就是用于通信的,肯定需要拿到这些地址信息才行。
    switch
        7
    switch  
       2014-01-23 23:16:56 +08:00
    可以使用 GM 来重写 RTCPeerConnection 构造函数,使其失效。
    est
        8
    est  
       2014-01-23 23:23:28 +08:00
    chrome还有个bug就是可以后台麦克风录音
    xvfeng
        9
    xvfeng  
       2014-01-23 23:46:07 +08:00
    webrtc本身没有连接功能.需要先通过一个signal的服务器来建立连接才行. 正常情况下根本不可能出现安全问题. 楼主禁用webrtc是要怎样...
    the13matrix
        10
    the13matrix  
    OP
       2014-01-24 00:02:52 +08:00
    @xvfeng 正常情况下,浏览器不该有读取网卡IP的权限。
    yfdyh000
        11
    yfdyh000  
       2014-01-24 00:50:21 +08:00   ❤️ 1
    确认是不经授权的泄露。
    最初披露者像是 http://net.ipcalf.com/ ,用这个地址能搜到相关的讨论。
    Firefox 用 media.peerconnection.enabled 可禁用功能避免泄露,Tor Browser 就已默认禁用。
    Chrome 的禁用方法没找到。
    582033
        12
    582033  
       2014-01-24 09:36:06 +08:00
    @the13matrix 这不算什么吧,相比chrome的另一大功能(话筒处于随时监听状态)小巫见大巫了啊。
    est
        13
    est  
       2014-01-24 09:36:35 +08:00
    @yfdyh000

    看了下

    https://2x.io/read/security-by-obscurity

    把我的桥接IP都识别出来了。厉害。
    DearMark
        14
    DearMark  
       2014-01-24 11:21:36 +08:00
    我的firefox无法获取ip,chrome可以
    bigbee
        15
    bigbee  
       2014-08-11 12:29:22 +08:00
    我的firefox、chrome都可以
    ForMoom
        16
    ForMoom  
       2015-02-02 11:42:29 +08:00
    @yfdyh000 听说Chrome 浏览器可以安装 WebRTC block 或 ScriptSafe 插件,
    Chrome 浏览器ScriptSafe扩展的地址:
    https://chrome.google.com/webstore/search/ScriptSafe
    impig33
        17
    impig33  
       2016-05-13 10:29:44 +08:00
    来个详细的说明
    firefox 输入 about:config 将 media.peerconnection.enabled 设为 false
    chrome 安装 webRTC blocker 禁用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4546 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:57 · PVG 17:57 · LAX 02:57 · JFK 05:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.