我的服务器依靠IP过滤来保证安全.我想知道是否有人可以绕过保护,依赖于远程IP过滤使用net.SplitHostPort(r.RemoteAddr)
为此,我创建了这个虚拟的HTTP服务器:
package main
import (
"fmt"
"net"
"net/http"
)
func getHello(w http.ResponseWriter, r *http.Request) {
fmt.Printf("got /hello request\n")
host, _, _ := net.SplitHostPort(r.RemoteAddr)
fmt.Printf("Ip is %s\n", host)
}
func main() {
http.HandleFunc("/hello", getHello)
http.ListenAndServe(":3333", nil)
}
然后我用Curl做了一些测试:
curl http://localhost:3333/hello
<- Logs in my server -> Ip is 127.0.0.1
curl http://localhost:3333/hello -H "X-Forwarded-For: 3.3.3.3" -H "Host: 3.3.3.3"
<- Logs in my server -> Ip is 127.0.0.1
这似乎是安全的,因为我无法欺骗我的服务器认为请求的IP是3.3.3.3
.
r.RemoteAddr
是否真的安全并查找TCP数据包内部的IP?或者,有没有办法通过使用报头或伪造数据包来绕过它?