Topic 02
Topic 02
Topic 02
DNS, HTTP
What happens when you type a URL and press
enter?
2
Domain Name System (DNS)
3
DNS
demo.com
171.40.230.105
4
How does the "DNS server" work?
Root Nameserver
demo.com
demo.com? “.com”
Nameserver
See “demo.com” NS
171.40.230.105
“demo.com”
Nameserver
5
What happens when you type a URL and press
enter?
1. Client asks DNS Recursive Resolver to lookup a hostname (demo.com).
2. DNS Recursive Resolver sends DNS query to Root Nameserver
• Root Nameserver responds with IP address of TLD Nameserver (".com" Nameserver)
3. DNS Recursive Resolver sends DNS query to TLD Nameserver
• TLD Nameserver responds with IP address of Domain Nameserver (“demo.com"
Nameserver)
4. DNS Recursive Resolver sends DNS query to Domain Nameserver
• Domain Nameserver is authoritative, so replies with server IP address.
5. DNS Recursive Resolver finally responds to Client, sending server IP
address (171.40.230.105)
6
DNS + HTTP
DNS
Recursive
Resolver
HTTP Request
Client Server
171.40.230.105
HTTP Response
7
Attacks on DNS ?
………………………………………………………
8
DNS hijacking
• Motivation
• Phishing
• Revenue through ads, cryptocurrency mining, etc.
9
DNS hijacking
Hijacked
DNS
Resolver
Malicious
Server
8.8.8.8
Client
Server
171.40.230.105
10
DNS hijacking vectors
11
12
DNS privacy
13
14
HTTP
What
happens
when you
…
type a URL
and press
enter?
15
HTTP
Request
Client Server
Response
16
Demo: Make an HTTP request
curl https://twitter.com
curl https://twitter.com > twitter.html
open twitter.html
17
HTTP request
GET / H T T P / 1 . 1
Host: twitter.com
User-Agent: Mozilla/5.0 . . .
18
HTTP response
HTTP/1.1 200 OK
Content-Length: 9001
19
HTTP
20
HTTP is stateless?
21
HTTP Status Codes
22
HTTP Success Codes
23
Range Request
GET /video.mp4
HTTP/1.1 Range:
bytes=1000-1499
Response
HTTP/1.1 206 Partial Content
Content-Range: bytes 1000-1499/1000000
24
HTTP Redirection Codes
25
HTTP Client Error Codes
26
HTTP Server Error Codes
27
HTTP with a proxy server
Request Request
Client Proxy Server
Response Response
28
HTTP proxy servers
29
HTTP request (…)
GET / H T T P / 1 . 1
Host: example.com
User-Agent: Mozilla/5.0 . . .
30
HTTP headers
• Let the client and the server pass additional information with an
HTTP request or response
• Essentially a map of key-value pairs
• Allow experimental extensions to HTTP without requiring protocol
changes
31
Useful HTTP request headers
32
Useful HTTP request headers (…)
33
Make an HTTP request with headers
34
Useful HTTP response headers (…)
35
Useful HTTP response headers (…)
36
37
Demo: Implement an HTTP client
• Not magic!
• Steps:
• Open a TCP socket
• Send HTTP request text over the socket
• Read the HTTP response text from the socket
38
Demo: Implement an HTTP client
import socket
while True:
data = sock.recv(4096)
if not data:
break
print(data.decode(), end='')
sock.close()
39
What happens when you type a URL and press
enter?
1. Perform a DNS lookup on the hostname (example.com) to get an IP address
(1.2.3.4)
2. Open a TCP socket to 1.2.3.4 on port 80 (the HTTP port)
3. Send an HTTP request that includes the desired path (/)
4. Read the HTTP response from the socket
5. Parse the HTML into the DOM
6. Render the page based on the DOM
7. Repeat until all external resources are loaded:
• If there are pending external resources, make HTTP requests for these (run steps 1-4)
• Render the resources into the page
40
example.com DNS Recursive NS
NS
Resolver NS
171.200.216.205
GET /
200 OK, <!doctype html …
41
Self-study
• Reading
• An overview of HTTP
https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
• A typical HTTP session
https://developer.mozilla.org/en-US/docs/Web/HTTP/Session
• HTTP headers
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
42