> For the complete documentation index, see [llms.txt](https://ivalexev.gitbook.io/rednote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ivalexev.gitbook.io/rednote/utility/service/smtp-25-465-587.md).

# SMTP (25-465-587)

<details>

<summary>Protocol Information</summary>

SMTP is a communication protocol used for the transmission of electronic mail.\
SMTP is often combined with [IMAP](/rednote/utility/service/imap-143-993.md) or [POP3](/rednote/utility/service/pop3-110-995.md) protocols, for email management.

Client (`MUA`) ➞ Submission Agent (`MSA`) ➞ Open Relay (`MTA`) ➞ Mail Delivery Agent (`MDA`) ➞ Mailbox (`POP3/IMAP`)

</details>

## Port

<table data-header-hidden><thead><tr><th width="166">Port</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:green;"><strong>25</strong></mark><strong> TCP</strong></td><td>SMTP (unencrypted)</td></tr><tr><td><mark style="color:green;"><strong>465</strong></mark><strong> TCP</strong></td><td>SMTP (encrypted) </td></tr><tr><td><mark style="color:green;"><strong>587</strong></mark><strong> TCP</strong></td><td>SMTP (encrypted) </td></tr></tbody></table>

## Config File

* `/etc/postfix/main.cf`

## Interact

{% code overflow="wrap" %}

```bash
telnet <IP> <PORT>
```

{% endcode %}

{% code overflow="wrap" %}

```bash
nc <IP> <PORT>
```

{% endcode %}

[Commands and Response](https://mailtrap.io/blog/smtp-commands-and-responses/).

{% code title="Example" overflow="wrap" %}

```bash
telnet <IP> <PORT>
> HELO mail1.inlanefreight.htb   # or EHLO inlanefreight.htb
> AUTH PLAIN 
> <OUTPUT>  # echo -ne '\0mail1.inlanefreight.htb\0<PASSWORD>' | base64
> MAIL FROM: <cry0l1t3@inlanefreight.htb>
> RCPT TO: <mrb3n@inlanefreight.htb> NOTIFY=success,failure
> DATA
> SUBJECT: Test message
> <MESSAGE>
> .
> QUIT
```

{% endcode %}

## Attacks

### User Discovery&#x20;

The **`VRFY`** command causes the server to check whether or not a particular user exists and get the answer.\
The **`EXPN`** command is used with a mailing list and will list all users on that list. \
The **`RCPT TO`** command identifies the recipient of the e-mail message and can be repeated several times to list valid users.

<table><thead><tr><th width="172">Tools</th><th>Details</th></tr></thead><tbody><tr><td><a href="https://github.com/cytopia/smtp-user-enum">smtp-user-enum</a></td><td><code>smtp-user-enum -m [VRFY,EXPN,RCPT] -U &#x3C;WORDLIST> &#x3C;IP> &#x3C;PORT></code><br>---<br><code>smtp-user-enum -M [VRFY,EXPN,RCPT] -U &#x3C;WORDLIST> -t &#x3C;IP> -w 60 [-D &#x3C;DOMAIN> for RCPT]</code></td></tr></tbody></table>

### Open Relay

An open relay is a mail server that is configured in such a way that it allows email to be sent to anyone, even unauthorized users, without any authentication control or limitation on access. In other words, it is an “open” mail server that accepts to forward email from external sources to recipients outside its domain. This configuration can be very problematic because it makes the server vulnerable to improper use, particularly by spammers and malicious attackers (phishing). These can exploit open relay to send huge amounts of unwanted email, hiding their identities and making it appear that the mail traffic is coming from the exploited server.

Check if it is an Open Relay

```
NMAP NSE: smtp-open-relay
```

Sending emails without authentication

{% code overflow="wrap" %}

```bash
swaks --from notifications@inlanefreight.com --to employees@inlanefreight.com --header 'Subject: Company Notification' --body 'Hi All, we want to hear from you! Please complete the following survey. http://mycustomphishinglink.com/' --server <IP>
```

{% endcode %}

{% code overflow="wrap" %}

```bash
swaks --from notifications@inlanefreight.com --to employees@inlanefreight.com -ap --attach @config.Library-ms --body @body.txt --header 'Subject: Error' --suppress-data --server <IP>
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ivalexev.gitbook.io/rednote/utility/service/smtp-25-465-587.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
