#!/usr/bin/perl
#
# dms - DAEMONSCAN - by initzero - dec'99
# initzero@thekeyboard.com | http://initzero.tripod.com
#
# nothing special, scans thru ip-#s & logs the daemon.
# by the way, sin scans are traceable.
# if somebody has an idea how to make the whole
# thing faster, contact me.
#
# usage:
#	dms <Scan Type, Input> <Port>
#
#	dms -h 127.0.0.1 21
#	 -> scan one host on port 21
#
#	dms -l host.list 110
#	 -> get hosts out of a file, use port 110
#
#	dms -s 198.168.10. 23
# 	 -> scan class c (198.168.10.*), telnet port
############################################################


#### I N I T
use Socket; 

print"\ndms - by initzero - initzero.tripod.com\n";
print"----------------------------------------\n";


if (@ARGV ne 3)
{
print"usage: dms <Scan Type, Input> <Port>

dms -h 127.0.0.1 21
 ->scan one host on port 21

dms -l host.list 110
 ->get hosts out of a file, use port 110

dms -s 198.168.10. 23
 -> scan class c (198.168.10.*), telnet port

";
  exit();
}

$port = $ARGV[2];
$host = $ARGV[1];
$victim = $host;
$scan_mode = $ARGV[0];
$count = 0;



#### M A I N
## -h
if ($scan_mode eq "-h")
{
print"scanning $host:$port\n";
$victim = $host;
send_ftp();

exit();
}

## -l
if ($scan_mode eq "-l")
{
get_file();
print"hosts in list: $totaly\n";

for ($y = 1 ; $y <= $totaly ; $y++)
{
$victim = @hosts[$y];
send_ftp();
}

exit();
}

## -s
if ($scan_mode eq "-s")
{
print"scanning subnet $host*, using port $port\n";

for ($y = 1 ; $y <= 255 ; $y++)
{
$victim = "$host$y";
send_ftp();
}

exit();
}

## u suck
print"unknown scan mode, take a course in typing, stupid!\n";
exit();



#### S U B S

sub send_ftp
{
$hoestlich = host_up();
if ($hoestlich ne 0)
{
$NETFD = &makeconn($victim, $port); 
sysread $NETFD, $message,100 ;
close $NETFD;

if ($message == "")
{
print"port is CLOSED\n";
return 0;
}

print"$message";
return 0;
}

print"$victim is DOWN\n";
return 0;
}

sub host_up
{
$ping_test = qx { ping -c 1 -q $victim };
if (index ($ping_test,"1 packets received") > 0)
{
print"$victim:$port ";
return 1;
}
return 0;
}


sub makeconn
{ 
my ($host, $portname, $server, $pt,$pts, $proto, $servaddr); 
$host = $_[0]; 
$pt = $_[1];  
$server = gethostbyname($host) or die "gethostbyname: cannot locate host: $!";
$pts = getservbyport($pt, 'tcp'); 
$proto = getprotobyname('tcp') or die " : $!"; 
$servaddr = sockaddr_in($pt, $server); 
socket(CONNFD, PF_INET, SOCK_STREAM, $proto); 
connect(CONNFD, $servaddr) ;
return CONNFD; 
}


sub get_file
{
open (LISTE,"$host");
while ($ente = <LISTE>) {
chop $ente; #HACK DIE ENTE, thats german
$count++;
@hosts[$count] = $ente;
}
close(LISTE);
$totaly = $count;
$count = 0;
return 0;
}

sub quiznos
{
print"quizno's subs are the best!\n";
print"don't copy my subs\n";
print"i love perl\n";
exit();
}

