pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

epixoip private pastebin - collaborative debugging tool What's a private pastebin?


Posted by epixoip on Tue 19 May 07:08
report abuse | View followups from epixoip | download | new post

  1. #!/usr/bin/perl
  2. # Mon May 18 13:33:40 PDT 2009 by epixoip <epixoip@hush.com>
  3. # multi-threaded scanner for webdav-enabled servers. note this
  4. # does NOT tell you if your server is vulnerable to any WebDAV
  5. # exploits! it only tells you if WebDAV is enabled.
  6.  
  7.  
  8. $|++;
  9. use IO::Socket;
  10. use threads;
  11. use Thread::Queue;
  12. use Term::ANSIColor qw(:constants);
  13. our $starttime : shared;
  14. our $count : shared;
  15. our $hostcnt : shared;
  16. our $thrnum :  shared = 75; # change to adjust performance
  17. our $q : shared;
  18. our %webdav : shared;
  19.  
  20. sub scan {
  21.         my $host = shift;
  22.         my $sock = new IO::Socket::INET (PeerAddr => "$host:http(80)",Timeout => 1);
  23.         if ($sock) {
  24.                 print $sock "OPTIONS * HTTP/1.0\n\n";
  25.                 while (<$sock>) {
  26.                         if ( $_ =~ /^(?:Allow|Public)\:\ (.*(?:COPY|MOVE|MKCOL|PROPFIND|PROPPATCH|LOCK|UNLOCK|SEARCH))/img ) {
  27.                                 $webdav{$host} = $1;
  28.                         }
  29.                 }
  30.                 close $sock;
  31.         }
  32. }
  33.  
  34. sub report {
  35.         print BOLD WHITE."\n\n[".GREEN."+".WHITE."]".RESET." The following hosts were discovered supporting WebDAV:\n";
  36.         while ( my ($key, $value) = each(%webdav) ) { print "\t$key \t=> $value\n"; }
  37.         exit;
  38. }
  39.  
  40. sub main {
  41.         print BOLD WHITE."[".GREEN."+".WHITE."]".RESET." Building queue... ";
  42.         $q = new Thread::Queue;
  43.         my $file = shift;
  44.         open HOSTS, $file or die $!;
  45.         while (<HOSTS>) { chomp $_; $q->enqueue($_); $hostcnt++; }
  46.         close HOSTS;
  47.         print "added $hostcnt hosts\n";
  48.         print BOLD WHITE."[".GREEN."+".WHITE."]".RESET." $thrnum worker thread(s) will be spawned\n";
  49.         print BOLD WHITE."[".GREEN."+".WHITE."]".RESET." WebDAV scan initiated for $hostcnt hosts\n";
  50.         while (1) {
  51.                 my @threads = threads->list;
  52.                 if ($q->pending > 0) {
  53.                         if  ($#threads <= $thrnum + 1) {
  54.                                 threads->new(\&scan, $q->dequeue);
  55.                                 $count++;
  56.                         } else {
  57.                                 foreach $running (@threads) {
  58.                                         $running->join();
  59.                                 }
  60.                         }
  61.                         my $percent = $count / $hostcnt * 100;
  62.                         $width = `tput cols` - 35;
  63.                         $char = ON_GREEN " ". RESET;
  64.                         printf GREEN."---".RESET." %s hosts scanned  %s %.0f%%\r", $count, $char x (($width)*$count/$hostcnt), $percent;
  65.                 } else {
  66.                         if ($#threads > 0) {
  67.                                 foreach $running (@threads) {
  68.                                         $running->join();
  69.                                 }
  70.                         }
  71.                         &report;
  72.                 }
  73.         }
  74. }
  75.  
  76. &main($ARGV[0]);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post