🖥️telnet

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the telnet command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ████████╗███████╗██╗     ███╗   ██╗███████╗████████╗
#                ╚══██╔══╝██╔════╝██║     ████╗  ██║██╔════╝╚══██╔══╝
#                   ██║   █████╗  ██║     ██╔██╗ ██║█████╗     ██║   
#                   ██║   ██╔══╝  ██║     ██║╚██╗██║██╔══╝     ██║   
#                   ██║   ███████╗███████╗██║ ╚████║███████╗   ██║   
#                   ╚═╝   ╚══════╝╚══════╝╚═╝  ╚═══╝╚══════╝   ╚═╝   
                

                                                                  
telnet localhost 2601
# telnet host port 

telnet http://telehack.com 
# A public telnet server with many little games and distractions.

HOST=127.0.0.1;for((port=1;port<=65535;++port)); do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then echo -en "\n\nport $port/tcp is open\n\n";fi;done | grep open
# scans for open ports using telnet

#-----------------------------------------------[CODE BEGINN ]-------------------------------------------------------------------------#
Using telnet

This may help when testing MTA setup such as Postfix, Sendmail, qmail, etc..

    Note S: stand for System message and C: stand for Client user. It is just for tutorial purpose. Do not need to enter C: in your input.
    Just dot (period character) is meaningful.

[root@hostname]# telnet mail.domain.com 25
    S: Trying 123.45.67.890...
    S: Connected to mail.domain.com.
    S: Escape character is '^]'.
    S: 220 mail.domain.com ESMTP Postfix
    C: ehlo domain.com
    S: 250-mail.domain.com  
    S: 250-PIPELINING 
    S: 250-SIZE 10240000  
    S: 250-VRFY  
    S: 250-ETRN  
    S: 250-STARTTLS  
    S: 250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5  
    S: 250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5  
    S: 250 8BITMIME
    C: mail from:<[email protected]>
    S: 250 Ok
    C: rcpt to:<[email protected]>
    S: 250 ok
    C: data
    S: 354 End data with <CR><LF>.<CR><LF>
    C: Subject: Your subject message
    C: Your messages.
    C: Your messages.
    C: .
    S: 250 Ok: queued as ABC1D1C123
    C: quit
    S: 221 Bye
    S: Connection closed by foreign host.

Using mail program
# mail [email protected]
Subject: Hello
Hi,

Testing. Testing. Take care.

. (Type  DOT (.) followed by ENTER KEY}
Cc: (Press ENTER KEY)

 IMAP
 
telnet localhost 143
1 capability
2 login username@domain password

 POP3

Test Your Pop3 Connection From Telnet
Type: telnet "the name of the pop3 server" 110
Type: user "username"
Type: pass "password"
Type: list
You will then get a list over the mails in your mailbox
Type: retr "mailnumber"
You will then see the mail with the mail number
End the session by typing "Quit"

Other Telnet commands:
stat = Status of you mailbox
dele N = delete mail nummer "N"
#------------------------------------------------[CODE ENDE]------------------------------------------------------------------------#

telnet mapscii\.me 
# World maps from OpenStreetMap right in your terminal w/ mouse support. Arrow keys & a/z to zoom, or mouse. 

telnet towel.blinkenlights\.nl 
# StarWars in ASCII. Also, towel! (Note the IPv4 and IPv6 addresses use of 42 too)

telnet http://nyancat.dakko.us  
# The Nyan Cat (flying rainbow poptart cat) telnet server returns! https://nyancat.dakko.us/ 

#-----------------------------------------------------------------------///

# Download a file from a webserver with telnet
(echo 'GET /'; echo; sleep 1; ) | telnet www.google.com 80
# Explanation: If you are ever in a minimal headless *nix which does not have any command line utilities for downloading files (no curl, wget, lynx) but you have telnet, then this can be a workaround.
# Another option is netcat:
/usr/bin/printf 'GET / \n' | nc www.google.com 80
# Use lynx.
# It is pretty common for most of Unix/Linux.  -dump: dump the first file to stdout and exit
lynx -dump http://www.google.com

##############################################

# Diverse Maildienste auf der Kommandozeile testen
# Vertrauen ist gut, Kontrolle ist besser. Hier folgt eine Sammlung von Kommandozeilentests für diverse Maildienste (smtp, pop, imap...)

# Wir gehen davon aus, dass der Mailserver erfolgreich installiert ist, in diesem Fall sei das Postfix mit Postgrey und Amavis, das Zertifikat wurde erstellt, die erforderlichen Dienste laufen und die gewünschten Ports sind in der Firewall geöffnet. Die Dienste imap, imaps, pop3 und pop3s werden von Dovecot zur Verfügung gestellt.
# Als Beispieldomain verwende ich dein.mailserver.net, als Beispiel-IP 1.2.3.4, der Beispieluser (brauchen wir zum Testen der Dienste mit Login) heißt userlein und er hat das Passwort "geheim". Um es übersichtlicher zu machen, sind die einzugebenden Befehle grün, die Antworten des Servers, auf die es besonders ankommt sind blau. Nun aber zu den Praxisbeipielen:

# 1) Funktioniert der Mailserver überhaupt (Test am Server selbst):
#-----------------------------------------------------------------------///
telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 dein.mailserver.net ESMTP Postfix
quit
221 2.0.0 Bye
Connection closed by foreign host.

Er funktioniert, also lauscht auf Port 25.

