SMTP Auth Gotcha
SMTP Auth Gotcha
shtml
One of the things to test is whether or not your server correctly supports the AUTH
command. This command is used when a remote client wishes to identify themself as an
"authenticated" user, normally so that they can use your server as an outbound mail
relay. This is very handy for companies with employees who travel, or for ISPs with clients
who travel.
Note: Make sure to use \0 both as the first character of what you're encoding, and as the
separator between the userid and the password. There was an error with the original version of
these directions- I had forgotten about needing a \0 at the beginning. Sorry all!
Another reader pointed out that perl silently interprets the "@" sign in the middle of a string and
replaces it with the contents of an array with that name, if one exists... or with nothing, if not. I
just did a full two-way test with my real password, and it turns out if you don't put a backslash in
front of the "@" sign it won't work. Good call.
And JT Justman pointed out that if you use \0 as the separator, and the userid or password happens
to start with a digit, perl will try to find and use a three-digit octal character code instead of a
one-digit null byte with two normal digits behind it. Using \000 instead of just \0 prevents this from
happening.
1 of 4
"decode_base64" (and put the encoded string between the double quotes, obviously.)
% telnet 1.2.3.4 25
To connect to a server which should support TLS, you may wish to verify that it does
support TLS first. When you send the EHLO command, the server will respond with
a list of the items it supports. If you see STARTTLS on the list, it means the server
will allow you to send the STARTTLS command. Example:
% telnet 1.2.3.4 25
220 a.mx.jms1.net NO UCE ESMTP
ehlo testing
250-a.mx.jms1.net NO UCE
250-STARTTLS
250-PIPELINING
250 8BITMIME
quit
Once you have verified that the server supports the STARTTLS command, you can
use the " -starttls smtp" option of openssl s_client to connect. This makes openssl connect
normally (without encryption), send a STARTTLS command, negotiate the SSL
encryption, and then allow you to interact with the encrypted session. For example,
to connect to a TLS-enabled SMTP servers on IP address 1.2.3.4, you would use this
command:
And for an SSL server (where you connect to a different port number and have to
establish an SSL connection before the SMTP conversation even starts) on IP
address 1.2.3.4 port 465, you would use this command:
When the banner is received, a normal SMTP client would send an EHLO command to the
server in order to identify the client machine, as well as ask for a list of the capabilities
supported by the server.
If you are using an openssl command to connect to an SSL or TLS server, make sure to enter your
2 of 4
SMTP commands in lowercase as shown here. The openssl "s_client" command watches what you
type- if you send a line of text starting with a capital "R", it will re-key the SSL layer instead of
sending your command to the server... and if you send a line of text which starts with a capital
"Q", it will terminate the SSL connection and exit.
Look at the response from your EHLO command, make sure AUTH is on the list, and that
PLAIN is one of the options it supports. If it's not listed, the server will not let you send an
AUTH command. This may be because the connection is not secured and the server is
protecting you from sending your authentication information across the net in plain
text...
If you see this message, you are authenticated. If you see this one instead...
... then obviously it means you are not authenticated. If you were not able to
authenticate, you can try another AUTH PLAIN command- although if the server is
logging the traffic or running an intrusion detection system, having multiple AUTH
commands in a single SMTP session is enough to raise a red flag. Be careful not to ban
your test client's IP address.
3 of 4
250 ok
data
354 go ahead
From: John <[email protected]>
To: Nobody <[email protected]>
Subject: fnord
hail eris!
.
250 ok 1113954693 qp 29052
quit
221 a.mx.jms1.net NO UCE
4 of 4