我在Github上做了一些搜索并遇到了这个特殊的脚本,并且想知道是否有人可以帮助解释这个脚本在技术上的作用?我一直在进行大量关于DNS过滤的研究,并试图更好地了解DNS过滤实际上是什么,以及人们如何滥用它。这是有问题的剧本:
use strict;
use warnings;
use Net::Pcap;
use Net::Pcap::Easy;
if ( $#ARGV != 2 ) {
print "Usage: perl filter.pl <outputfile> <minbytereply> <domain>\n";
print " Example: perl filter.pl output.txt 3000 1x1.cz\n";
print " Coded by Vypor, https://github.com/Vypor\n";
exit(1);
}
my $err;
my $minbytes = $ARGV[1];
my $domain = $ARGV[2];
my $interface = pcap_lookupdev( \$err );
my $ethip = `/sbin/ifconfig $interface | grep "inet addr" | awk -F: '{print \$2}' | awk '{print \$1}'`;
$ethip = substr( $ethip, 0, -1 );
# all arguments to new are optoinal
my $npe = Net::Pcap::Easy->new(
dev => $interface,
filter => "not src host $ethip and port 53 and greater $minbytes",
packets_per_loop => 10,
bytes_to_capture => 1024,
timeout_in_ms => 0, # 0ms means forever
promiscuous => 0, # true or false
udp_callback => sub {
my ($npe, $ether, $ip, $udp, $header ) = @_;
my $xmit = `date +"%H:%M:%S"`;
chomp($xmit);
print "$xmit $ip->{src_ip} -> $ip->{dest_ip} $udp->{len}\n";
open (FFILE, ">>$ARGV[0]");
print FFILE "$ip->{src_ip} $domain $udp->{len}\n";
close FFILE;
},
);
1 while $npe->loop;
答案 0 :(得分:0)
这是一个写得很糟糕的Perl脚本,似乎旨在窥探网络流量并写入所有传入DNS数据包的日志。为什么它被称为&#34;过滤&#34;你不得不问谁是谁写的。
请不要使用此脚本作为如何编写Perl的示例。这些行是作者呼吁外部程序过滤文本和格式日期是巨大的红旗,他对Perl知之甚少,并且其中有一个Uncaught exception 'Thrift\Exception\TTransportException' with message 'TSocket: timed out reading 4 bytes from localhost:10000' in /Users/lazhcm10385/projects/hive/hive-hs2-php-thrift/thrift/Thrift/Transport/TSocket.php:274
和两个grep
的行显示他对awk
或shell编程也不太了解。最重要的是,大部分脚本都是从awk
模块的文档中剪切出来的(包括那里的一个注释)。