Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created May 1, 2014 17:19
Show Gist options
  • Select an option

  • Save warewolf/bbc4f58b6b95ff57cf23 to your computer and use it in GitHub Desktop.

Select an option

Save warewolf/bbc4f58b6b95ff57cf23 to your computer and use it in GitHub Desktop.
dns2rule.pl
#!/usr/bin/perl
# usage:
# perl dns2rule.pl "context string" < list.of.newline.delimited.domains.txt
use strict;
use warnings;
my $addon_string = shift @ARGV;
foreach my $domain (<>) {
# remove trailing newline or carraige return
$domain =~ s/[\r\n]*$//g;
next unless (length($domain) > 0);
printf('alert udp $HOME_NET any -> $EXTERNAL_NET 53 (msg:"BLACKLIST DNS request for domain %s%s"; flow:to_server; byte_test:1,!&,0xF8,2; content:"%s|00|"; fast_pattern:only; metadata:impact_flag red, service dns; classtype:trojan-activity;)'."\n",
$domain,
defined($addon_string)?" $addon_string":"",
join("",map { "|".sprintf("%02x",length($_))."|".$_ } split(m/\./,$domain))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment