一个有趣的问题。我在linux上有类似的问题。如果可执行文件的哈希值突然发生变化,OSSEC 或tripwire 等入侵检测系统可能会产生误报。这可能比 Linux“预链接”程序修补可执行文件以加快启动速度更糟糕。
为了比较两个二进制文件(在ELF format 中),可以使用“readelf”可执行文件,然后使用“diff”来比较输出。我确信有完善的解决方案,但事不宜迟,Perl 中的一个穷人的比较器:
#!/usr/bin/perl -w
$exe = $ARGV[0];
if (!$exe) {
die "Please give name of executable\n"
}
if (! -f $exe) {
die "Executable $exe not found or not a file\n";
}
if (! (`file '$exe'` =~ /\bELF\b.*?\bexecutable\b/)) {
die "file command says '$exe' is not an ELF executable\n";
}
# Identify sections in ELF
@lines = pipeIt("readelf --wide --section-headers '$exe'");
@sections = ();
for my $line (@lines) {
if ($line =~ /^\s*\[\s*(\d+)\s*\]\s+(\S+)/) {
my $secnum = $1;
my $secnam = $2;
print "Found section $1 named $2\n";
push @sections, $secnam;
}
}
# Dump file header
@lines = pipeIt("readelf --file-header --wide '$exe'");
print @lines;
# Dump all interesting section headers
@lines = pipeIt("readelf --all --wide '$exe'");
print @lines;
# Dump individual sections as hexdump
for my $section (@sections) {
@lines = pipeIt("readelf --hex-dump='$section' --wide '$exe'");
print @lines;
}
sub pipeIt {
my($cmd) = @_;
my $fh;
open ($fh,"$cmd |") or die "Could not open pipe from command '$cmd': $!\n";
my @lines = <$fh>;
close $fh or die "Could not close pipe to command '$cmd': $!\n";
return @lines;
}
现在您可以在例如机器 1 上运行:
./checkexe.pl /usr/bin/curl > curl_machine1
在机器 2 上:
./checkexe.pl /usr/bin/curl > curl_machine2
将文件复制粘贴、SFTP-ed 或 NSF-ed(您不使用 FTP,对吗?)后,将文件放入同一个文件树中,比较文件:
diff --side-by-side --width=200 curl_machine1 curl_machine2 | less
就我而言,“.gnu.conflict”、“.gnu.liblist”、“.got.plt”和“.dynbss”部分存在差异,这对于“预链接”干预可能是可以的,但在代码部分“.text”,这将是一个坏标志。