08TCP
SMTP
Port 25 is the standard SMTP port for server-to-server email relay but is often blocked due to spam abuse; port 587 is the recommended default for secure email submission, while port 465 is a legacy.
| Command | Description |
|---|---|
| HELO | Introduces the client to the server (used in SMTP). |
| EHLO | Extended HELO; used in ESMTP to request server capabilities. |
| MAIL FROM: | Specifies the sender's email address. |
| RCPT TO: | Specifies the recipient's email address. |
| DATA | Indicates that the email content (headers + body) follows. |
| RSET | Resets the current mail transaction. |
| VRFY | Verifies if a user/email address exists on the server. |
| EXPN | Expands a mailing list to show all recipients. |
| NOOP | No operation; used to keep the connection alive. |
| QUIT | Terminates the SMTP session. |
| STARTTLS | Initiates a TLS-secured connection (if supported). |
| AUTH | Begins the authentication process (e.g, LOGIN, PLAIN, CRAM-MD5). |
| Code | Type | Meaning |
|---|---|---|
| 211 | Success | System status or help reply |
| 214 | Success | Help message |
| 220 | Success | Service ready |
| 221 | Success | Service closing transmission channel |
| 250 | Success | Requested action completed |
| 251 | Success | User not local; will forward |
| 252 | Success | Cannot verify user, but will accept message |
| 354 | Intermediate | Start mail input; end with . |
| 421 | Error | Service not available, closing transmission channel |
| 450 | Error | Requested action not taken: mailbox unavailable |
| 451 | Error | Requested action aborted: local error in processing |
| 452 | Error | Requested action not taken: insufficient system storage |
| 500 | Error | Syntax error, command unrecognized |
| 501 | Error | Syntax error in parameters or arguments |
| 502 | Error | Command not implemented |
| 503 | Error | Bad sequence of commands |
| 504 | Error | Command parameter not implemented |
| 550 | Error | Requested action not taken: mailbox unavailable |
| 551 | Error | User not local; please try |
| 552 | Error | Requested mail action aborted: exceeded storage allocation |
| 553 | Error | Requested action not taken: mailbox name not allowed |
| 554 | Error | Transaction failed (message rejected) |
- Nmap Script
bash2 lines
sudo nmap --script smtp-enum-users -p25 <IP>sudo nmap --script smtp-open-relay,smtp-commands,smtp-ntlm-info -p25 <IP>- Username enumerate
bash15 lines
## ------------------| smtp-user-enumsmtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 10.10.10.17smtp-user-enum -U /usr/share/seclists/Usernames/Honeypot-Captures/multiplesources-users-fabian-fingerle.de.txt -m 50 -M RCPT -D humongousretail.com -t 10.10.10.17
## ------------------| Metasploitmsfconsoleuse auxiliary/scanner/smtp/smtp_enumset RHOSTS <IP>set USER_FILE /usr/share/seclists/Usernames/Names/names.txtset THREADS 10set RPORT 25run
## ------------------| Bash Scriptfor i in $(cat /usr/share/seclists/Usernames/Names/names.txt);do echo -e "HELO test.com\nVRFY $i\nQUIT" | nc -nv <IP> 25 | grep -E "250|550"; done- Check Auth
bash5 lines
telnet <IP> 587EHLO mailserver.comAUTH LOGIN<Username_in_base64> # echo -n "username" | base64<Password_in_base64> # echo -n "password" | base64- Send mail
bash62 lines
## !! Be aware about from address. If you are using same domain for both from and to. they will ask auth. So please use [email protected] first !!## ------------------| Using Swaksswaks --from [email protected] --to [email protected] --header 'Subject: Hello world' --body 'This is msg body' --server 10.10.10.197
## ------------------| Using sendEmailsendEmail -m 'Hello machan' -f [email protected] -t [email protected] -s <IP> -u "Message Subject" -a attachment.pdfsendEmail -o message-file=message.txt -f [email protected] -t [email protected] -s <IP> -u "Message Subject" -a attachment.pdf
## ------------------| Using Telnettelnet <IP> 25HELO writer.htbDATASubject: Test mailHello h4rith.QUIT
## ------------------| Using NetCatnc <IP> 25HELO writer.htbDATASubject: Test mailHello h4rith.QUIT
## ------------------| Using NodeJSconst nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({ host: 'smtp.example.com', // Your provider's SMTP server port: 587, // Common: 587 (STARTTLS), 465 (SSL), 25 (non-auth, old) secure: false, // true for 465, false for other ports auth: { pass: 'your_password_or_app_password' }});
// Optional: For self-signed certs or debugging// tls: {// rejectUnauthorized: false// }
const mailOptions = { subject: 'SMTP Test', text: 'Test email', // html: '<p>HTML body with <strong>custom SMTP</strong></p>'};
transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.error('Send error:', error); } console.log('Email sent:', info.response);});- SMTP server
python38 lines
## ------------------| Using smtpd (deprecated)import smtpdimport asyncore
class CustomSMTPServer(smtpd.SMTPServer): def __init__(self, localaddr, remoteaddr): smtpd.SMTPServer.__init__(self, localaddr, remoteaddr)
def process_message(self, peer, mailfrom, rcpttos, data): print('Received email from:', mailfrom) print('To:', rcpttos) print('Message:', data)
server = CustomSMTPServer(('0.0.0.0', 1025), None)asyncore.loop()
## ------------------| Using asyncioimport asynciofrom aiosmtpd.controller import Controller
class CustomSMTPHandler: async def handle_RCPT(self, server, session, envelope, address, rcpt_options): envelope.rcpt_tos.append(address) return '250 OK'
async def handle_DATA(self, server, session, envelope): print('Received email from:', envelope.mail_from) print('To:', envelope.rcpt_tos) print('Message:', envelope.content.decode('utf-8')) return '250 OK'
async def main(loop): handler = CustomSMTPHandler() controller = Controller(handler, hostname='localhost', port=1025) controller.start()
loop = asyncio.get_event_loop()loop.run_until_complete(main(loop))