【问题标题】:Need help understanding DNSfilter script需要帮助了解 DNSfilter 脚本
【发布时间】:2016-05-04 17:38:36
【问题描述】:

我在 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;

【问题讨论】:

    标签: dns


    【解决方案1】:

    这是一个写得很糟糕的 Perl 脚本,似乎旨在窥探网络流量并记录所有传入 DNS 数据包的日志。为什么它被称为“过滤器”你得问是谁写的。

    请不要将此脚本用作编写 Perl 的示例。这些行是作者调用外部程序来过滤文本和日期格式是巨大的危险信号,他对 Perl 知之甚少,而带有一个 grep 和两个 awk 的行表明他没有对awk 或shell 编程也不太了解。最重要的是,大部分脚本都是从Net::Pcap::Easy 模块的文档中剪切并粘贴的(包括那里的一条评论)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-19
      • 2016-05-03
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多