#!/usr/bin/perl use IO::Socket; use Net::Ping; $ip = $ARGV[0] or die ":: usage vt.ban [start port] [end port]\n"; $s_port = $ARGV[1] or $s_port = 1; $e_port = $ARGV[2] or $e_port = 1024; if ( !$ARGV[2] and $ARGV[1] ) { $e_port = $s_port; } @dont = (); # skip ports $do_ping = 0; $ping_timeout = 0.2; $request_timer = 1; $request_timeout = 4; $| = 1; $verbose = 1; $ports = "0_21:1_25:2_80:2_8080:3_110:4_79:"; @requests = ( "USER anonymous\nPASS l4m3r\@aol.com\nQUIT\n", "EHLO COMPUTER?\nQUIT\n", "OPTIONS / HTTP/1.0\n\n", "CAPA\nQUIT\n", "root\r\n" ); $req = "_kill_"; $skipped = 0; $last = $s_port; print "\n::::[ scanning host $ip ( ports $s_port - $e_port ) ]\n::\n"; if ( $do_ping == 1 ) { $p = Net::Ping->new("icmp"); if ( $p->ping( $ip, $ping_timeout ) ) { $ping_succeeded = 1; } } if ( $ping_succeeded or $do_ping == 0 ) { for ( $port = $s_port ; $port <= $e_port ; $port++ ) { foreach $skip (@dont) { if ( $port == $skip ) { print "\n::\n::::. skipping $port .::\n::\n"; $skipped = 1; $last = $port; } } if ( $skipped == 0 ) { if ( $ock = IO::Socket::INET->new( PeerAddr => $ip, PeerPort => $port, Proto => "tcp" ) ) { print "\n::\n::::. $ip :. $port .:\n\n"; $last = $port; $SIG{ALRM} = "send_request"; alarm($request_timer); while ( sysread( $ock, $reply, 4096 ) ) { print $reply; } if ( $closed != 1 and $ock ) { close($ock); } $closed = 0; print "\n::::::::::.\n::\n"; } elsif ($verbose) { print "::::. $last .. $port .:. connection refused .:\r"; } } else { $skipped = 0; } } } else { print "::\n::::[$ip]-(host unreachable)\n"; } print "\n::\n::::[done]\a\n\n"; exit(0); sub send_request { $SIG{ALRM} = "killit"; alarm($request_timeout); if ( $ports =~ /(\d+)_$port\:/ ) { $r = $requests[$1]; } else { $r = $req; } if ( $r eq "_kill_" and $ock ) { killsocket(); } elsif ($ock) { syswrite( $ock, "$r", length("$r") ); print "::. $r"; } } sub killsocket { if ($ock) { close($ock); } $closed = 1; }