简体   繁体   English

如何在Tor / lighttpd上运行的PHP应用程序中获取退出节点ip

[英]How to get exit node ip in PHP app running on tor/lighttpd

I'm having trouble getting the IP address of the exit node that hits my hidden service (PHP). 我无法获得命中我的隐藏服务(PHP)的出口节点的IP地址。 No matter what I try, it comes back as local (127.0.0.1), as if it's going through a proxy. 不管我尝试什么,它都会以本地(127.0.0.1)的形式返回,就好像它正在通过代理一样。

I have Tor configured like this: 我将Tor配置如下:

HiddenServicePort 80 127.0.0.1:9028

and Lighty like this: 和Lighty像这样:

server.port = 9028

which means the hit against the hidden service should arrive through Tor on virtual port 80 , get directed to 9028 on Lightly, and then served to the end user. 这意味着对隐藏服务的攻击应该通过虚拟端口80上的Tor到达,在Lightly上定向到9028 ,然后再提供给最终用户。

I have privoxy installed too but I don't believe it has anything to do with Tor hidden services (I've confirmed this thru the privoxy debug logs). 我也安装了privoxy,但我不认为它与Tor隐藏服务有任何关系(我已经通过privoxy调试日志确认了这一点)。

I've tried code like this: 我试过这样的代码:

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        return $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
    return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'];

but the headers don't include any forwarding IP information. 但标头不包含任何转发IP信息。

What am I missing? 我想念什么? Why can't Lightly see the exit node IP address? 为什么看不到出口节点的IP地址? Is there a way I could configure a proxy in there somewhere that could alter the headers and inject the X-FORWARDED header? 有什么办法可以在其中配置代理的地方更改标题并注入X-FORWARDED标题? I don't care to lookup the exit node in the public database - I just want the IP address. 我不在乎在公共数据库中查找出口节点-我只需要IP地址。

You need to check more server vars than that. 您需要检查更多的服务器变量。 I would do something like this: 我会做这样的事情:

$ipaddress = ”;
if ($_SERVER[‘HTTP_CLIENT_IP’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘HTTP_CLIENT_IP’];
else if ($_SERVER[‘HTTP_X_FORWARDED_FOR’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
else if ($_SERVER[‘HTTP_X_FORWARDED’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘HTTP_X_FORWARDED’];
else if ($_SERVER[‘HTTP_FORWARDED_FOR’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘HTTP_FORWARDED_FOR’];
else if ($_SERVER[‘HTTP_FORWARDED’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘HTTP_FORWARDED’];
else if ($_SERVER[‘REMOTE_ADDR’] != ‘127.0.0.1’)
$ipaddress = $_SERVER[‘REMOTE_ADDR’];
else
$ipaddress = 'UNKNOWN';

Hopefully that helps. 希望有帮助。

The reason it sees 127.0.0.1 is because when hidden services are in use - there is no "exit node" in the traditional sense. 它看到127.0.0.1的原因是,当使用隐藏服务时-传统意义上没有“退出节点”。

Exit nodes are used to route traffic in and out of the Tor network. 出口节点用于将流量路由进出Tor网络。 Since hits to your hidden service are coming from inside the Tor network, no exit node is actually used. 由于对隐藏服务的攻击来自Tor网络内部,因此实际上没有使用出口节点。 Instead when the Tor client wants to access your hidden service it builds a circuit to the service and the connection takes place over the Tor network, to your local Tor client which then proxies the connection (over 127.0.0.1) to your web server. 相反,当Tor客户端想要访问您的隐藏服务时,它会建立与该服务的电路,并通过Tor网络建立与本地Tor客户端的连接,然后本地Tor客户端将代理(超过127.0.0.1)连接到Web服务器。

The only time your hidden service will see an exit node IP is if your hidden service is available over Tor ( .onion ) and through the internet. 隐藏服务唯一会看到出口节点IP的时间是您的隐藏服务是否可以通过Tor( .onion通过Internet获得。

For example you can host your website publicly as usual (eg https://torsite.yourdomain.com ) so regular & Tor clients (using exit nodes) can access your site. 例如,您可以像往常一样公开托管您的网站(例如https://torsite.yourdomain.com ),以便常规和Tor客户端(使用退出节点)可以访问您的网站。 Additionally you can set up your local Tor node to proxy the hidden service (in which case access is strictly within the Tor network) and proxied through localhost. 另外,您可以设置本地Tor节点以代理隐藏的服务(在这种情况下,访问权限严格在Tor网络内)并通过localhost代理。

Since it sounds like you are only hosting a hidden service, all hits from the Tor network will show up as 127.0.0.1 thus indicating they are accessing the service over Tor. 由于听起来您只是在托管一个隐藏的服务,因此Tor网络中的所有匹配都将显示为127.0.0.1,从而表明它们正在通过Tor访问该服务。 Since Tor simply proxies the connection from the network to your local service, no circuit or Tor relay information is passed to the lighttpd. 由于Tor只是代理从网络到本地服务的连接,因此不会将任何电路或Tor中继信息传递到lighttpd。

Hope that makes sense. 希望有道理。

See also: https://www.torproject.org/docs/hidden-services.html.en 另请参阅: https : //www.torproject.org/docs/hidden-services.html.en

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM