|
(view this code in a separate window) #!/usr/bin/perl # # pasv_ports.pl # # Determine if an FTP server uses sequential # ports in response to the PASV command # # Copyright 2002, Bri Hatch # Released under the GPL. See COPYING file # for more information. use FileHandle; $|=1; $hostname = shift @ARGV; $username=shift @ARGV || 'anonymous' if @ARGV; $password=shift @ARGV || 'mozilla@' if @ARGV; die "Usage: $0 ftpserver [username [password] ]" if @ARGV or !$hostname; defined ($pid = open NETCAT, "-|" ) || die "open"; if ( $pid ) { # parent NETCAT->autoflush(1); for ( <NETCAT> ) { push @ports, $1*256+$2 if /\( \d+,\d+,\d+,\d+, (\d+),(\d+) \)/x; # IP ADDRESS PORT } } else { open NC, "|nc $hostname 21" or die "Can't fork netcat"; NC->autoflush(1); print NC "USER $username\nPASS $password\n"; for ( 1..10 ) { sleep 1; print NC "PASV\n"; } print NC "QUIT\n"; close NC; exit 0; } print "The passive ports opened were:\n@ports\n";
|