/M4/mail8_zombie

https://github.com/gitpan/Sendmail_M · Perl · 175 lines · 124 code · 38 blank · 13 comment · 5 complexity · 0765fe0302769e6ba6edb93caa2b4208 MD5 · raw file

  1. #!/usr/bin/perl -w
  2. # Copyright (c) 2007 celmorlauren limited. All rights reserved.
  3. # This program is free software; you can redistribute it and/or modify it under
  4. # the same terms as Perl itself.
  5. =head1 NAME
  6. Sendmail::M4::mail8_zombie - Stop fake MX and most spammers, sendmail M4 hack file
  7. =head1 STATUS
  8. Version 0.2 (early Beta)
  9. Very much a work in progress.
  10. =head1 SYNOPSIS
  11. Perl Helper for B<sendmail>
  12. =head1 AUTHOR
  13. Ian McNulty, celmorlauren limited (registered in England & Wales 5418604).
  14. email E<lt>development@celmorlauren.comE<gt>
  15. =head1 HISTORY
  16. B<Versions>
  17. =over 5
  18. =item 0.1
  19. Nov 2006 1st version, Perl plug-in program for B<sendmail> anti spam hack file, original hack did a large amount of checking. But not as much or even in the same order as the new B<Sendmail::M4::Mail8> hack generator. The original hack continued in use at B<celmorlauren>, however it will be replaced by the CPAN version on completion and initial testing, it is thought that the improved format and action of the B<Sendmail::M4::Mail8> hack should suffice, the future of the other helpers will be decided at a later date.
  20. B<Amendments> to release version>
  21. =over 3
  22. =item 22
  23. Sept 2007 Ported from old format to format and use required by B<Sendmail::M4::Mail8>
  24. =back
  25. =item 0.2
  26. 22 Sept 2007 CPAN Release
  27. =back
  28. =head1 USES NOTHING
  29. =head1 EXPORTS NOTHING
  30. =cut
  31. # mail8 sendmail anti spammer aid
  32. sub whoops
  33. {
  34. my $whoops = join ",", @_;
  35. print "ERR.WHOOPS PROGRAM ERROR: $whoops\n";
  36. exit 0;
  37. }
  38. #Globals
  39. my ( $helo, $ip ) = @ARGV or whoops "called without required arguments, HELO IP";
  40. if ( $helo =~ s/ +/\t/g )
  41. {
  42. ( $helo, $ip ) = split "\t", $helo;
  43. }
  44. # sendmail macros should have already checked ip against helo name, however it can not cope with run together
  45. # names, just in case these checks as well as run together checks
  46. my $IP = $ip; # split won't work with '.'!
  47. $IP =~ s/\./\t/g;
  48. my ( $ip1, $ip2, $ip3, $ip4 ) = split "\t", $IP or whoops "ip <$ip> is not an IP?";
  49. # some ISP's encode their users as HEX strings!
  50. my $IP1 = sprintf "%lx", $ip1;
  51. my $IP2 = sprintf "%lx", $ip2;
  52. my $IP3 = sprintf "%lx", $ip3;
  53. my $IP4 = sprintf "%lx", $ip4;
  54. # now match strings
  55. my $wild = '\D*(\.|-|\D)*0*';
  56. my $WILD = '([g-zG-Z])*(\.|-)*';
  57. my %grep = (
  58. p1_4 => "$ip1"."$wild"."$ip2"."$wild"."$ip3"."$wild"."$ip4",
  59. p4_1_3 => "$ip4"."$wild"."$ip1"."$wild"."$ip2"."$wild"."$ip3",
  60. p1_3 => "$ip1"."$wild"."$ip2"."$wild"."$ip3",
  61. p1_2 => "$ip1"."$wild"."$ip2",
  62. p2_4 => "$ip2"."$wild"."$ip3"."$wild"."$ip4",
  63. p3_4 => "$ip3"."$wild"."$ip4",
  64. p4_1 => "$ip4"."$wild"."$ip3"."$wild"."$ip2"."$wild"."$ip1",
  65. p4_2 => "$ip4"."$wild"."$ip3"."$wild"."$ip2",
  66. p4_3 => "$ip4"."$wild"."$ip3",
  67. p3_1 => "$ip3"."$wild"."$ip2"."$wild"."$ip1",
  68. p2_1 => "$ip2"."$wild"."$ip1",
  69. __BAR__ => "above numeric, below HEX",
  70. P1_4 => "$IP1"."$WILD"."$IP2"."$WILD"."$IP3"."$WILD"."$IP4",
  71. P4_1_3 => "$IP4"."$WILD"."$IP1"."$WILD"."$IP2"."$WILD"."$IP3",
  72. P1_3 => "$IP1"."$WILD"."$IP2"."$WILD"."$IP3",
  73. P1_2 => "$IP1"."$WILD"."$IP2",
  74. P2_4 => "$IP2"."$WILD"."$IP3"."$WILD"."$IP4",
  75. P3_4 => "$IP3"."$WILD"."$IP4",
  76. P4_1 => "$IP4"."$WILD"."$IP3"."$WILD"."$IP2"."$WILD"."$IP1",
  77. P4_2 => "$IP4"."$WILD"."$IP3"."$WILD"."$IP2",
  78. P4_3 => "$IP4"."$WILD"."$IP3",
  79. P3_1 => "$IP3"."$WILD"."$IP2"."$WILD"."$IP1",
  80. P2_1 => "$IP2"."$WILD"."$IP1",
  81. );
  82. my @numeric_match = qw(
  83. p1_4
  84. p4_1_3
  85. p1_3
  86. p1_2
  87. p2_4
  88. p3_4
  89. p4_1
  90. p4_2
  91. p4_3
  92. p3_1
  93. p2_1
  94. );
  95. my @hex_match = qw(
  96. P1_4
  97. P4_1_3
  98. P1_3
  99. P1_2
  100. P2_4
  101. P3_4
  102. P4_1
  103. P4_2
  104. P4_3
  105. P3_1
  106. P2_1
  107. );
  108. my @grep = ( @numeric_match, @hex_match );
  109. # NOTE however sendmail macros do a very good job of matching .|- delimited IP HELO's
  110. # Better than this can do easily
  111. foreach ( @grep )
  112. {
  113. my $match= $grep{$_};
  114. my $grep = "\$helo =~ m/$match/i";
  115. my $ok = eval $grep;
  116. defined $ok or whoops "grep failed with:",$@;
  117. if ( scalar $ok )
  118. {
  119. print "ERR.IP <HOST $helo with IP $ip> matched mail8_zombie: $_\n";
  120. exit 0;
  121. }
  122. }
  123. # one last test, might not match IP but have a lots of numerics
  124. my $HELO = $helo;
  125. $HELO =~ s/(\D|\.|-)+//g;
  126. my $length = length $HELO;
  127. if ( $length >= 6 )
  128. {
  129. print "ERR.IP <HOST $helo> looks like a numeric user address, name resolves to $length digit <$HELO>\n";
  130. exit 0;
  131. }
  132. elsif ( $length >= 4 )
  133. {
  134. print "ERR.IP <HOST $helo> looks numeric <like a spammer>, name resolves to $length digit <$HELO>, apply for OK listing using NON spammer address\n";
  135. exit 0;
  136. }
  137. 1;