我正在寻找一种在网站源代码中混淆 mailtos 的方法。我想从此开始:
href="mailto:[email protected]"
对此:
href="" onmouseover="this.href='mai'+'lto:'+'pre'+'sid'+'ent'+'@wh'+'ite'+'hou'+'se.'+'gov'"</code>
我可能会改用 PHP 解决方案,比如 this (这样我只需全局替换整个 mailto,我这边的源代码看起来会更好),但我花了太多时间查看sed 和 Perl,现在我无法停止思考如何做到这一点!有什么想法吗?
更新: 很大程度上基于 eclark 的解决方案,我最终想出了这个:
#!/usr/bin/env perl -pi
if (/href="mailto/i) {
my $start = (length $`) +6;
my $len = index($_,'"',$start)-$start;
substr($_,$start,$len,'" onmouseover="this.href=' .
join('+',map qq{'$_'}, substr($_,$start,$len) =~ /(.{1,3})/g));
}
#!/usr/bin/perl
use strict; use warnings;
my $s = 'mailto:[email protected]';
my $obfuscated = join('+' => map qq{'$_'}, $s =~ /(.{1,3})/g );
print $obfuscated, "\n";
输出:
'mai'+'lto'+':pr'+'esi'+'den'+'t@w'+'hit'+'eho'+'use'+'.go'+'v'
请注意,
'lto:
是四个字符,而看起来您需要三个字符组。
基于 Sinan 的想法,这里有一个简短的 Perl 脚本,它将逐行处理文件。
#!/usr/bin/env perl -p
my $start = index($_,'href="') +6;
my $len = index($_,'"',$start)-$start;
substr($_,$start,$len+1,'" onmouseover="this.href=' .
join('+',map qq{'$_'}, substr($_,$start,$len) =~ /(.{1,3})/g)
);
如果您要使用它,请确保将旧文件提交到源代码管理,并将 -p 选项更改为 -i,这将重写文件。
只是一个例子。
$ echo $s
href="mailto:[email protected]"
$ echo $s | sed 's|\(...\)|\1+|g' | sed 's/hre+f=\"/href="" onmouseover="this.href=/'
href="" onmouseover="this.href=+mai+lto+:pr+esi+den+t@w+hit+eho+use+.go+v"
确认! Thppfft!我给你这个毛球:
s='href="mailto:[email protected]"'
echo "$s" | sed -n 's/=/=\x22\x22\n/;
h;
s/\n.*//;
x;
s/[^\n]*\n//;
s/"//g;
s/\(...\)/\x27&\x27+/g;
s/.*/onmouseover=\x22this.href=&\x22/;
x;
G;
s/\n//2;
s/+\([^\x22]\{1,2\}\)\x22$/+\x27\1\x27\x22/;
s/+\x22$/\x22/;
p'
这足够接近吗?
use strict;
use warnings;
my $old = 'href="mailto:[email protected]"';
$old =~ s/href="(.*)"/$1/;
my $new = join '+', map { qq('$_') } grep { length $_ } split /(.{3})/, $old;
$new = qq(href=""\nonmouseover="this.href=$new\n");
print "$new\n";
输出:
href=""
onmouseover="this.href='mai'+'lto'+':pr'+'esi'+'den'+'t@w'+'hit'+'eho'+'use'+'.go'+'v'
"