我有一个开发站点和生产站点:
我在底部有一个mailto电子邮件链接,php源代码完全如下:
<section>
<h2>Looking for a LAMP, WordPress or Drupal Developer?</h2>
<p>Contact me today: <br/>
<a href='mailto:mail@example.com'>mail@example.com</a>
<br/>
<a href='tel:+13334445555'>333 444 5555</a>
</p>
</section>
在我的开发网站上一切正常,生成的 html 如下:
<section>
<h2>Looking for a LAMP, WordPress or Drupal Developer?</h2>
<p>Contact me today: <br>
<a href="mailto:mail@example.com">mail@example.com</a>
<br>
<a href="tel:+13334445555">333 444 5555</a>
</p>
</section>
然后神秘地在我的生产站点上添加了一些 javascript 我的 mailto 链接(并且只有 mailto 链接,在这种情况下只是一个,但我添加了更多并且脚本也添加到了它们中)这是生产站点上的 html 输出:
<section>
<h2>Looking for a LAMP, WordPress or Drupal Developer?</h2>
<p>Contact me today: <br>
<a href="mailto:mail@example.com">mail@example.com
<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function() {for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */
</script>
</a>
<br>
<a href="tel:+13334445555">333 444 5555</a>
</p>
</section>
我已经检查了生产服务器上的代码,此脚本不存在。
可能发生了什么?
ColdFusion无关。在此代码中,cf-hash
是 SCRIPT
标记(纯 HTML)的属性。搜索'cf-hash="f9e31"会得到很多类似的代码。找到此链接,指向它可能是CloudFlare电子邮件保护脚本。这将是在您的生产服务器上运行的内容,而不是在您的本地开发环境中。
不同语言的电子邮件去混淆:
爪哇语
function cfDecodeEmail(encodedString) {
var email = "", r = parseInt(encodedString.substr(0, 2), 16), n, i;
for (n = 2; encodedString.length - n; n += 2){
i = parseInt(encodedString.substr(n, 2), 16) ^ r;
email += String.fromCharCode(i);
}
return email;
}
console.log(cfDecodeEmail("543931142127353935313e352e7a373b39")); // usage
蟒
def cfDecodeEmail(encodedString):
r = int(encodedString[:2],16)
email = ''.join([chr(int(encodedString[i:i+2], 16) ^ r) for i in range(2, len(encodedString), 2)])
return email
print( cfDecodeEmail('543931142127353935313e352e7a373b39') ) # usage
.PHP
function cfDecodeEmail($encodedString){
$k = hexdec(substr($encodedString,0,2));
for($i=2,$email='';$i<strlen($encodedString)-1;$i+=2){
$email.=chr(hexdec(substr($encodedString,$i,2))^$k);
}
return $email;
}
echo cfDecodeEmail('543931142127353935313e352e7a373b39'); // usage
去
package main
import (
"bytes"
"strconv"
)
func cf(a string) (s string) {
var e bytes.Buffer
r, _ := strconv.ParseInt(a[0:2], 16, 0)
for n := 4; n < len(a)+2; n += 2 {
i, _ := strconv.ParseInt(a[n-2:n], 16, 0)
e.WriteString(string(i ^ r))
}
return e.String()
}
func main() {
email := cf("543931142127353935313e352e7a373b39") // usage
print(email)
print("'n")
}
C++
#include <iostream>
#include <string>
using namespace std;
string cfDecodeEmail(string encodedString);
int main()
{
cout << cfDecodeEmail("543931142127353935313e352e7a373b39") << endl;
}
string cfDecodeEmail(string encodedString)
{
string email;
char xorKey = stoi( encodedString.substr(0, 2), nullptr, 16);
for( unsigned i = 2; i < encodedString.length(); i += 2)
email += stoi( encodedString.substr(i, 2), nullptr, 16) ^ xorKey;
return email;
}
C
using System;
public class Program
{
public static string cfDecodeEmail(string encodedString)
{
string email = "";
int r = Convert.ToInt32(encodedString.Substring(0, 2), 16), n, i;
for (n = 2; encodedString.Length - n > 0; n += 2)
{
i = Convert.ToInt32(encodedString.Substring(n, 2), 16) ^ r;
char character = (char)i;
email += Convert.ToString(character);
}
return email;
}
public static void Main(string[] args)
{
Console.WriteLine(cfDecodeEmail("543931142127353935313e352e7a373b39")); // usage
}
}
<小时 />源
CloudFlare默认会混淆您的电子邮件地址。如果您想忽略电子邮件的混淆,只需将它们包装在 HTML 注释标签中,如下所示。CloudFlare将忽略这些。
<!--email_off-->EMAIL ADDRESS<!--/email_off-->
来源: http://roaringapps.com/blog/cloudflare-email-obfuscation/
Cloudflare隐藏了电子邮件地址,以防止机器人从网页上抓取它们。
如果你是一个普通的Web用户而不是一个机器人,你将运行JavaScript。Cloudflare 注入 JavaScript 来解密电子邮件地址。
某些网页不允许运行内联 JavaScript,因此最终用户看不到电子邮件地址。
考虑改变网站发出的Content_Security策略元标记,以允许运行内联 JavaScript。
例如,请参阅"不安全内联"的使用;
"从Chrome 46开始,内联脚本可以通过在策略中指定源代码的base64编码哈希来列入白名单。此哈希必须以使用的哈希算法(sha256、sha384 或 sha512)为前缀。有关示例,请参阅元素的哈希用法。
更多有用的信息在这里 : https://developer.chrome.com/extensions/contentSecurityPolicy