h4rithdpentest

$Target variables

Set it once. Every <IP>, <USER> or <DOMAIN> placeholder in the notes is rewritten live, and the copy buttons copy your values.

Stored in this browser only
h4rithd.com ↗

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.

Port
25 · 587
Read
3 min
Blocks
5
Updated
Target
CommandDescription
HELOIntroduces the client to the server (used in SMTP).
EHLOExtended HELO; used in ESMTP to request server capabilities.
MAIL FROM:Specifies the sender's email address.
RCPT TO:Specifies the recipient's email address.
DATAIndicates that the email content (headers + body) follows.
RSETResets the current mail transaction.
VRFYVerifies if a user/email address exists on the server.
EXPNExpands a mailing list to show all recipients.
NOOPNo operation; used to keep the connection alive.
QUITTerminates the SMTP session.
STARTTLSInitiates a TLS-secured connection (if supported).
AUTHBegins the authentication process (e.g, LOGIN, PLAIN, CRAM-MD5).
CodeTypeMeaning
211SuccessSystem status or help reply
214SuccessHelp message
220SuccessService ready
221SuccessService closing transmission channel
250SuccessRequested action completed
251SuccessUser not local; will forward
252SuccessCannot verify user, but will accept message
354IntermediateStart mail input; end with .
421ErrorService not available, closing transmission channel
450ErrorRequested action not taken: mailbox unavailable
451ErrorRequested action aborted: local error in processing
452ErrorRequested action not taken: insufficient system storage
500ErrorSyntax error, command unrecognized
501ErrorSyntax error in parameters or arguments
502ErrorCommand not implemented
503ErrorBad sequence of commands
504ErrorCommand parameter not implemented
550ErrorRequested action not taken: mailbox unavailable
551ErrorUser not local; please try
552ErrorRequested mail action aborted: exceeded storage allocation
553ErrorRequested action not taken: mailbox name not allowed
554ErrorTransaction 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-enum
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 10.10.10.17
smtp-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
## ------------------| Metasploit
msfconsole
use auxiliary/scanner/smtp/smtp_enum
set RHOSTS <IP>
set USER_FILE /usr/share/seclists/Usernames/Names/names.txt
set THREADS 10
set RPORT 25
run
## ------------------| Bash Script
for 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> 587
EHLO mailserver.com
AUTH 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 Swaks
swaks --from [email protected] --to [email protected] --header 'Subject: Hello world' --body 'This is msg body' --server 10.10.10.197
## ------------------| Using sendEmail
sendEmail -m 'Hello machan' -f [email protected] -t [email protected] -s <IP> -u "Message Subject" -a attachment.pdf
sendEmail -o message-file=message.txt -f [email protected] -t [email protected] -s <IP> -u "Message Subject" -a attachment.pdf
## ------------------| Using Telnet
telnet <IP> 25
HELO writer.htb
DATA
Subject: Test mail
Hello h4rith
.
QUIT
## ------------------| Using NetCat
nc <IP> 25
HELO writer.htb
DATA
Subject: Test mail
Hello h4rith
.
QUIT
## ------------------| Using NodeJS
const 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: {
user: '[email protected]', // Your email address
pass: 'your_password_or_app_password'
}
});
// Optional: For self-signed certs or debugging
// tls: {
// rejectUnauthorized: false
// }
const mailOptions = {
from: '"HarithD" <[email protected]>',
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 smtpd
import 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 asyncio
import asyncio
from 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))