Skip to content

Instantly share code, notes, and snippets.

@andreibosco
Created May 10, 2021 17:17
Show Gist options
  • Save andreibosco/f4de3e267fe0e461e9d29fa92e345e41 to your computer and use it in GitHub Desktop.
Save andreibosco/f4de3e267fe0e461e9d29fa92e345e41 to your computer and use it in GitHub Desktop.
Testing SMTP authentication with TLS using telnet

Sources

Steps

  1. Create base64 string of username and password:
# With the base64 binary
echo echo -ne '\0login\0password' | base64
ZWNobyAtbmUgXDBsb2dpblwwcGFzc3dvcmQK
# Or use Openssl
echo echo -ne '\0login\0password' | openssl base64
ZWNobyAtbmUgXDBsb2dpblwwcGFzc3dvcmQK
# Or use Perl
perl -MMIME::Base64 -e 'print encode_base64("\0login\0password")'
ZWNobyAtbmUgXDBsb2dpblwwcGFzc3dvcmQK
  1. Connect to SMTP server using openssl: openssl s_client -starttls smtp -connect smtp.yourserver.com 587
  2. Initiate communication: EHLO smtp.yourserver.com
  3. Authenticate using the base64 string: AUTH PLAIN ZWNobyAtbmUgXDBsb2dpblwwcGFzc3dvcmQK
  4. Send out your email:
mail from:<[email protected]>
rcpt to:<[email protected]>
data
Subject: Test
Email content lorem ipsum.
.

Tip

If you get an SSL_renegotiate:wrong ssl version error, that's because an uppercase R is recognized as TLS renegotiation command. The solution is to use lowercase command (e.g., rcpt instead of RCPT).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment