> For the complete documentation index, see [llms.txt](https://zeyad-abulaban.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zeyad-abulaban.gitbook.io/notes/web-penetration-testing/web-vulns/imap-smtp-injection.md).

# IMAP & SMTP injection

***

An IMAP/SMTP Injection makes it possible to **access** a mail server which otherwise would not be directly accessible from the Internet. In some cases, these internal systems do not have the same level of infrastructure security and hardening that is applied to the front-end web servers.

![smtp](/files/wcieEg69HQ5qdKsT7JXJ)

Some examples of attacks using the IMAP/SMTP Injection technique are:

* Exploitation of vulnerabilities in the IMAP/SMTP protocol
* Application restrictions evasion
* Anti-automation process evasion
* Information leaks
* Relay/SPAM

## Identifying Vulnerable Parameters

### IMAP special parameters that should be used are:

![imap](/files/rZZ7mK2NW70oCMiGLr7W)

In this example, the “mailbox” parameter is being tested by manipulating all requests with the parameter in:

```txt
http://<webmail>/src/read_body.php?mailbox=INBOX&passed_id=46106&startMessage=1
```

The following examples can be used.

* Assign a null value to the parameter.
* Substitute the value with a random value.
* Add other values to the parameter.
* Add non standard special characters (i.e.: `\`, `'`, `"`, `@`, `#`, `!`, `|`).
* Eliminate the parameter. Examples:

```txt
1- http://<webmail>/src/read_body.php?mailbox=&passed_id=46106&startMessage=1

2- http://<webmail>/src/read_body.php?mailbox=NOTEXIST&passed_id=46106&startMessage=1

3- http://<webmail>/src/read_body.php?mailbox=INBOX PARAMETER2&passed_id=46106&startMessage=1

4- http://<webmail>/src/read_body.php?mailbox=INBOX"&passed_id=46106&startMessage=1

5- http://<webmail>/src/read_body.php?passed_id=46106&startMessage=1
```

The final result of the above testing gives the tester three possible situations:

* **S1** - The application returns a error code/message *(Successful injection)*
* **S2** - The application does not return an error code/message, but it does not realize the requested operation *(Successful injection - harder and must use blind)*
* **S3** - The application does not return an error code/message and realizes the operation requested normally

**Error example**

```txt
ERROR: Bad or malformed request.
Query: SELECT "INBOX""
Server responded: Unexpected extra arguments to Select
```

> For more details on exploitation: <https://owasp.org/www-project-web-security-testing-guide/stable/4-Web\\_Application\\_Security\\_Testing/07-Input\\_Validation\\_Testing/10-Testing\\_for\\_IMAP\\_SMTP\\_Injection>

### Whitepapers

* [RFC 0821 “Simple Mail Transfer Protocol”](https://tools.ietf.org/html/rfc821)
* [RFC 3501 “Internet Message Access Protocol - Version 4rev1”](https://tools.ietf.org/html/rfc3501)
* [Vicente Aguilera Díaz: “MX Injection: Capturing and Exploiting Hidden Mail Servers”](http://www.webappsec.org/projects/articles/121106.pdf)


---

# 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://zeyad-abulaban.gitbook.io/notes/web-penetration-testing/web-vulns/imap-smtp-injection.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.
