Hi
I have simple python script that open a TCP socket,connect to the SMTP servert and issue a VRFY command.
When I run the script I got error,I wonder How can I fix error?

#!/usr/bin/python
import socket
import sys
if len(sys.argv) != 2:
        print "Usage: vrfy.py <username>"
        sys.exit(0)
# Create a Socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the Server
connect=s.connect(('127.0.0.1',25))
# Recieve the banner
banner=s.recv(1024)
print banner
# VRFY a user
s.send('VRFY ' + sys.argv[1] + '\r\n')
result=s.recv(1024)
print result
# Close the socket
s.close()






        connect=s.connect(('127.0.0.1',25))
      File "C:\Python27\lib\socket.py", line 224, in meth
        return getattr(self._sock,name)(*args)
    socket.error: [Errno 10013] An attempt was made to access a socket in a way forb
    idden by its access permissions

Same error in linux ?

File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

Edited 2 Years Ago by tony75

Have you got a server listening on port 25? This is not the Windows default configuration. (>netstat -aon).

It's easy enuf to write your own mail server that just looks for connects, accepts them, and logs appropriate data.

Thanks for your answer
No I did't get server listening on port 25 when I run in linux!!?

I still got this error anyone now please

File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

I don't know this subject but did you try to connect using the standard module smtplib ? Also do you have a way to check that the server is running ?

Thanks Sir
I find this code in http://pentestlab.wordpress.com/2012/11/26/smtp-vrfy-scanner/?goback=.gde_113049_member_189513676
But got error becuse of I think indeting? any help?

#!/usr/bin/python
# This was written for educational and learning purposes only.
# The author will be not responsible for any damage!
# SMTP VRFY Scanner

import socket, sys, fileinput, re, time
from optparse import OptionParser

usage =  "./%prog -t <target> -p <port> -i <inputfile>\nExample: ./%prog -t 74.52.252.187 -p 25 -f names.txt"
parser = OptionParser(usage=usage)
parser.add_option("-t", type="string",
action="store", dest="target",
help="Target Host")
parser.add_option("-p", type="int",
action="store", dest="port",
help="Target Port")
parser.add_option("-f", action="store",
dest="filename",help="Inputfile")
(options, args) = parser.parse_args()

host = options.target
port = options.port
inputfile = options.filename

if len(sys.argv) != 7:
    print "\n|---------------------------------------------------------------|"
    print "|             SMTP vrfy enumeration scanner v0.5                |"
    print "|                      by MrMe 07/2009                          |"
    print "|                    Special Greetz: krma                       |"
    print "|---------------------------------------------------------------|\n"
    parser.print_help()
sys.exit()
try:
    names = open(sys.argv[6], "r")
except(IOError):
    print "Error: Check your wordlist path\n"
sys.exit(1)

line = names.readline()
counter = 0

print "[+] Connecting to server"
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

def connect():
    try:
        connect=s.connect((host,port))
    except socket.timeout:
print "\n[-] Server timed out"
sys.exit(1)
except socket.error:
print "\n[-] There was an error with the server"
sys.exit(1)
print "[+] Connected on" +timer()
print "[+] Waiting for SMTP banner"
banner=s.recv(1024)
print banner

def timer():
now = time.localtime(time.time())
return time.asctime(now)

connect()

for line in names:
s.send('VRFY '+line)
result=s.recv(1024)
bad = re.match("502",result)
bad1 = re.search("send some mail",result)
found = re.search("252",result)
notfound = re.match("550",result)
if bad or bad1:
print "[-] This server is not vulnerable!"
sys.exit(1)
elif notfound:
print "[-] Not found "+line
elif found:
print "[+] Found! "+line
if counter == 20:
s.close()
print "[+] Resetting connection"
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
connect()
counter = 0
counter +=1

s.close()
This article has been dead for over six months. Start a new discussion instead.