7.protocols 2

1,938 views

Published on

SMTP, POP3, IMAP, HTTP

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,938
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
167
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

7.protocols 2

  1. 1. Send Mail TransportSend Mail TransportProtocol (SMTP)Protocol (SMTP)➢ 1982 - RFC 8211982 - RFC 821➢ 2008 - RFC 5321 (ESMTP)2008 - RFC 5321 (ESMTP)➢ TCP ports 25 and 587TCP ports 25 and 587➢ Mail User Agent(MUA)Mail User Agent(MUA)➢ Mail Submission Agent(MSA)Mail Submission Agent(MSA)➢ Mail Transfer Agent(MTA)Mail Transfer Agent(MTA)➢ Mail Delivery Agent(MDA)Mail Delivery Agent(MDA)
  2. 2. MUAMSAMSAMTAMTAMDAMDAMTAMTAmailmailqueuequeue-mail1-mail1-mail2-mail2-mail3-mail3mailboxmailbox
  3. 3. SMTP commandsSMTP commands➢ HELOHELO➢ EHLOEHLO➢ MAIL FROM:MAIL FROM:➢ RCPT TO:RCPT TO:➢ DATADATA➢ RSETRSET➢ VRFYVRFY➢ HELPHELP➢ QUITQUIT➢ Valid replies (2xx)Valid replies (2xx)➢ Transient errors(4xx)Transient errors(4xx)➢ Permanent errors(5xx)Permanent errors(5xx)
  4. 4. SMTP commandsSMTP commandshackman@terion:~$ telnet yuhu.biz 25hackman@terion:~$ telnet yuhu.biz 25Trying 85.14.7.4...Trying 85.14.7.4...Connected to yuhu.biz.Connected to yuhu.biz.Escape character is ^].Escape character is ^].220 blackpearl.yuhu.biz ESMTP Postfix (2.1.1)220 blackpearl.yuhu.biz ESMTP Postfix (2.1.1)HELOHELO501 Syntax: HELO hostname501 Syntax: HELO hostnameHELO yuhu.bizHELO yuhu.biz250 blackpearl.yuhu.biz250 blackpearl.yuhu.biz
  5. 5. SMTP commandsSMTP commandshackman@terion:~$ telnet yuhu.biz 25hackman@terion:~$ telnet yuhu.biz 25Trying 85.14.7.4...Trying 85.14.7.4...Connected to yuhu.biz.Connected to yuhu.biz.Escape character is ^].Escape character is ^].220 blackpearl.yuhu.biz ESMTP Postfix (2.1.1)220 blackpearl.yuhu.biz ESMTP Postfix (2.1.1)EHLO yuhu.bizEHLO yuhu.biz250-blackpearl.yuhu.biz250-blackpearl.yuhu.biz250-PIPELINING250-PIPELINING250-SIZE 30720000250-SIZE 30720000250-VRFY250-VRFY250-ETRN250-ETRN250-STARTTLS250-STARTTLS250-AUTH CRAM-MD5 PLAIN LOGIN DIGEST-MD5250-AUTH CRAM-MD5 PLAIN LOGIN DIGEST-MD5250-AUTH=CRAM-MD5 PLAIN LOGIN DIGEST-MD5250-AUTH=CRAM-MD5 PLAIN LOGIN DIGEST-MD5250 8BITMIME250 8BITMIME
  6. 6. SMTP commandsSMTP commandshackman@terion:~$ telnet yuhu.biz 25hackman@terion:~$ telnet yuhu.biz 25Trying 85.14.7.4...Trying 85.14.7.4...Connected to yuhu.biz.Connected to yuhu.biz.Escape character is ^].Escape character is ^].HELO yuhu.bizHELO yuhu.biz250 blackpearl.yuhu.biz250 blackpearl.yuhu.bizMAIL FROM: mm@yuhu.bizMAIL FROM: mm@yuhu.biz250 Ok250 OkRCPT TO: mm@yuhu.bizRCPT TO: mm@yuhu.biz250 Ok250 OkDATADATA354 End data with <CR><LF>.<CR><LF>354 End data with <CR><LF>.<CR><LF>Subject: testingSubject: testingtest 1test 1..250 Ok: queued as 450D1156263C250 Ok: queued as 450D1156263C
  7. 7. SMTP commandsSMTP commandshackman@terion:~$ telnet yuhu.biz 25hackman@terion:~$ telnet yuhu.biz 25Trying 85.14.7.4...Trying 85.14.7.4...Connected to yuhu.biz.Connected to yuhu.biz.Escape character is ^].Escape character is ^].HELO yuhu.bizHELO yuhu.biz250 blackpearl.yuhu.biz250 blackpearl.yuhu.bizVRFY hackman@yuhu.bizVRFY hackman@yuhu.biz252 hackman@yuhu.biz252 hackman@yuhu.bizVRFY dsadas@yuhu.bizVRFY dsadas@yuhu.biz550 <dsadas@yuhu.biz>: Recipient address550 <dsadas@yuhu.biz>: Recipient addressrejected: User unknown in virtual mailbox tablerejected: User unknown in virtual mailbox tableRSETRSET250 Ok250 Okquitquit221 Bye221 Bye
  8. 8. SMTPSMTP➢ Retry interval, at least 30minRetry interval, at least 30min➢ Give-up time, at least 4-5 daysGive-up time, at least 4-5 days➢ Storage - either Mailbox or MaildirStorage - either Mailbox or Maildir➢ Failover setupFailover setup
  9. 9. SMTPSMTPMailbox vs. MaildirMailbox vs. Maildirmail# ls -1Amail# ls -1ASpamSpammail-trashmail-trashsaved-draftssaved-draftssaved-messagessaved-messagessent-mailsent-mailmail# ls -1Amail# ls -1Acamera/camera/cur/cur/new/new/tmp/tmp/mail# ls -1Amail# ls -1ASpamSpammail-trashmail-trashsaved-draftssaved-draftssaved-messagessaved-messagessent-mailsent-mail
  10. 10. SMTP failoverSMTP failoverIN MX 10 mail.example.com.IN MX 10 mail.example.com.IN MX 20 mail2.example.com.IN MX 20 mail2.example.com.mailmail IN A 123.123.13.11IN A 123.123.13.11mail2mail2 IN A 123.123.13.12IN A 123.123.13.12.13.11.13.11.13.12.13.12
  11. 11. SMTP failoverSMTP failoverIN MX 10 mail.example.com.IN MX 10 mail.example.com.IN MX 20 mail2.example.com.IN MX 20 mail2.example.com.mailmail IN A 123.123.13.11IN A 123.123.13.11mail2mail2 IN A 123.123.13.12IN A 123.123.13.12.13.11.13.11.13.12.13.12
  12. 12. SMTP failoverSMTP failoverIN MX 10 mail.example.com.IN MX 10 mail.example.com.IN MX 20 mail2.example.com.IN MX 20 mail2.example.com.mailmail IN A 123.123.13.11IN A 123.123.13.11mail2mail2 IN A 123.123.13.12IN A 123.123.13.12.13.11.13.11.13.12.13.12
  13. 13. Post Office Protocol - POPPost Office Protocol - POP➢ 1984 – POP1984 – POP - RFC 918- RFC 918➢ 1985 – POP21985 – POP2 - RFC 973- RFC 973➢ 1988 – POP31988 – POP3 - RFC 1081- RFC 1081➢ 1996 – POP31996 – POP3 - RFC 1939- RFC 1939➢ TCP ports 110, 995(SSL)TCP ports 110, 995(SSL)
  14. 14. POP3 commandsPOP3 commands➢ USERUSER➢ PASSPASS➢ LISTLIST➢ STATSTAT➢ UIDLUIDL➢ RETRRETR➢ DELEDELE➢ QUITQUIT➢ Valid replies (+OK)Valid replies (+OK)➢ Negative replies(-ERR)Negative replies(-ERR)➢ Single connectionSingle connection
  15. 15. POP3 commandsPOP3 commandshackman@BlackPearl: ~$ telnet localhost 110hackman@BlackPearl: ~$ telnet localhost 110Trying 127.0.0.1...Trying 127.0.0.1...Connected to 127.0.0.1.Connected to 127.0.0.1.Escape character is ^].Escape character is ^].+OK+OK Dovecot ready.Dovecot ready.USER userX@yuhu.bizUSER userX@yuhu.biz+OK+OKPASS Jer0n1m0!PASS Jer0n1m0!+OK Logged in.+OK Logged in.STATSTAT+OK 1717 21744442+OK 1717 21744442
  16. 16. POP3 commandsPOP3 commandsLISTLIST+OK 1717 messages:+OK 1717 messages:1 84821 84822 808532 808533 330933 330934 55434 5543..........1715 80601715 80601716 65581716 65581717 46151717 4615..RETR 1717RETR 1717___mail message here______mail message here___..DELE 1717DELE 1717+OK Marked to be deleted.+OK Marked to be deleted.
  17. 17. Interactive Message AccessInteractive Message AccessProtocol - IMAPProtocol - IMAP➢ 1988 – IMAP 21988 – IMAP 2 - RFC 1064- RFC 1064➢ 1991 – IMAP 31991 – IMAP 3 - RFC 1203- RFC 1203➢ 2003 – IMAP 42003 – IMAP 4 - RFC 3501- RFC 3501➢ becomes INTERNET MESSAGE ACCESS PROTOCOLbecomes INTERNET MESSAGE ACCESS PROTOCOL➢ 2011 – SRV records – RFC 61862011 – SRV records – RFC 6186➢ 2013 – IMAP 42013 – IMAP 4 - RFC 6858- RFC 6858➢ TCP port 143, 993(SSL)TCP port 143, 993(SSL)
  18. 18. Interactive Message AccessInteractive Message AccessProtocol - IMAPProtocol - IMAP➢ Support multiple connectionsSupport multiple connections➢ Supports foldersSupports folders➢ Support pulling only the headers ofSupport pulling only the headers ofthe e-mail, pull the data on demandthe e-mail, pull the data on demand➢ Support mail PUSH(sending mail)Support mail PUSH(sending mail)
  19. 19. IMAP SRV records - RFC6186IMAP SRV records - RFC6186_submission._tcp.example.com. SRV 0 1 587_submission._tcp.example.com. SRV 0 1 587mail.example.com.mail.example.com._service._proto.name TTL class SRV priority weight port_service._proto.name TTL class SRV priority weight porttargettarget- service: the symbolic name of the desired service.- service: the symbolic name of the desired service.- proto: the transport protocol of the desired service; this is- proto: the transport protocol of the desired service; this isusually either TCP or UDP.usually either TCP or UDP.- name: the domain name for which this record is valid.- name: the domain name for which this record is valid.- TTL: standard DNS time to live field.- TTL: standard DNS time to live field.- class: standard DNS class field (this is always IN).- class: standard DNS class field (this is always IN).- priority: the priority of the target host, lower value means- priority: the priority of the target host, lower value meansmore preferred.more preferred.- weight: A relative weight for records with the same priority.- weight: A relative weight for records with the same priority.- port: the TCP or UDP port on which the service is to be- port: the TCP or UDP port on which the service is to befound.found.- target: the canonical hostname of the machine providing- target: the canonical hostname of the machine providingthe service.the service.
  20. 20. IMAP Basic commandsIMAP Basic commands➢ a001 login USER PASSa001 login USER PASS➢ a001 logouta001 logout➢ a001 select FOLDERa001 select FOLDER➢ a001 list "" *a001 list "" *➢ a001 fetch PARAMa001 fetch PARAM➢ ALL/HEADERS/BODYALL/HEADERS/BODY➢ a001 delete "Message"a001 delete "Message"➢ Valid replies - (a00x OK)Valid replies - (a00x OK)➢ Negative replies - (a00x BAD or NO)Negative replies - (a00x BAD or NO)
  21. 21. IMAPIMAPhackman@BlackPearl: ~$ telnet localhost 143hackman@BlackPearl: ~$ telnet localhost 143Trying 127.0.0.1...Trying 127.0.0.1...Connected to 127.0.0.1.Connected to 127.0.0.1.Escape character is ^].Escape character is ^].* OK* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR[CAPABILITY IMAP4rev1 LITERAL+ SASL-IRLOGIN-REFERRALS ID ENABLE IDLE STARTTLSLOGIN-REFERRALS ID ENABLE IDLE STARTTLSAUTH=PLAIN] Dovecot ready.AUTH=PLAIN] Dovecot ready.a001 login userX@yuhu.biz Jer0n1m0!a001 login userX@yuhu.biz Jer0n1m0!a001 OKa001 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR[CAPABILITY IMAP4rev1 LITERAL+ SASL-IRLOGIN-REFERRALS ID ENABLE IDLE SORTLOGIN-REFERRALS ID ENABLE IDLE SORTSORT=DISPLAY THREAD=REFERENCESSORT=DISPLAY THREAD=REFERENCESTHREAD=REFS MULTIAPPEND UNSELECT CHILDRENTHREAD=REFS MULTIAPPEND UNSELECT CHILDRENNAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1CONDSTORE QRESYNC ESEARCH ESORT SEARCHRESCONDSTORE QRESYNC ESEARCH ESORT SEARCHRESWITHIN CONTEXT=SEARCH LIST-STATUS QUOTA]WITHIN CONTEXT=SEARCH LIST-STATUS QUOTA]Logged inLogged in
  22. 22. IMAPIMAPa002 lista002 lista002 BADa002 BAD Error in IMAP command LIST: InvalidError in IMAP command LIST: Invalidreference.reference.a003 select inboxa003 select inbox* FLAGS (Answered Flagged Deleted Seen Draft* FLAGS (Answered Flagged Deleted Seen Draft$label2)$label2)* OK [PERMANENTFLAGS (Answered Flagged* OK [PERMANENTFLAGS (Answered FlaggedDeleted Seen Draft $label2 *)] Flags permitted.Deleted Seen Draft $label2 *)] Flags permitted.* 1714 EXISTS* 1714 EXISTS* 0 RECENT* 0 RECENT* OK [UIDVALIDITY 1330989345] UIDs valid* OK [UIDVALIDITY 1330989345] UIDs valid* OK [UIDNEXT 59881] Predicted next UID* OK [UIDNEXT 59881] Predicted next UID* OK [HIGHESTMODSEQ 1] Highest* OK [HIGHESTMODSEQ 1] Highesta003 OKa003 OK [READ-WRITE] Select completed.[READ-WRITE] Select completed.
  23. 23. IMAPIMAPa004 list "" *a004 list "" ** LIST (HasNoChildren) "." "Spam"* LIST (HasNoChildren) "." "Spam"* LIST (HasNoChildren) "." "INBOX"* LIST (HasNoChildren) "." "INBOX"a004 OKa004 OK List completed.List completed.a005 FETCH 1:15 ENVELOPEa005 FETCH 1:15 ENVELOPE* 1 FETCH (ENVELOPE ("Thu, 23 May 2013 07:58:06* 1 FETCH (ENVELOPE ("Thu, 23 May 2013 07:58:06+0000" "RE: svn commit: r1484852 - in+0000" "RE: svn commit: r1484852 - in/httpd/httpd/trunk: CHANGES/httpd/httpd/trunk: CHANGESmodules/http/http_filters.c"modules/http/http_filters.c"* 2 FETCH (ENVELOPE ("Thu, 23 May 2013 10:17:56* 2 FETCH (ENVELOPE ("Thu, 23 May 2013 10:17:56+0200" {89}......+0200" {89}............* 15 FETCH* 15 FETCH (ENVELOPE ..........(ENVELOPE ..........a005 OKa005 OK Fetch completed.Fetch completed.
  24. 24. Hypertext Transfer ProtocolHypertext Transfer ProtocolHTTPHTTP➢ 1995 – HTML 2.01995 – HTML 2.0 - RFC 1866- RFC 1866➢ 1996 – HTTP/1.01996 – HTTP/1.0 - RFC 1945- RFC 1945➢ 1997 – HTTP/1.11997 – HTTP/1.1 - RFC 2068- RFC 2068➢ 1999 – HTTP/1.11999 – HTTP/1.1 - RFC 2616- RFC 2616➢ 2012 – STATUS codes – RFC 65852012 – STATUS codes – RFC 6585➢ 1995 – URI1995 – URI - RFC 1808- RFC 1808➢ 2005 – URI2005 – URI - RFC 3986- RFC 3986➢ Uniform Resource Identifier (URI)Uniform Resource Identifier (URI)proto :// userinfo @ host : port / pathproto :// userinfo @ host : port / pathuser : passuser : passuseruser
  25. 25. Hypertext Transfer ProtocolHypertext Transfer ProtocolHTTPHTTP➢ Absolute URI or PathAbsolute URI or Path➢ http://x.com/images/srpr/logo4w.pnghttp://x.com/images/srpr/logo4w.png➢ /images/srpr/logo4w.png/images/srpr/logo4w.png➢ Request methodsRequest methods➢ GETGET➢ POSTPOST➢ HEADHEAD➢ OPTIONSOPTIONS➢ CONNECTCONNECT
  26. 26. Hypertext Transfer ProtocolHypertext Transfer ProtocolHTTPHTTP➢ Request methodsRequest methods➢ GETGET➢ POSTPOST➢ HEADHEAD➢ OPTIONSOPTIONS➢ CONNECTCONNECT
  27. 27. HTTPHTTP➢ Request HeadersRequest Headers➢ HostHost➢ Accept-CharsetAccept-Charset➢ Accept-EncodingAccept-Encoding➢ AuthorizationAuthorization➢ RangeRange➢ RefererReferer➢ User-AgentUser-Agent
  28. 28. HTTP/1.0 vs. HTTP/1.1HTTP/1.0 vs. HTTP/1.1➢ MethodsMethods➢ GETGET➢ HEADHEAD➢ POSTPOST➢ MethodsMethods➢ GETGET➢ HEADHEAD➢ POSTPOST➢ OPTIONSOPTIONS➢ CONNECTCONNECT➢ PUTPUT➢ DELETEDELETE
  29. 29. HTTP/1.0 vs. HTTP/1.1HTTP/1.0 vs. HTTP/1.1➢ HeadersHeaders➢ AuthorizationAuthorization➢ RefererReferer➢ User-AgentUser-Agent➢ HeadersHeaders➢ HostHost➢ Accept-CharsetAccept-Charset➢ Accept-EncodingAccept-Encoding➢ AuthorizationAuthorization➢ RangeRange➢ RefererReferer➢ User-AgentUser-Agent
  30. 30. HTTP/1.0 vs. HTTP/1.1HTTP/1.0 vs. HTTP/1.1hackman@terion:~$ telnet google.com 80hackman@terion:~$ telnet google.com 80Trying 173.194.39.100...Trying 173.194.39.100...Connected to google.com.Connected to google.com.Escape character is ^].Escape character is ^].GET / HTTP/1.0GET / HTTP/1.0HTTP/1.0 302 FoundHTTP/1.0 302 FoundLocation: http://www.google.bg/Location: http://www.google.bg/Cache-Control: privateCache-Control: privateContent-Type: text/html; charset=UTF-8Content-Type: text/html; charset=UTF-8Date: Thu, 06 Jun 2013 08:35:46 GMTDate: Thu, 06 Jun 2013 08:35:46 GMTServer: gwsServer: gwsContent-Length: 218Content-Length: 218Connection closed.Connection closed.
  31. 31. HTTP/1.0 vs. HTTP/1.1HTTP/1.0 vs. HTTP/1.1hackman@terion:~$ telnet google.com 80hackman@terion:~$ telnet google.com 80Trying 173.194.39.99...Trying 173.194.39.99...Connected to google.com.Connected to google.com.Escape character is ^].Escape character is ^].GET / HTTP/1.1GET / HTTP/1.1Host: google.comHost: google.comHTTP/1.1 301 Moved PermanentlyHTTP/1.1 301 Moved PermanentlyLocation: http://www.google.com/Location: http://www.google.com/Content-Type: text/html; charset=UTF-8Content-Type: text/html; charset=UTF-8Date: Thu, 06 Jun 2013 08:36:01 GMTDate: Thu, 06 Jun 2013 08:36:01 GMTExpires: Sat, 06 Jul 2013 08:36:01 GMTExpires: Sat, 06 Jul 2013 08:36:01 GMTCache-Control: public, max-age=2592000Cache-Control: public, max-age=2592000Server: gwsServer: gwsContent-Length: 219Content-Length: 219.......Connection still open............Connection still open.....
  32. 32. HTTP OPTIONSHTTP OPTIONShackman@terion:~$ telnet s1 81hackman@terion:~$ telnet s1 81Trying 192.168.155.100...Trying 192.168.155.100...Connected to s1.Connected to s1.Escape character is ^].Escape character is ^].OPTIONS / HTTP/1.0OPTIONS / HTTP/1.0HTTP/1.1 200 OKHTTP/1.1 200 OKDate: Thu, 06 Jun 2013 15:13:30 GMTDate: Thu, 06 Jun 2013 15:13:30 GMTServer: ApacheServer: ApacheAllow: GET,HEAD,POST,OPTIONSAllow: GET,HEAD,POST,OPTIONSHost-Header: 192fc2e7e50945beb8231a492d6a8024Host-Header: 192fc2e7e50945beb8231a492d6a8024Content-Length: 0Content-Length: 0Connection: closeConnection: closeContent-Type: text/htmlContent-Type: text/html
  33. 33. HTTP/1.0 requestHTTP/1.0 requestRequestRequestResponse and closeResponse and closeTimeoutTimeout
  34. 34. HTTP/1.1 requestHTTP/1.1 requestRequestRequestResponseResponseRequestRequestResponseResponseKeepAliveTimeoutKeepAliveTimeout
  35. 35. HTTPHTTP➢ Request with headerRequest with header➢ Request with cookieRequest with cookie➢ Difference between normal and HEADDifference between normal and HEADrequestsrequests

×