# 2) Funktioniert Greylisting (Test von anderswo, eine frische IP, die der Mailserver, genau genommen Postgrey, noch nicht "kennt"):
#-----------------------------------------------------------------------///
telnet dein.mailserver.net 25
Trying 1.2.3.4...
Connected to dein.mailserver.net.
Escape character is '^]'.
220 dein.mailserver.net ESMTP Postfix
helo localhost
250 dein.mailserver.net
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
450 4.7.1 <[email protected]>: Recipient address rejected: Greylisted, see http://yadda/yadda/yadda..
quit
221 2.0.0 Bye
Connection closed by foreign host.

Greylisting funktioniert. Nach der in postgrey konfigurierten Zeit (z.B. 5 Min.) darf man natürlich nicht nochmal im Greylisting hängen bleiben.

# 3) Wird relaying fremder Domains verweigert (muss es! Test von irgendwo):
#-----------------------------------------------------------------------///
telnet dein.mailserver.net 25
Trying 1.2.3.4...
Connected to dein.mailserver.net.
Escape character is '^]'.
220 dein.mailserver.net ESMTP Postfix
helo example.com
250 dein.mailserver.net
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
554 5.7.1 <[email protected]>: Relay access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

Brav: "Relay access denied"

# 4) Funktioniert pop3 (vom Mailserver selbst, plaintext):
#-----------------------------------------------------------------------///
telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER userlein
+OK
PASS geheim
+OK Logged in.
LIST
+OK 3 messages:
1 4136
2 1705
3 1709
.
QUIT
+OK Logging out.
Connection closed by foreign host.

Verwendete Kommandos: USER, PASS, LIST, QUIT
Derselbe Test kann natürlich auch von remote ausgeführt werden.
Für diesen und die anderen Tests gilt: die Kommandos müssen nicht groß geschrieben werden.

# 5) Funktioniert imap (vom Mailserver selbst, plaintext):
#-----------------------------------------------------------------------///
telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK Dovecot ready.
01 LOGIN userlein geheim
01 OK Logged in.
02 LIST "" *
* LIST (\NoInferiors \UnMarked) "/" "Queue"
* LIST (\NoInferiors \UnMarked) "/" "Sent"
* LIST (\NoInferiors \Marked) "/" "Trash"
* LIST (\NoInferiors \UnMarked) "/" "Drafts"
* LIST (\HasNoChildren \UnMarked) "/" "INBOX"
02 OK List completed.
03 LOGOUT
* BYE Logging out
03 OK Logout completed.
Connection closed by foreign host.

Verwendete Kommandos: LOGIN, LIST "" *, LOGOUT, immer mit Nummer davor. Wir lassen uns einfach unsere Ordner auflisten.

# 6) Funktioniert STARTTLS für smtp (getestet von remote):
#-----------------------------------------------------------------------///
telnet dein.mailserver.net 25
Trying 1.2.3.4...
Connected to dein.mailserver.net.
Escape character is '^]'.
220 dein.mailserver.net ESMTP Postfix
ehlo localhost
250-dein.mailserver.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

Es wird auf alle Fälle vom MTA (Postfix) angeboten.
Die doppelte Angabe von "AUTH" ist übrigens kein Fehler, das gehört so - einmal mit, einmal ohne "=" (für manche Clients).

Funktioniert es aber auch wirklich?

openssl s_client -connect dein.mailserver.net:25 -crlf -starttls smtp

...sehr viel Info über den public key des Servers...
---
SSL handshake has read 1556 bytes and written 369 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: D14E6blablabla
    Session-ID-ctx:
    Master-Key: 654C5blablabla
    Key-Arg   : None
    Start Time: 1262264795
    Timeout   : 300 (sec)
    Verify return code: 18 (self signed certificate)
---
250 DSN
quit
221 2.0.0 Bye
read:errno=0

Aha, es ist ein selbst unterzeichnetes Zertifikat, das auch wirklich funktioniert.

# 7) Funktionieren imaps und pop3s:
#-----------------------------------------------------------------------///

IMAPS wird mit folgendem Befehl getestet:

openssl s_client -connect dein.mailserver.net:993

POP3S mit folgendem:

openssl s_client -connect dein.mailserver.net:995

Im Dialog mit Dovecot (bietet in unserem Beispiel imap(s) und pop3(s)) funktionieren jeweils die selben Befehle wie bei Verbindungen ohne Verschlüsselung (siehe weiter oben).

# 8) Funktioniert der Virenfilter:
#-----------------------------------------------------------------------///
Das testet man am einfachsten mit dem Eicar Testvirus: www.eicar.org/anti_virus_test_file.htm
Einfach an einen lokalen User als Anhang schicken. Es darf nicht durchkommen.

# 9) Funktioniert der Spamfilter:
#-----------------------------------------------------------------------///
Auch das ist einfach: in der Datei /etc/mail/spamassassin/local.cf folgende Zeilen einfügen:

header  LOCAL_DEMO_SUBJECT      Subject =~ /halloweltdasistnurspam/
score   LOCAL_DEMO_SUBJECT      15.0

Amavisd durchladen und dann mit genau dem Betreff "halloweltdasistnurspam" ein Mail am besten von anderswo an einen lokalen User senden. Eventuell noch den Score anpassen.

echo 'ein testmail' | mail -s 'halloweltdasistnurspam' [email protected]

#-----------------------------------------------------------------------///

#==============================##==============================#
# CMD TELNET						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░