#!/usr/bin/env python # # Author: Necati Demir # Version: v0.1 # import socket import sys def send_command(data): global s sys.stdout.write(">>>"+data) s.send(data) received_data = s.recv(1024) for r in received_data.split("\r\n")[:-1]: sys.stdout.write("<<<"+r+"\n") return int(received_data.split("\r\n")[-2].split()[0]) def send_request(mail_from, rcpt_to): print "-----------" global i i=i+1 print "Relay Test " + str(i) send_command("RSET\n") if send_command("MAIL FROM:<"+mail_from+">\n") == 250: if send_command("RCPT TO:<"+rcpt_to+">\n") == 250: print """ Host appeared to accept a message for relay. THIS MAY OR MAY NOT MEAN THAT IT'S AN OPEN RELAY. Some systems appear to accept relay mail, but then reject messages internally rather than delivering them, but you cannot tell at this point whether the message will be relayed or not. You cannot tell if it is really an open relay without sending a test message; this anonymous user test DID NOT send a test message.""" sys.exit(1) if len(sys.argv) != 2: print """Usage: ./mailrelaytester smtp-server Example: ./mailrelaytester gmail-smtp-in.l.google.com""" sys.exit(2) i=0 HOST = sys.argv[1] PORT = 25 print "Connecting to " + HOST print "" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) sys.stdout.write("<<<"+s.recv(1024)) send_command("HELO spam.org.tr\n") print "" sys.stdout.flush() send_request("spamtest@spam.org.tr", "securitytest@spam.org.tr") #1 send_request("spamtest", "securitytest@spam.org.tr") #2 send_request("", "securitytest@spam.org.tr") #3 index=HOST.find(".") send_request("spamtest@"+HOST[0:], "securitytest@spam.org.tr") #4 send_request("spamtest@["+socket.gethostbyname(HOST)+"]", "securitytest@spam.org.tr") #5 send_request("spamtest@"+HOST[0:], "securitytest%spam.org.tr@"+HOST[0:]) #6 send_request("spamtest@"+HOST[0:], "securitytest%spam.org.tr@["+socket.gethostbyname(HOST)+"]") #7 send_request("spamtest@"+HOST[0:], "\"securitytest@spam.org.tr\"") #8 send_request("spamtest@"+HOST[0:], "\"securitytest%spam.org.tr\"") #9 send_request("spamtest@"+HOST[0:], "securitytest@spam.org.tr@"+HOST[0:]) #10 send_request("spamtest@"+HOST[0:], "\"securitytest@spam.org.tr\"@"+HOST[0:]) #11 send_request("spamtest@"+HOST[0:], "securitytest@spam.org.tr@["+socket.gethostbyname(HOST)+"]") #12 send_request("spamtest@"+HOST[0:], "@"+HOST[0:]+":securitytest@spam.org.tr") #13 send_request("spamtest@"+HOST[0:], "@["+socket.gethostbyname(HOST)+"]:securitytest@spam.org.tr") #14 send_request("spamtest@"+HOST[0:], "spam.org.tr!securitytest") #15 send_request("spamtest@"+HOST[0:], "spam.org.tr!securitytest@"+HOST[0:]) #16 send_request("spamtest@"+HOST[0:], "spam.org.tr!securitytest@["+socket.gethostbyname(HOST)+"]") #17 print "----------" send_command("QUIT\n") s.close() print """ All tests performed, no relays accepted.""" sys.exit(0)