小贝博客

主机资讯以及工具软件分享

套用cloudflare后防止真实ip地址泄露

背景介绍

今天看到一篇文档,通过censys.io可以查出套用cf以后的真实ip地址,
如果你不相信,可以去下面的地址查一下

https://censys.io/ipv4?q=你的域名

会列出所有你的ip

解决方案

1、服务端使用cloudflare的自签名证书,设置强制跳转到https

2、cloudflare的ssl加密部分选择 FULL 模式

3、部署Authenticated Origin Pulls

下面内容保存成cloudflare.crt

-----BEGIN CERTIFICATE-----
MIIGBjCCA/CgAwIBAgIIV5G6lVbCLmEwCwYJKoZIhvcNAQENMIGQMQswCQYDVQQG
EwJVUzEZMBcGA1UEChMQQ2xvdWRGbGFyZSwgSW5jLjEUMBIGA1UECxMLT3JpZ2lu
IFB1bGwxFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xEzARBgNVBAgTCkNhbGlmb3Ju
aWExIzAhBgNVBAMTGm9yaWdpbi1wdWxsLmNsb3VkZmxhcmUubmV0MB4XDTE1MDEx
MzAyNDc1M1oXDTIwMDExMjAyNTI1M1owgZAxCzAJBgNVBAYTAlVTMRkwFwYDVQQK
ExBDbG91ZEZsYXJlLCBJbmMuMRQwEgYDVQQLEwtPcmlnaW4gUHVsbDEWMBQGA1UE
BxMNU2FuIEZyYW5jaXNjbzETMBEGA1UECBMKQ2FsaWZvcm5pYTEjMCEGA1UEAxMa
b3JpZ2luLXB1bGwuY2xvdWRmbGFyZS5uZXQwggIiMA0GCSqGSIb3DQEBAQUAA4IC
DwAwggIKAoICAQDdsts6I2H5dGyn4adACQRXlfo0KmwsN7B5rxD8C5qgy6spyONr
WV0ecvdeGQfWa8Gy/yuTuOnsXfy7oyZ1dm93c3Mea7YkM7KNMc5Y6m520E9tHooc
f1qxeDpGSsnWc7HWibFgD7qZQx+T+yfNqt63vPI0HYBOYao6hWd3JQhu5caAcIS2
ms5tzSSZVH83ZPe6Lkb5xRgLl3eXEFcfI2DjnlOtLFqpjHuEB3Tr6agfdWyaGEEi
lRY1IB3k6TfLTaSiX2/SyJ96b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bz+1CD4D/bWrs3cC9+kk/jFmrrAymZlkFX8tDb5aXASSLJjUjcptci9SKqtI2h0J
wUGkD7+bQAr+7vr8/R+CBmNMe7csE8NeEX6lVMF7Dh0a1YKQa6hUN18bBuYgTMuT
QzMmZpRpIBB321ZBlcnlxiTJvWxvbCPHKHj20VwwAz7LONF59s84ZsOqfoBv8gKM
s0s5dsq5zpLeaw==
-----END CERTIFICATE-----

nginx增加下面配置

sl_client_certificate /etc/nginx/certs/cloudflare.crt;
ssl_verify_client on;

4、重启nginx,直接访问网站会提示400 Bad Request

5、cloudflare启用认证来源 Authenticated Origin Pulls 设置为on

安全了

不过censys保存的快照不知道什么时候可以删除

以上内容参考 这里的文档

后续

逛论坛发现有人说了下原理如下:
扫描ip,然后https://ip 取得证书,还有默认网站内容
如果某网址内容和证书一样,就是认为这个ip为源

简单解决方案:

宝塔新建个网站,
域名填写ip,作为default,
搞张自签名的ip证书加上,
直接访问ip或者其他恶意指向都会定向到这个默认的ip站点
自签名证书教程

本原创文章未经允许不得转载 | 当前页面:小贝博客 » 套用cloudflare后防止真实ip地址泄露

评论