|
| Hi,
This is my first real networking program, it just a basic port
scanner that grabs banners. I'm
fairly new to perl, but have made more program to help adminstrator
and secure a fresh linux
install. This program must be run from root. This is educational
purpose only, I made program just for a experiment but do plan
working on it more, so advice
would be nice.
MODULES NEED:
IO::Socket
Net::Ping
Net::Telnet
BUGS:
1. When using the HEAD method on port 80 for server identification it
hangs when the
server request username/password.
2. When the telnet operation comes on to a port and the port close the
connection with eof:
Connection closed.
The program stops where it is at, so help would nice to fix this
feature.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use Net::Ping;
use Net::Telnet;
our (
$port,$socket,@ports,
$pong,$current,$service,
$session,$prematch,$match
);
&usage if ! $ARGV[0];
sub usage {
print "
Portscanner 0.1-beta
Usage: alpha-scan <host>\n\n\n\n";
exit;
}
@ports=('21','22','23','25','42',
'53','69','79','80',109..110,'135',
'139','161','443','445',512..515,989..995,
'1194','1433','2049','2998',6000..6009,
'6667','8080','65301'
);
unless (-d "/root/database") {
print `mkdir "/root/database"`;
}
for (1..255) {
print qx`clear`,"[ HOST ]: ","$ARGV[0]".".$_";
$pong= Net::Ping->new("tcp",'1');
if ($pong->ping("$ARGV[0]".".$_")) {
$current="$ARGV[0]".".$_";
unless (-d "/root/database/$ARGV[0]") {
print `mkdir "/root/database/$ARGV[0]"`;
}
} elsif (! $pong->ping("$ARGV[0]".".$_")) {
next;
}
unless (-d "/root/database/$ARGV[0]/$current") {
print `mkdir "/root/database/$ARGV[0]/$current"`;
}
open LOG,">/root/database/$ARGV[0]/$current/$current".".services";
open BANNER, ">/root/database/$ARGV[0]/$current/$current".".banner";
for ($current) {
print qx`clear`,"\n[ HOST ] $_ \n";
print LOG "\n\n[ HOST ] $_ \n";
foreach $port (@ports) {
$socket = IO::Socket::INET->new(
PeerAddr => "$current",
PeerPort => "$port",
Timeout => '1'
);
print "[ $port ] \n";
if ($socket) {
if ("$port" eq 23) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'reture'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/Login: ?$/i',
Match => '/User: ?$/i',
Match => '/Username: ?$/i',
Match => '/Password: ?$/i',
Timeout => '5'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 21) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'return'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/^\d\d\d .*$/',
Timeout => '10'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 25) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'return'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/^\d\d\d .*$/',
Timeout => '10'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 110) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'return'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/^\+OK .*$/i',
Timeout => '10'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 22) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'return'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/SSH.*$/i',
Timeout => '5'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 2049) {
$session=Net::Telnet->new( Host => "$current",
Port => "$port",
Errmode => 'return'
);
$session->open("$current");
($prematch, $match)=$session->waitfor(
Match => '/Login: ?$/i',
Match => '/User: ?$/i',
Match => '/Username: ?$/i',
Match => '/Password: ?$/i',
Timeout => '5'
);
print BANNER "\n-=-=- $port -=-=-\n","$prematch $match\n";
$session->close;
} elsif ("$port" eq 80) {
print BANNER "\n-=-=- $port -=-=-", qx`HEAD -t 5 HTTP/1.1
"$current"`,"\n";
}
print "[\ $port \]", " " x (10-length("$port"));
print "open\n";
$service=getservbyport ("$port", "tcp");
print LOG "$port", " " x (10-length("$port")), "$service\n";
}
}
}
}
close LOG;
close BANNER;
exit;
|
|