【问题标题】:PHP: Tor check not workingPHP:Tor 检查不起作用
【发布时间】:2015-06-18 09:22:15
【问题描述】:

我已经安装了 Tor 中继和 Nginx,并在我的 Linux 服务器上创建了我的 .onion。

在 torcHiddenServicePort 80 127.0.0.1:8747

在nginx的默认:listen 8747

我已修改TorDNSExitList 的 PHP Pear Net_DNS 以使用 Net_DNS2。当我回显 $ip, $myip, $myport 时,我得到:

ip = 127.0.0.1
my ip = 127.0.0.1
port = 8747

因此,它选择 IP 地址作为本地计算机,而不是 Tor 出口节点的 IP 地址。还有其他为什么要测试页面是否可以通过 Tor 网络访问?

(我也试过this suggestion

【问题讨论】:

    标签: php nginx ip tor


    【解决方案1】:

    解决方案是检查 127.0.0.1 IP 地址,看到 torrc 指向 127.0.0.1。这在通过 .onion 路径访问网站时有效。但是仍然需要进行全面检查,因为可以通过完整的 URL 访问网站,例如http:// [IP 地址]:[端口] - 使用“普通”或 Tor 浏览器。我对以下函数的更改:

    <?php include("Net/DNS2.php");
    // torel_check ($ip, $port, $destip) queries the Tor DNS Exit List server.
    //   The result of the query is one of the following:
    //   -1 : DNS lookup failed to get a response, or other error occurred.
    //    0 : $ip does not appear to be a Tor exit.
    //    1 : $ip is a known Tor exit for the provided destination IP / port.
    function revaddr ($ip) {
        list($a, $b, $c, $d) = split("[.]", $ip);
        return("${d}.${c}.${b}.${a}");
    }
    
    function torel_qh ($ip, $port, $destip) {
        $rsrcip = revaddr ($ip);
        $rdstip = revaddr ($destip);
        return("${rsrcip}.${port}.${rdstip}.ip-port.exitlist.torproject.org");
    }
    
    function torel_check ($ip, $port, $destip) {
        try{
            if($ip == "127.0.0.1") {
                //TX: Access via .onion path
                // is Tor exit
                return (1);
            }
            //TX: Access web site directly
            $ndr = new Net_DNS2_Resolver();
            $qh = torel_qh($ip, $port, $destip);
    
           // uncomment these two lines to query the server directly...
           //$ns = "exitlist-ns.torproject.org";
           //$ndr->nameservers( array($ns) );
    
           // tune DNS params accordingly.  this is just my preference.
           $ndr->retrans = 2;
           $ndr->retry = 3;
           $ndr->usevc = 0;
    
           // perform DNS query
           // TX: Old Net_DNS check $ndr->search($qh)
           if (! $pkt = $ndr->query($qh)) {
               if (strcmp($ndr->errorstring, "NXDOMAIN") == 0) {
                   // response but no answer.  does not appear to be Tor exit.
                   return (0);
               }
               // search failed: no response or other problem...
               return(-1);
           }
           if (! isset($pkt->answer[0])) {
               // response but no answer section.  does not appear to be Tor exit.
               // (this should only happen when authority sections are provided without answer)
               return(0);
           }
           // is Tor exit
           return(1);
       } catch(Net_DNS2_Exception $e) {
           return (-1);
       }
    }
    
    // get client request parameters from Apache or equiv server:
    $ip = $myip = $myport = 0;
    if (isset ($_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; }
    if (isset ($_SERVER["SERVER_ADDR"])) { $myip = $_SERVER["SERVER_ADDR"]; }
    if (isset ($_SERVER["SERVER_PORT"])) { $myport = $_SERVER["SERVER_PORT"]; }
    
    $istor = torel_check($ip, $myport, $myip);
    

    TX: 是我的 cmets

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      • 2012-06-21
      • 2011-02-14
      • 2021-04-24
      相关资源
      最近更新 更多