Outils pour utilisateurs

Outils du site


linux:telnet (lu 1192 fois)

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
linux:telnet [25-03-2015 16:46]
edmc73 créée
linux:telnet [26-06-2018 14:53]
edmc73
Ligne 1: Ligne 1:
 ====== Telnet et dialogue avec les serveurs ====== ====== Telnet et dialogue avec les serveurs ======
  
 +===== SMTP =====
 +
 +Tester une connection à un serveur SMTP
 +
 +
 +Scenario: 
 +Your domain: mydomain.com
 +Domain you wish to send to: theirdomain.com
 +
 +Sous windows pour trouver le serveur de mail
 +* Open a CMD prompt 
 +  NSLOOKUP 
 +  > set q=mx 
 +  > theirdomain.com 
 +  Response: 
 +  Non-authoritative answer: 
 +  theirdomain.com MX preference = 50, mail exchanger = mail.theirdomain.com
 +
 +
 +SMTP communicates over port 25. We will now try to use TELNET to connect to their mail server "mail.theirdomain.com"
 +
 +* Open a CMD prompt 
 +  telnet mail.theirdomain.com 25
 +
 +You should see something like this as a response: 
 +  220 mx.google.com ESMTP 6si6253627yxg.6
 +
 +Be aware that different servers will come up with different greetings but you should get SOMETHING. If nothing comes up at this point there are 2 possible problems. Port 25 is being blocked at your firewall, or their server is not responding. Try a different domain, if that works then it's not you.
 +
 +Now, use simple SMTP commands to send a test email. This is very important, you CANNOT use the backspace key, it will work onscreen but not be interpreted correctly. You have to type these commands perfectly.
 +
 +  ehlo mydomain.com 
 +  mail from:<martin9700@mydomain.com> 
 +  rcpt to:<recipient@theirdomain.com> 
 +  data 
 +  This is a test, please do not respond 
 +  . 
 +  quit
 +
 +So, what does that all mean? 
 +EHLO - introduce yourself to the mail server HELO can also be used but EHLO tells the server to use the extended command set (not that we're using that).
 +
 +MAIL FROM - who's sending the email. Make sure to place this is the greater than/less than brackets as many email servers will require this (Postini).
 +
 +RCPT TO - who you're sending it to. Again you need to use the brackets. See Step #4 on how to test relaying mail!
 +
 +DATA - tells the SMTP server that what follows is the body of your email. Make sure to hit "Enter" at the end.
 +
 +. - the period alone on the line tells the SMTP server you're all done with the data portion and it's clear to send the email.
 +
 +quit - exits the TELNET session.
 +
 +Step 4: Test SMTP relay
 +
 +Testing SMTP relay is very easy, and simply requires a small change to the above commands. See below:
 +
 +  ehlo mydomain.com 
 +  mail from:<martin9700@mydomain.com> 
 +  rcpt to:<recipient@someotherdomain.com> 
 +  data 
 +  This is a test, please do not respond 
 +  . 
 +  quit
 +
 +See the difference? On the RCPT TO line, we're sending to a domain that is not controlled by the SMTP server we're sending to. You will get an immediate error is SMTP relay is turned off. If you're able to continue and send an email, then relay is allowed by that server.
 +
 +
 +===== SMTP with Auth =====
 +
 +To encode text to base64, use the following syntax:
 +
 +  $ echo -n 'scottlinux.com rocks' | base64
 +  c2NvdHRsaW51eC5jb20gcm9ja3MK
 +To decode, use base64 -d. To decode base64, use a syntax like the following:
 +
 +  $ echo -n c2NvdHRsaW51eC5jb20gcm9ja3MK | base64 -d
 +  scottlinux.com rocks
 +
 +
 +What will be returned from each command is a base64 encoding of the username and password; save these as you will need them later. Now connect to the mail server using Telnet:
 +
 +  telnet mailserver.com 25
 +Greet the mail server:
 +
 +  EHLO mailserver.com
 +Tell the server you want to authenticate with it:
 +
 +  AUTH LOGIN
 +The server should have returned 334 VXNlcm5hbWU6; this is a base64 encoded string asking you for your username, paste the base64 encoded username you created earlier, example:
 +
 +  dXNlcm5hbWUuY29t
 +Now the server should have returned 334 UGFzc3dvcmQ6;. Again this is a base64 encoded string now asking for your password, paste the base64 encoded password you created, example:
 +
 +  bXlwYXNzd29yZA==
 +Now you should have received a message telling you that you successfully authenticated. If it failed your user/pass may have been wrong or your mailserver is broken.
 +
 +Below is a log of a real successful SMTP AUTH connection over Telnet:
 +<code>
 +user@localhost [~]# telnet exampledomain.com 25
 +Trying 1.1.1.1...
 +Connected to exampledomain.com (1.1.1.1).
 +Escape character is '^]'.
 +220-server1.exampledomain.com ESMTP Exim 4.66 #1 Wed, 09 May 2007 23:55:12 +0200
 +220-We do not authorize the use of this system to transport unsolicited,
 +220 and/or bulk e-mail.
 +EHLO exampledomain.com
 +250-server1.exampledomain.com Hello  [1.1.1.2]
 +250-SIZE 52428800
 +250-PIPELINING
 +250-AUTH PLAIN LOGIN
 +250-STARTTLS
 +250 HELP
 +AUTH LOGIN
 +334 VXNlcm5hbWU6
 +dXNlcm5hbWUuY29t
 +334 UGFzc3dvcmQ6
 +bXlwYXNzd29yZA==
 +
 +235 Authentication succeeded
 +</code>
  
 ===== HTTPS ===== ===== HTTPS =====
linux/telnet.txt · Dernière modification: 26-06-2018 14:53 de edmc73