为什么从 Perl 读入 Snort 日志文件时显示错误?
我正在编写一个 Perl 程序来读取 Snort 日志文件。我使用 VMware 运行 Fedora 14。
使用命令 /usr/loca/bin/snort -r /var/log/snort/snort.log.1299686068
时,我得到结果:
03/08-21:16:03.609258 172.16.115.87:4159 -> 205.181.112.67:80
TCP TTL:63 TOS:0x0 ID:3588 IpLen:20 DgmLen:385 DF
***AP*** Seq: 0xEB6DE4B0 Ack: 0xD00D0DA6 Win: 0x7D78 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
03/08-21:16:03.627973 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2458 IpLen:20 DgmLen:40 DF
***A**** Seq: 0xD00D0DA6 Ack: 0xEB6DE609 Win: 0x7E87 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
03/08-21:16:03.651503 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2459 IpLen:20 DgmLen:978 DF
***AP*** Seq: 0xD00D0DA6 Ack: 0xEB6DE609 Win: 0x7FE0 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+^C
*** Caught Int-Signal
03/08-21:16:03.654590 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2460 IpLen:20 DgmLen:40
***A***F Seq: 0xD00D1150 Ack: 0xEB6DE609 Win: 0x7FE0 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
列出了目标和源 IP 地址以及更多信息,但是当我使用Perl编写程序来读取它们时,列出的是未知符号。
日志文件是否受 Snort 保护,或者还有其他问题吗?它并不完全 100% 显示与第一个示例相同的结果,但至少清楚地列出了所有内容。
我的代码是:
#!/usr/local/bin/perl
use File::Tail;
opendir L_FOL, "/var/log/snort" || die "Could not open LOGFOLDER direcotry\n $!";
my @allrule = grep {/^snort.log./} readdir L_FOL;
close L_FOL;
foreach my $rulefile (@allrule) {
open(LF, "/var/log/snort/$rulefile") or die "$!";
while (<LF>) {
print "$_\n";
}
close(LF);
}
I am writing a Perl program to read a Snort log file. I run Fedora 14 using VMware.
When using the command /usr/loca/bin/snort -r /var/log/snort/snort.log.1299686068
I get the result:
03/08-21:16:03.609258 172.16.115.87:4159 -> 205.181.112.67:80
TCP TTL:63 TOS:0x0 ID:3588 IpLen:20 DgmLen:385 DF
***AP*** Seq: 0xEB6DE4B0 Ack: 0xD00D0DA6 Win: 0x7D78 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
03/08-21:16:03.627973 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2458 IpLen:20 DgmLen:40 DF
***A**** Seq: 0xD00D0DA6 Ack: 0xEB6DE609 Win: 0x7E87 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
03/08-21:16:03.651503 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2459 IpLen:20 DgmLen:978 DF
***AP*** Seq: 0xD00D0DA6 Ack: 0xEB6DE609 Win: 0x7FE0 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+^C
*** Caught Int-Signal
03/08-21:16:03.654590 205.181.112.67:80 -> 172.16.115.87:4159
TCP TTL:64 TOS:0x0 ID:2460 IpLen:20 DgmLen:40
***A***F Seq: 0xD00D1150 Ack: 0xEB6DE609 Win: 0x7FE0 TcpLen: 20
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
The destination and source IP address and more information is listed, but when I use Perl to write a program to read them, what list out is unknown symbol.
Isn't the log file protected by Snort or what else could be the problem? It is not exactly 100% displaying the result same as in the 1st example but at least clearly list out everything.
My code is:
#!/usr/local/bin/perl
use File::Tail;
opendir L_FOL, "/var/log/snort" || die "Could not open LOGFOLDER direcotry\n $!";
my @allrule = grep {/^snort.log./} readdir L_FOL;
close L_FOL;
foreach my $rulefile (@allrule) {
open(LF, "/var/log/snort/$rulefile") or die "$!";
while (<LF>) {
print "$_\n";
}
close(LF);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Snort 日志文件采用二进制 (tcpdump) 格式。你不能只将它们作为文本来阅读。
如果你想这样做,你需要告诉 snort 使用
-K ascii
选项将它们写为 ASCII。问题是,这可能会导致您的 snort 无法跟上。更好的选择是简单地将 snort 的输出通过管道传输到 Perl 程序中并阅读:
请注意,这是非常旧的 Perl 语法,实际上不应再使用。您应该避免使用裸词并使用三个参数
open()
Your Snort log files are in a binary (tcpdump) format. You can't just read them as text.
If you want to do that, you'd need to tell snort to write them as ASCII with the
-K ascii
option.The problem is, that may cause you problems with snort being able to keep up. The better option is to simply pipe the output of snort into your perl program and read that:
Note that this is very old perl syntax and really shouldn't be used any longer. You should be avoiding barewords and using the three argument
open()