SMTP enum python

Viewed 168

I'm testing smtp enum on metasploitable, but I didn't get it to work.
The code that I'm using is:

import socket
import sys


ip = '192.168.1.137'
port = 25
users = ['msfadmin'] # Se deberia hacer leyendo de un fichero los usuarios

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(5)

    connect = s.connect((ip, port))
    banner = s.recv(1024)

    for user in users:
        if '220' in str(banner):
            s.send(('VRFY ' + user).encode())
            print(ip, s.recv(1024))
    s.close()

except socket.timeout as st:
    print('Timeout:', ip)
except socket.error as sr:
    print('Connection error', sr)

Nmap scan

Nmap scan report for 192.168.1.137
Host is up (0.00073s latency).

PORT   STATE SERVICE
25/tcp open  smtp

On line print(ip, s.recv(1024)) always give me timeout.

1 Answers
        s.send(('VRFY ' + user).encode())
        print(ip, s.recv(1024))

You are sending VRFY user. But you should send VRFY user\r\n because the command must end with CR+LF. The server will just wait for the rest of the command (the missing CRLF) which you don't send. Thus, both server and client wait for the other to send data.

For more see the SMTP standard because that's what standards are for.

Related