简体   繁体   English

我们可以用php cURL欺骗$ _SERVER ['REMOTE_ADDR'] /用户ip吗?

[英]Can we spoof $_SERVER['REMOTE_ADDR'] / user ip with php cURL?

Well the title basically says it. 好吧,标题基本上是这样说的。

But for more info . 但欲了解更多信息。 .

This method works but . 这种方法有效。 .

$ip = '1.1.1.1';
curl_setopt($handle, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "X_FORWARDED_FOR: $ip"));

It only adds these two keys on the $_SERVER array 它只在$_SERVER数组上添加这两个keys

  • HTTP_REMOTE_ADDR
  • HTTP_X_FORWARDED_FOR

The key REMOTE_ADDR still remains the same. 关键REMOTE_ADDR仍然保持不变。

Can REMOTE_ADDR be changed? 可以更改REMOTE_ADDR吗? The answer here says NO . 答案在这里NO。 But a comment also says It may, however, NOT be the user's real IP address because it may be hidden by proxies and other methods. 但是评论还说, 它可能不是用户的真实IP地址,因为它可能被代理和其他方法隐藏。 That is why the general rule is to not depend on $_SERVER['REMOTE_ADDR'] for a security feature. 这就是为什么一般规则是不依赖于$_SERVER['REMOTE_ADDR']来获得安全功能。

With all that aside is there a curl php method to also hide/mask/change the ip? 除此之外还有一个curl php方法来隐藏/掩盖/更改ip? (any other php method aside from the above code would do.) (除了上面的代码之外的任何其他php方法都可以。)

AND

Is there a way for countering the method OR Is there a way to get the ACTUAL REAL IP of a user? 有没有办法对抗方法有没有办法获得用户的ACTUAL REAL IP

Cheers! 干杯!

No. $_SERVER['REMOTE_ADDR'] is the actual physical IP address the client used to connect to the webserver, as confirmed by a three-way TCP handshake. $_SERVER['REMOTE_ADDR']是实际的物理IP地址用于连接到网络服务器,通过三方TCP握手证实客户端。 There's no way to fake this by setting simple HTTP headers. 没有办法通过设置简单的HTTP标头来伪装它。 You also cannot make the webserver/PHP overwrite this value with something else in any way. 您也无法使webserver / PHP以任何方式用其他内容覆盖此值。 $_SERVER['REMOTE_ADDR'] is set from TCP connection information, period. $_SERVER['REMOTE_ADDR']是根据TCP连接信息period设置的。

To actually spoof an IP address, you have to go much deeper into the actual network layer and have some level of control over network equipment/man in the middle positions/proxies/whatnot to actually be able to establish a TCP connection from an IP address other than the one you're establishing it from. 要实际欺骗IP地址,您必须更深入地了解实际网络层,并对中间位置/代理中的网络设备/人员进行某种程度的控制/实际上能够从IP地址建立TCP连接除了你建立它的那个。

Is there a way for countering the method OR Is there a way to get the ACTUAL REAL IP of a user? 有没有办法对抗方法或有没有办法获得用户的ACTUAL REAL IP?

No. "The actual IP address of the user" is the address your webserver received the connection from, period. 不可以。“用户的实际IP地址”是您的网络服务器从中获取连接的地址。 There is no other address for you. 没有其他地址适合您。 The client connects to your server from a certain IP, this is confirmed with a three-way TCP handshake, that's the only address you know for this client. 客户端从某个IP连接到您的服务器,这通过三方TCP握手确认,这是您知道的该客户端的唯一地址。 This client may be a proxy or a NAT router (ie a proxy) or something else, you simply do not know and neither should it make any difference to you. 这个客户端可能是代理或NAT路由器(即代理)或其他东西,你根本就不知道,也不应该对你产生任何影响。

If the client uses a browser behind a proxy, the $_SERVER['REMOTE_ADDR'] will be the IP address of the proxy. 如果客户端使用代理后面的浏览器, $_SERVER['REMOTE_ADDR']将是代理的IP地址。 The remote address is the IP of the machine that is making the connection. 远程地址是进行连接的计算机的IP。

If the proxy uses headers to indicate if the connection is performed in behalf of other machines, you can use these headers to determine the IP of the browser behind the proxy. 如果代理使用标头来指示是否代表其他计算机执行连接,则可以使用这些标头来确定代理后面的浏览器的IP。

  • Some of these HTTP headers are converted to environment variables such as $_SERVER['HTTP_X_FORWARDED_FOR'] , $_SERVER['HTTP_X_FORWARDED'] , $_SERVER['HTTP_FORWARDED_FOR'] and $_SERVER['HTTP_FORWARDED'] 其中一些HTTP标头转换为环境变量,例如$_SERVER['HTTP_X_FORWARDED_FOR']$_SERVER['HTTP_X_FORWARDED']$_SERVER['HTTP_FORWARDED_FOR']$_SERVER['HTTP_FORWARDED']
  • You may check if some of these variables have been defined by the server and (try to) determine the IP of the browser behind of the proxy. 您可以检查服务器是否已定义其中一些变量,并(尝试)确定代理后面的浏览器的IP。

Note that the RFC 6648 deprecated the X-* headers and the RFC 7239 deprecated X-Forwarded-* by defining a Forwarded header. 请注意, RFC 6648弃用了X-*标头, RFC 7239通过定义Forwarded标头弃用了X-Forwarded-*

You can check some answers at 你可以查看一些答案

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

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