Connecting Tech Pros Worldwide Forums | Help | Site Map

SMTP honeypot

Newbie
 
Join Date: Jan 2007
Posts: 12
#1: Feb 22 '07
Ok, I wrote a Honeypot in perl. It listens on port 25 and acts as a crude SMTP server.
It responds to the most basic commands(helo, mail from, rcpt to, data) needed for sending mail.
It has no way of closing the socket from the client side, so it acts also as a tarpit by not allowing automatic spam mailers to disconnect from it.
It does not actually send any mail, but simulates the situation.

Problems I'm having:

1.
Expand|Select|Wrap|Line Numbers
  1. #elsif ($message =~ '.') {print $client "250 Ok: queued as 6AB5150038\n";}
The last step in sending mail, is to put a "." on an empty line and press enter. But I cannot match ($message =~ '.'). What are the alternatives?
2. When I run the script and I connect to the port, it displays
Expand|Select|Wrap|Line Numbers
  1. print "Connection received\n";
for me and
Expand|Select|Wrap|Line Numbers
  1. print $client "220 mail.kuratkull.pri.ee ESMTP\n";
for the client. After i disconnect the client and reconnect, it doesn't display neither of them.
How can I fix this?
3. How could I log the IP of the client?

Thank you for your replies :)


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2.  
  3. use IO::Socket;
  4.  
  5. my $client;
  6. my $socket;
  7. my $message;
  8.  
  9. $socket = IO::Socket::INET->new(
  10.         "Proto" => "tcp",
  11.     "Reuse" => "1",        
  12.     "LocalPort" => "25",
  13.         "Listen" => 1) or die "ERROR: $!\n";
  14.  
  15. $client = $socket->accept();
  16.  
  17. print "Connection received\n";
  18.  
  19. print $client "220 mail.kuratkull.pri.ee ESMTP\n";
  20.  
  21. while ($message = <$client>) {
  22.  
  23. # the commands and the simulated anwsers to them. This is all static data.
  24. if ($message =~ "helo") {print $client "250 mail.kuratkull.pri.ee, How can I help you?\n";} 
  25. elsif ($message =~ "mail from:") {print $client "250 ok\n";}
  26. elsif ($message =~ "rcpt to:") {print $client "250 ok\n";}
  27. elsif ($message =~ "data") {print $client "354 go ahead and end data with .\n";}
  28. elsif ($message =~ "HELO") {print $client "250 mail.kuratkull.pri.ee, How can I help you?\n";} 
  29. elsif ($message =~ "MAIL FROM:") {print $client "250 ok\n";}
  30. elsif ($message =~ "RCPT TO:") {print $client "250 ok\n";}
  31. elsif ($message =~ "DATA") {print $client "354 go ahead and end data with .\n";}
  32. #elsif ($message =~ '.') {print $client "250 Ok: queued as 6AB5150038\n";}
  33. #else {print $client "500 Command not recognized: $message.";}
  34.  
  35. print "$message";
  36.  
  37. $out = "/home/httpd/html/smtpserv.txt";
  38.  
  39. open OUT, ">>$out" or die "Cannot open $out for append :$!";
  40. print OUT "\n", $message, scalar(localtime);
  41. close OUT;
  42.  
  43. print "Disconnected...\n";
  44. }
  45.  
  46. #this keeps the script running after the client disconnects
  47. my $new_sock = $socket->accept();
  48. while(<$new_sock>) {
  49.    print $_;
  50. }
  51. close($sock);

Newbie
 
Join Date: Jan 2007
Posts: 12
#2: Feb 22 '07

re: SMTP honeypot


It is also unreachable from outside my local network. Maybe this has to do something with "bind". I am looking for information, but there isn't very much of it.
If you could give me any help on this, it would be very appreciated too :)
Reply


Similar Perl bytes