#!/usr/bin/perl
#
##########################################
#                                        #
# No warranty whatsoever is given about  #
# this software, use at your own risk.   #
# It listens on port 25  and saves       #
# whatever the client types in.          #
#                                        #
##########################################
use Socket;
$SIG{CHLD} = sub {wait ()};

if ($uid!=0)
{
  print "I need to run as root.\n";
  exit;
}
###########################################
#  Change the port to whatever you want   #
#  to impersonate.  Do port 23 and people #
# will suddenly start typing their user   #
# names and passwords.  I dont know why,  #
# they just do.                           #

$port=25;

#                                         #
###########################################

$proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto)  || die "error socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))|| die "error setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY))        || die "error bind: $!";
listen(Server,SOMAXCONN)                            || die "error listen: $!";
print "basic listener waiting for connection on port $port\n";
while (1) {
while ($paddr = accept(Client,Server))
{
   my($port,$iaddr) = sockaddr_in($paddr);
   @ip=unpack('C4',$iaddr);
   $clientip=$ip[0].".".$ip[1].".".$ip[2].".".$ip[3];
   print "S: Forking handler for $clientip\n";
   $pid = fork;
   if ($pid == 0)
   {
      select(Client);
      $|=1;
      select(STDOUT);
      print Client "220 My private mail service SMTP server ready.   \r\n";
      while ($line=<Client>) {
      ####################################
      #####                          #####
      #####    here you put your     #####
      #####    custom  handler       #####
      #####                          #####
      ####################################
      print Client "250 Ohhh send me more crap packets please.  mmmmm  \r\n";
      }
      exit(0);
   }
}
    close(Client);
}


