Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 11.65 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # addrcheck - mail address checker
  4. # by tchrist@perl.com
  5. # Copyright 1997 Tom Christiansen
  6. # version 1.001 Fri Feb 14 15:20:02 MST 1997
  7.  
  8. ####################################
  9. # this program takes an email address as its argument
  10. # and decides whether you're being spoofed or not.
  11. # it exists 0 if it likes the address, and 1 if it doesn't.
  12. #
  13. # can be tested interactively.  if not interactive, it will
  14. # use syslog.
  15. #
  16. # should be rewritten instead of just growing via hacks.
  17. ####################################
  18.  
  19. $LOGGER   = '/usr/bin/logger';  # or /usr/ucb?
  20. $NSLOOKUP = '/usr/bin/nslookup';  # or /usr/ucb?
  21.  
  22. $DEBUG = -t STDIN && -t STDOUT;
  23. $address = shift || die "usage: $0 address\n";
  24.  
  25. for ($address) {
  26.     s/^-+//;
  27.     tr/A-Z/a-z/;
  28. }
  29.  
  30. ($user, $host) = split /\@/, $address;
  31.  
  32. # we check in this order because of speed;
  33. # this way it will fail more quickly.
  34.  
  35. check_passwd($user);    # picky
  36.  
  37. if ($address =~ /\@./) {
  38.     check_host($host);
  39.     ck822($address);    # inscrutable
  40.     dns_check($host);   # slow
  41. }
  42.  
  43. exit 0;
  44.  
  45. ####################################
  46.  
  47. sub bad {
  48.     # GLOBAL $hispass and $what
  49.     if ($DEBUG) {
  50.     print "$what `$hispass' is bad: @_\n";
  51.     } else {
  52.     system $LOGGER,
  53.             "-p", "daemon.notice",
  54.             "-t", "ftpucheck",
  55.         "BOGUS \U$what\E $hispass (@_)";
  56.     }
  57.     exit 1;
  58. }
  59.  
  60. ####################################
  61.  
  62. #############
  63.  
  64. sub check_passwd {  
  65.     local $what = 'user';
  66.     local $hispass = shift;
  67.  
  68.     for (@rude) {
  69.     bad("rude") if index($hispass, lc $_) != -1;
  70.     }
  71.  
  72.     for (@anywhere) {
  73.     bad("inside") if index($hispass, lc $_) != -1;
  74.     }
  75.  
  76.     for (@full) {
  77.     bad("full") if $hispass eq lc $_;
  78.     }
  79.  
  80.     for (@start) {
  81.     bad("start") if index($hispass, lc $_) == 0;
  82.     }
  83.  
  84.     # single char
  85.     bad("single") if length($hispass) == 1;
  86.  
  87.     study $hispass;
  88.  
  89.     bad("dup letters") if $hispass =~ /(\w)\1{3,}/;
  90.  
  91.     bad("white") if $hispass =~ /\s/;
  92.  
  93.     bad("junk") if $hispass =~ /[;,\/#^*]/;
  94.  
  95.     $V = 'aeiouy';
  96.     if ($hispass =~ /netscape/ || $hispass =~ /^m[$V]*[sz]+[$V]*l+[$V]*\W*$/) {
  97.     bad("mozilla");
  98.     }
  99.  
  100.     if ($hispass =~ /xyz+y/) {
  101.     bad("xyzzy");
  102.     }
  103.  
  104.     # all same letter
  105.     bad("dup letters") if $hispass =~ /^(.)\1+$/;
  106.  
  107.     # want letters
  108.     bad("ugly") unless $hispass =~ /[a-z]/;
  109.  
  110.     bad("backspace") if $hispass =~ /[\010\177]/;
  111.  
  112.     $letters = "qwertyuiopasdfghjklzxcvbnmmnbvcxzlkjhgfrdsapoiuytrewq";
  113.  
  114.     # consecutive
  115.     bad("consecutive") if
  116.         length($hispass) > 2 &&
  117.         ( index($letters, $hispass) != -1
  118.             ||
  119.           ($hispass =~ /^(\w+)\1$/ && length($1) > 2
  120.             && index($letters, $1) != -1)
  121.         );
  122.  
  123.     print "$what: $hispass is good\n" if $DEBUG;
  124.  
  125. }
  126.  
  127.  
  128. #############
  129.  
  130. sub check_host {
  131.     local $what = 'host';
  132.     local $hispass = shift;
  133.  
  134.     bad("dotless") unless index($hispass, '.') >= 0;
  135.  
  136.     for (@rude) {
  137.     bad("rude") if index($hispass, lc $_) != -1;
  138.     }
  139.  
  140.     for (@full) {
  141.     bad("full") if $hispass eq lc $_;
  142.     }
  143.  
  144.     # single char
  145.     bad("single") if length($hispass) == 1;
  146.  
  147.     study $hispass;
  148.  
  149.     bad("white") if $hispass =~ /\s/;
  150.  
  151.     bad("junk") if $hispass =~ /[;,\/#^*]/;
  152.  
  153.     # want letters, darnit;  this will cause 127.1 to fail though
  154.     bad("ugly") unless $hispass =~ /[a-z]/;
  155.  
  156.     bad("backspace") if $hispass =~ /[\010\177]/;
  157.  
  158.     $letters = "qwertyuiopasdfghjklzxcvbnmmnbvcxzlkjhgfrdsapoiuytrewq";
  159.  
  160.     # consecutive
  161.     bad("consecutive") if
  162.         length($hispass) > 2 &&
  163.         ( index($letters, $hispass) != -1
  164.             ||
  165.           ($hispass =~ /^(\w+)\1$/ && length($1) > 2
  166.             && index($letters, $1) != -1)
  167.         );
  168.  
  169.     print "$what: $hispass is good\n" if $DEBUG;
  170.  
  171. }
  172.  
  173. sub dns_check {
  174.     # first try an MX record, then an A rec (for badly configged hosts)
  175.  
  176.     my $host = shift;
  177.     local $/ = undef;
  178.     local $what = "DNS record";
  179.     local $hispass = $host;
  180.  
  181.  
  182.     # the following is comment out for security reasons:
  183.     #   if ( `nslookup -query=mx $host` =~ /mail exchanger/
  184.     # otherwise there could be naughty bits in $host
  185.     # we'll bypass system() and get right at execvp()
  186.  
  187.     if (open(NS, "-|")) {
  188.     if (<NS> =~ /mail exchanger/) {
  189.         print "$what MX: $hispass is good\n" if $DEBUG;
  190.         close NS;
  191.         return;
  192.     }
  193.     } else {
  194.     open(SE, ">&STDERR");
  195.     open(STDERR, ">/dev/null");
  196.     exec $NSLOOKUP, '-query=mx', $host;
  197.     open(STDERR, ">&SE");
  198.     die "can't exec nslookup: $!";
  199.     }
  200.  
  201.     if (open(NS, "-|")) {
  202.     $_ = <NS>;
  203.     if (/answer:.*Address/s) {
  204.         print "$what A: $hispass is good\n" if $DEBUG;
  205.         close NS;
  206.         return;
  207.     }
  208.     if (/Name:.*$host.*Address:/si) {
  209.         print "$what A: $hispass is good\n" if $DEBUG;
  210.         close NS;
  211.         return;
  212.     }
  213.     } else {
  214.     open(SE, ">&STDERR");
  215.     open(STDERR, ">/dev/null");
  216.     exec $NSLOOKUP, '-query=a', $host;
  217.     open(STDERR, ">&SE");
  218.     die "can't exec nslookup: $!";
  219.     }
  220.  
  221.     bad("No DNS");
  222. }
  223.  
  224.  
  225. sub ck822 {
  226.  
  227.     # ck822 -- check whether address is valid rfc 822 address
  228.     # tchrist@perl.com
  229.     #
  230.     # pattern developed in program by jfriedl;
  231.     # see "Mastering Regular Expressions" from ORA for details
  232.  
  233.     # this will error on something like "ftp.perl.com." because
  234.     # even though dns wants it, rfc822 hates it.  shucks.
  235.  
  236.     local $what = 'address';
  237.  
  238.     local $hispass = shift;
  239.     local $_;
  240.  
  241.     $is_a_valid_rfc_822_addr = '';
  242.  
  243.     while (<DATA>) {
  244.     chomp;
  245.     $is_a_valid_rfc_822_addr .= $_;
  246.     }
  247.  
  248.  
  249.     bad("rfc822 failure") unless $hispass =~ /^${is_a_valid_rfc_822_addr}$/o;
  250.     print "$what: $hispass is good\n" if $DEBUG;
  251. }
  252.  
  253. ##############################
  254. # initializations
  255. ##############################
  256.  
  257. BEGIN {
  258.  
  259.     @full = qw{
  260.  
  261.     admin
  262.     anon
  263.     anonymous
  264.     bar
  265.     big-liar
  266.     bin
  267.     bizarre
  268.     bla
  269.     blah
  270.     bogus
  271.     cache
  272.     collect
  273.     compuserve
  274.     cool
  275.     crud
  276.     DeleGateMaster
  277.     devnull
  278.     dialup
  279.     dork
  280.     dummy
  281.     employee
  282.     first1
  283.     foo
  284.     friendly
  285.     ftpsearch-collect
  286.     fu
  287.     god
  288.     guest
  289.     gunk
  290.     gw
  291.     harvest
  292.     here
  293.     hi
  294.     ident
  295.     ident
  296.     ie30user
  297.     info
  298.     internet
  299.     junk
  300.     liar
  301.     login
  302.     lycos
  303.     maxima
  304.     me
  305.     mirror
  306.     mosaic
  307.     nobody
  308.     none
  309.     none-known
  310.     nouser
  311.     ntcon
  312.     ok
  313.     outbound
  314.     postmaster
  315.     president
  316.     public
  317.     Put_Your_Email_Address
  318.     report_abuse
  319.     root
  320.     satan
  321.     socks
  322.     spanky
  323.     src
  324.     sticky
  325.     system
  326.     there
  327.     Unknown_Netscape_User
  328.     Unregistered
  329.     unverified
  330.     user
  331.     UserName
  332.     vice-president
  333.     vividnet
  334.     whoever
  335.     wow
  336.     xyz
  337.     xyz
  338.  
  339.     };
  340.  
  341.     @start = qw{
  342.  
  343.     aaa
  344.     abc
  345.     account
  346.     anon
  347.     anon
  348.     asquid
  349.     daemon
  350.     delegate
  351.     ftp
  352.     gopher
  353.     gotch
  354.     oracle
  355.     otthttp
  356.     pass
  357.     satan
  358.     squid
  359.     student
  360.     test
  361.     web
  362.     xx
  363.  
  364.     };
  365.  
  366.     @anywhere = qw{
  367.  
  368.     adresse
  369.     asdf
  370.     asfd
  371.     cache
  372.     firewall
  373.     -gw
  374.     http
  375.     mail
  376.     mirror
  377.     mother
  378.     name
  379.     nobody
  380.     proxy
  381.     sadf
  382.     system
  383.     user
  384.     www
  385.  
  386.     };
  387.  
  388.     @rude = qw{
  389.  
  390.     asshole
  391.     crap
  392.     cunt
  393.     damn
  394.     fuck
  395.     piss
  396.     shit
  397.     suck
  398.     tits
  399.     upyour
  400.  
  401.     };
  402.  
  403. }
  404.  
  405. # don't touch this stuff down here or you'll break the rfc822 matcher.
  406. __END__
  407. (?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n
  408. \015()]|\\[^\x80-\xff])*\))*\))*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\
  409. xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"
  410. ]|\\[^\x80-\xff])*")(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xf
  411. f]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?:[
  412. ^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\
  413. xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;
  414. :".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*"))
  415. *(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\
  416. n\015()]|\\[^\x80-\xff])*\))*\))*@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\
  417. \[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\04
  418. 0)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-
  419. \xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?
  420. :[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80
  421. -\xff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\(
  422. (?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]
  423. \000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\
  424. \x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\]))*|(?:[^(\040)<>@,;:".\\\[\]\000-\0
  425. 37\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:[^\\\x80-\xf
  426. f\n\015"]|\\[^\x80-\xff])*")(?:[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\03
  427. 7]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\
  428. \[^\x80-\xff])*\))*\)|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*")*<(?:[\04
  429. 0\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]
  430. |\\[^\x80-\xff])*\))*\))*(?:@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x
  431. 80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@
  432. ,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]
  433. )|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^\\
  434. \x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff
  435. ])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^
  436. \\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-
  437. \037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-
  438. \xff\n\015\[\]]|\\[^\x80-\xff])*\]))*(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\01
  439. 5()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*,(?
  440. :[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\0
  441. 15()]|\\[^\x80-\xff])*\))*\))*@(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^
  442. \x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<
  443. >@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xf
  444. f])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^
  445. \\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\x
  446. ff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:
  447. [^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\00
  448. 0-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x8
  449. 0-\xff\n\015\[\]]|\\[^\x80-\xff])*\]))*)*:(?:[\040\t]|\((?:[^\\\x80-\xff\n\
  450. 015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*)
  451. ?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000
  452. -\037\x80-\xff])|"(?:[^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*")(?:(?:[\040\t]
  453. |\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[
  454. ^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xf
  455. f]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\
  456. \\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"(?:
  457. [^\\\x80-\xff\n\015"]|\\[^\x80-\xff])*"))*(?:[\040\t]|\((?:[^\\\x80-\xff\n\
  458. 015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*@
  459. (?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n
  460. \015()]|\\[^\x80-\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff
  461. ]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\
  462. ]]|\\[^\x80-\xff])*\])(?:(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\
  463. xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*\.(?:[\040\t]|\((?
  464. :[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80
  465. -\xff])*\))*\))*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@
  466. ,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff
  467. ])*\]))*(?:[\040\t]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff]|\((?:[^\\\x8
  468. 0-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*>)(?:[\040\t]|\((?:[^\\\x80-\xff\n\
  469. 015()]|\\[^\x80-\xff]|\((?:[^\\\x80-\xff\n\015()]|\\[^\x80-\xff])*\))*\))*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement