Perl CPAN PowerDNS modules released.

Tuesday, January 1st, 2008

I have released several PowerDNS modules to CPAN:

http://search.cpan.org/~augie/

PowerDNS::Backend::MySQL Provides an interface to manipulate PowerDNS data in the MySQL Backend.

PowerDNS::Control::Client Provides an interface to control the PowerDNS daemon.

PowerDNS::Control::Server Provides an interface to control the PowerDNS daemon.

The MySQL interface is based on code I have in production, but currently is not what I have running, yet.

The Client/Server Control code I do have running in production; although they currently only implement the features I needed to deploy.

Replay DNS traffic – dnsreplay.pl

Thursday, November 9th, 2006

The following is a handy little script for replaying DNS traffic and thus verifying that a Name Server will answer as you expect it to.

Updated: Tue Apr 15 16:12:59 PDT 2008.

#!/usr/bin/perl
# Augie Schwer
# dnsreplay.pl - replay a BIND query log and print to STDOUT
# when a query fails against the given name server.
# $Id: dnsreplay.pl 1829 2008-04-15 23:07:12Z augie $

use strict;
use Net::DNS;
use Getopt::Long;

my %options=();

GetOptions( \%options ,
"nameserver=s", "querylog=s", "port=i", "recurse", "help"
);

my $nameserver = $options{'nameserver'};
my $querylog = $options{'querylog'};
my $port = $options{'port'};
my $recurse = $options{'recurse'};
my $help = $options{'help'};

if ( $help ) { print "Usage: dnsreplay.pl --nameserver=NAMESERVER --querylog=QUERYLOG [--port=PORT NUMBER] [--recurse]\n"; exit;}

my $res = Net::DNS::Resolver->new(
'nameservers' => [$nameserver],
'recurse' => $recurse,
'debug' => 0,
'port' => 53 || $port
);

open(FILE,"< $querylog") or die("Could not open $querylog: $!");
while()
{
my ($zone,$type) = (split)[3,5];

if ( $type eq 'A6' ) # Net::DNS does not understand A6 records.
{ print "Skipping A6 Record.\n"; next; }

my $packet = $res->send($zone,$type);

if ( ! defined $packet )
{
warn "Packet not defined for ($zone,$type).\n";
print "Packet not defined for ($zone,$type).\n";
next;
}

if( $packet->answer )
{ print "$nameserver answered for $zone of type $type .\n"; }
else
{ print "$nameserver did not answer for $zone of type $type .\n"; }
}
close(FILE);

To get the Query Log out of BIND put the following in to your named.conf :

logging {
channel queries {
file "query.log";

};
category queries { queries; };
};

Count bandwidth

Saturday, September 3rd, 2005

Ed: this has been sitting in my “drafts” box for a while now, so I figure I might as well just push it out.

Here’s a script I wrote to count the bandwidth used from the Apache access_log:

#!/usr/bin/perl -w

use strict;

my $access_log = $ARGV[0];
my $total = 0;
my @chunks;

open(LOGFILE, $access_log) or die "Could not open $access_log $!";

# count amount of data.
while(<logfile>)
{
@chunks = split();
if($chunks[9] =~ /\d/)
{ $total += $chunks[9]; }
}

close(LOGFILE);

# convert to human readable; 1024 * 1024 = 1048576.
$total /= 1048576;

print "Amount of bandwidth : $total MB\n";

Vulnerable phpBB : Find and Disable.

Monday, July 18th, 2005

Here’s a little script I wrote that attempts to find and disable old phpBB instances that may be vulnerable to the recent phpBB Worm in the wild.


#!/usr/bin/perl
# Name: Augie Schwer
# File: find-vuln.pl
# Date: 18, July 2005
# Purpose: Find vulnerable phpBBs and disable them.

use strict;

my ($line,$location,$user,$this_version,$newest_version);

$newest_version = '2005/06/26';

# where to search.
my $webdir = '/home/WWW_pages/';

# spawn sub shell and find the viewtopic.php and capture its version and location.
my @output = `find $webdir -type f -name viewtopic.php -print | xargs --verbose grep '\$Id: viewtopic.php,v' 2>&1`;

# parse out location and version.
foreach $line (@output)
{
if($line =~ /(.+?): .+ \$Id: viewtopic.php,v .+ (\d{4}\/\d{2}\/\d{2}) .+/)
{
$location = $1;
$this_version = $2;

# old phpBB, disable it.
if($this_version ne $newest_version)
{ print "OLD PHPBB\n" ; `chmod 000 $location`; }

print "Location: $location \n";
print "This V : $this_version \n";
print "New V : $newest_version \n";
}
}