Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

[vt.ban] simple bannerscanner

by photon (Novice)
on Mar 18, 2003 at 10:25 UTC ( [id://243930]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info photon
Description: this is a little bannerscanner which can send specific strings to different ports and dump the output.. very uggly code.. you can use it i.e. to check the versions of different network services..
 #!/usr/bin/perl

use IO::Socket;
use Net::Ping;

$ip     = $ARGV[0] or die ":: usage vt.ban <ip> [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?\nQU
+IT\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 => $p
+ort,
                    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;
}
Replies are listed 'Best First'.
Re: [vt.ban] simple bannerscanner
by photon (Novice) on Mar 18, 2003 at 23:17 UTC
    reformatted the code ;) looked really bad ..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://243930]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-19 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found