Author Topic: [Perl] Anonymous FTP scanner  (Read 588 times)

0 Members and 1 Guest are viewing this topic.

Offline Freak

  • /dev/null
  • *
  • Posts: 17
  • Cookies: 3
    • View Profile
[Perl] Anonymous FTP scanner
« on: March 16, 2015, 09:04:34 pm »
It's my spring break so I've been programming a bit, and yesterday I whipped this up.

You enter 2 IPv4 addresses (a start and an end) and it will try to connect to anonymous FTP on every address between those two addresses, then it will write all of the addresses that it worked on to a file called "list.txt"

I just made it really quick so I didn't really bother to make it user-proof. If you give it something other than an IPv4 address it will probably crash. If your end IP comes before your start IP it will scan everything between the start address and 255.255.255.255

I also set the timeout to only 5 seconds, so if you're on a slow network or something you could get false negatives, but this way it won't take 1000 years to finish.

Code: [Select]
#!/usr/bin/perl -w
use strict;
use Net::FTP;
my(@ipArr, $end, $ftp);
print "Enter the start IP:\n>  ";
chomp(@ipArr = split(/\./, <STDIN>));
print "Enter the end IP:\n>  ";
chomp($end = <STDIN>);
open FILE, ">list.txt" or die "Error: $!\n";
for(; $ipArr[0]<=255; ++$ipArr[0]){
   for(; $ipArr[1]<=255; ++$ipArr[1]){
      for(; $ipArr[2]<=255; ++$ipArr[2]){
         for(; $ipArr[3]<=255; ++$ipArr[3]){
            if($end eq $ipArr[0]."\.".$ipArr[1]."\.".$ipArr[2]."\.".($ipArr[3]-1)){
               print "Done.\n";
               close FILE;
               exit(1);
            }
            $ftp = Net::FTP->new($ipArr[0]."\.".$ipArr[1]."\.".$ipArr[2]."\.".$ipArr[3], Timeout => 5) or next;
            $ftp->login() or do{$ftp->quit(); next;};
            $ftp->quit;
            print FILE $ipArr[0]."\.".$ipArr[1]."\.".$ipArr[2]."\.".$ipArr[3]."\n";
         }
         $ipArr[3] = 0;
      }
      $ipArr[2] = 0;
   }
   $ipArr[1] = 0;
}
print "Something unexpected happened.\n";
close FILE;


Enjoy :)