#!/usr/bin/env pike // Open Relay Checker // (c)iMil / 2001 // updates by kiwi // This software is copyrighted under the GNU GPL // See ftp://ftp.gcu-squad.org/pub/pike/COPYING import Getopt; // here are the tests, this may (should :) be cleaned // If you want to add some tests, use the following array // where : // from : complete Mail From: address // to : complete Rcpt To: address // fromuser : from's email login part // touser : to's email login part // ip : tested host ip // hostdomain : tested host's domain part // AT : @ #define TESTLIST array (array(string)) trick= ({ \ ({ from,to }), \ ({ fromuser,to }), \ ({ "",to }), \ ({ fromuser+AT+hostdomain,to }), \ ({ "nobody"+AT+hostdomain,to }), \ ({ "postmaster"+AT+hostdomain,to }), \ ({ "hostmaster"+AT+hostdomain,to }), \ ({ "nobody"+AT+"localhost",to }), \ ({ "nobody"+AT+"[127.0.0.1]",to }), \ ({ "nobody"+AT+gethostname(),to }), \ ({ fromuser+AT+"["+ip+"]",to }), \ ({ fromuser+AT+hostdomain,replace(to,AT,"%")+AT+hostdomain }), \ ({ fromuser+AT+hostdomain,replace(to,AT,"%")+AT+"["+ip+"]" }), \ ({ fromuser+AT+hostdomain,"\""+to+"\"" }), \ ({ fromuser+AT+hostdomain,"\""+replace(to,AT,"%")+"\"" }), \ ({ fromuser+AT+hostdomain,to+AT+hostdomain }), \ ({ fromuser+AT+hostdomain,"\""+to+AT+hostdomain+"\"@["+ip+"]" }), \ ({ fromuser+AT+hostdomain,to+AT+hostdomain+"@["+ip+"]" }), \ ({ fromuser+AT+hostdomain,"\""+to+"\""+AT+hostdomain }), \ ({ fromuser+AT+hostdomain,to+AT+"["+ip+"]" }), \ ({ fromuser+AT+hostdomain,AT+hostdomain+":"+to }), \ ({ fromuser+AT+hostdomain,AT+"["+ip+"]"+":"+to }), \ ({ fromuser+AT+hostdomain,hostdomain+"!"+touser }), \ ({ fromuser+AT+hostdomain,hostdomain+"!"+touser+AT+hostdomain }), \ ({ fromuser+AT+hostdomain,hostdomain+AT+touser+AT+hostdomain+"\"" }), \ ({ fromuser+AT+hostdomain,hostdomain+"!"+touser+AT+"["+ip+"]" }) \ }); #define FROMUSER "spamcheck" #define TOUSER "relaycheck" #define DOMAIN "rbl.v6net.org" #define AT "@" #define HELO "HELO" #define MAILFROM "MAIL FROM:" #define RCPTTO "RCPT TO:" #define QUIT "QUIT\r\n" #define NULL 0 int testnb=0; int isrelay=0; array (array(string)) tricklist(string host, string from, string to) { string fromuser=Regexp("(.*)(@.*)")->split(from)[0]; string touser=Regexp("(.*)(@.*)")->split(to)[0]; string hostdomain; array res=gethostbyname(host); string ip=res[1][0]; //res=gethostbyaddr(ip); // get real host adress array|int res2=gethostbyaddr(ip); // get real host adress if (arrayp(res2)) { host=res2[0]; hostdomain=Regexp("([0-9aA-zZ]*\.)(.*\..*)")->split(host)[1]; } else hostdomain=host; TESTLIST return(trick); } void usage(string pgname) { werror(pgname+" [-f from] [-t to] [-h]\n"); exit(1); } string query(object sock,string req) { string reply=0; if (req) sock->write(req); sock->set_nonblocking(); while(!reply) reply=sock->read(); sock->set_blocking(); write("<< "+reply); return(reply); } string telnet25(string host, string from, string to) { object sock=Stdio.File(); string reply=NULL; string log=""; testnb++; write("\nTest n."+(string)testnb+"\n\n"); if (sock->connect(host,25)) { log=log+query(sock,0); write(">> "+HELO+" "+gethostname()+"\r\n"); log=log+query(sock,HELO+" "+gethostname()+"\r\n"); write(">> "+MAILFROM+" <"+from+">\r\n"); log=log+query(sock,MAILFROM+" <"+from+">\r\n"); write(">> "+RCPTTO+" <"+to+">\r\n"); log=log+query(sock,RCPTTO+" <"+to+">\r\n"); write(">> "+QUIT); log=log+query(sock,QUIT); sock->close(); if (!Regexp("\n5[0-9][0-9]")->match(log)) isrelay=1; } else reply=host+": couldn't contact host.\n"; return reply; } void test(string host,string from, string to) { array (array(string)) trick=tricklist(host, from, to); int tricklen = sizeof(trick); for (int i=0;i