#!/usr/bin/perl -s # this script is a quick hack to do a simple crawl over a key and its # signatures. the point of this exercise it to stress-test your key # server. i hacked this up to help test the db4 back-end. typically you # run a bunch of copies of this and search for different keys (or names) # from the top 1000 best-connected keys. # # Usage: pkspider [-l] [server[:port]] # # bsd licensed. # Copyright (C) 2003 Chris Kuethe # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. The name of the author(s) may not be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use LWP; die "Usage: $0 [-l] [server[:port]]" unless (scalar @ARGV); $SIG{INT} = \&bye; $SIG{QUIT} = \&bye; $SIG{ABRT} = \&bye; $SIG{HUP} = \&bye; $crawler = LWP::UserAgent->new; $crawler->agent("PKSpider/0.0 "); $| = 1; @keypath = (); #keys in the order they were searched %keylogs = (); #key has been searched @keytemp1 = (); # keys to be searched %keytemp2 = (); # key has been queued for searching $keytemp1[0] = $ARGV[0]; if (defined($ARGV[1])){ $server = $ARGV[1]; } else { $server = "127.0.0.1:11371"; } if (defined($l)){ open(L, ">$ARGV[0].log") || die "open($ARGV[0].log) -> $!"; } $kt = 0; while(scalar @keytemp1){ #uncomment or or the other of the next two lines # $cur = pop(@keytemp1); #depth-first search $cur = shift(@keytemp1); #breadth-first search next if ($keylogs{$cur}); push (@keypath, $cur); print "$cur "; $keylogs{$cur}=1; keydump($cur) if (defined($l)); $str = "http://${server}/pks/lookup?op=vindex&search=${cur}"; $req = HTTP::Request->new(GET => "$str"); $_ = $crawler->request($req); $_ = $_->content; @words = split; $retrieved = 0; foreach $w (@words){ next unless ($w =~ /vindex/); $k = (split(/[="]/, $w))[4]; next if ($keylogs{$k}); if ($keytemp2{$k} != 1){ push(@keytemp1, $k); $keytemp2{$k} = 1; $kt++ ; $retrieved++; } } print "[$retrieved] " if $retrieved; } bye(); ###################################################### sub bye{ print STDERR "\n" . "="x80 . "\nkey path:\n"; print STDERR "@keypath \n"; print STDERR "="x80 . "\nkeys searched: $kt\n"; exit 0; } ###################################################### sub keydump{ $cur = $_[0]; $str = "http://${server}/pks/lookup?op=get&search=${cur}"; $req = HTTP::Request->new(GET => "$str"); $_ = $crawler->request($req); $_ = $_->content; print L $_ if (/BEGIN PGP/); }