Lukáš Bařinka
© 2021
REV 2.10
HyperText Markup Language
<!DOCTYPE
html
represents whole documenttitle
), language, encoding, keywords, description, stylesheet<!DOCTYPE
html
reprezentuje celý dokumenttitle
), jazyk, kódování, klíčová slova, popis, použitý styl zobrazení
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML 4.01 Transitional</title>
</head>
<body>
…
<a href="http://www.example.com">
<img src="link.gif" alt="Link na www.example.com">
</a>
…
</body>
</html>
XHTML is XML version of HTML
XHTML je XML verze jazyka HTML
<!DOCTYPE
at the beginning<?xml encoding=""?>
is expected <!DOCTYPE
jako první<?xml encoding=""?>
se předpokládá
<?xml version="1.0" encoding="iso-8859-2"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
URL
= Uniform Resource Locator
URI
URI
= Uniform Resource Identifier
IRI
= Internationalized Resource Identifier
URI
URL
= Uniform Resource Locator
URI
URI
= Uniform Resource Identifier
IRI
= Internationalized Resource Identifier
URI
URL
in HTTP
scheme can contain #fragment
URL
according to RFC
URL
can safely contain (without encoding) only
0-9a-zA-Z
$-_.+!*'()
%xx
xx
character code is according to ISO 8859-1
HTTP
může URL
obsahovat #fragment
URL
podle RFC
0-9a-zA-Z
$-_.+!*'()
%xx
kód je podle ISO 8859-1
<>"#%{}[]|\^~`
;/?:@=&
URL
<>"#%{}[]|\^~`
;/?:@=&
Char | Code |
---|---|
Znak | Kód |
& | %2B |
: | %3A |
= | %3D |
@ | %40 |
Char | Code |
---|---|
Znak | Kód |
/ | %2F |
; | %3B |
? | %3F |
␣ | %20 |
HyperText Transfer Protocol
HTTPS = encrypted version used for secure communication HTTP + SSL/TLS
HTTPS = šifrovaná verze protokolu HTTP + SSL/TLS
Host:
header in every request Ability to use virtual "servers" – virtual hostsConnection: close
to terminate connectionExpect: 100-continue
and response 100 Continue
Usually ignoredCache-Control
Host:
u každého požadavku Možnost používat virtuální „servery“ – virtual hostsConnection: close
při ukončení spojeníExpect: 100-continue
a odpovědi 100 Continue
Obvykle se ignorujeCache-Control
ping
Discover IP address, connection test (ICMP)
Zjištění IP adresy, kontrola spojení (ICMP)
nslookup
, dig
Domain information (from DNS)
Informace o doméně (z DNS)
telnet
Interactive network communication
Interaktivní síťová komunikace
nc
net-cat TCP+UDP communication (easy for scripting)
net-cat TCP+UDP komunikace (dobře se skriptuje)
ping
Discover IP address, connection test (ICMP)
Zjištění IP adresy, kontrola spojení (ICMP)
ping www.google.com
PING www.google.com (172.217.23.196) 56(84) bytes of data.
64 bytes from prg03s05-in-f196.1e100.net (172.217.23.196): icmp_seq=1 ttl=115 time=6.90 ms
64 bytes from prg03s05-in-f4.1e100.net (172.217.23.196): icmp_seq=2 ttl=115 time=2.71 ms
64 bytes from prg03s05-in-f196.1e100.net (172.217.23.196): icmp_seq=3 ttl=115 time=3.05 ms
nslookup
Domain information (from DNS)
Informace o doméně (z DNS)
nslookup www.google.com
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer:
Name: www.google.com
Address: 172.217.23.196
Name: www.google.com
Address: 2a00:1450:4014:80c::2004
dig
Domain information (from DNS)
Informace o doméně (z DNS)
dig www.google.com
; <<>> DiG 9.16.13-Debian <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46672
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 8
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 260 IN A 172.217.23.196
;; AUTHORITY SECTION:
google.com. 313231 IN NS ns3.google.com.
google.com. 313231 IN NS ns2.google.com.
google.com. 313231 IN NS ns1.google.com.
google.com. 313231 IN NS ns4.google.com.
;; ADDITIONAL SECTION:
ns2.google.com. 144507 IN A 216.239.34.10
ns2.google.com. 203036 IN AAAA 2001:4860:4802:34::a
ns3.google.com. 144507 IN A 216.239.36.10
ns3.google.com. 174240 IN AAAA 2001:4860:4802:36::a
ns1.google.com. 144507 IN A 216.239.32.10
ns4.google.com. 144507 IN A 216.239.38.10
ns4.google.com. 174240 IN AAAA 2001:4860:4802:38::a
;; Query time: 108 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Ne dub 04 20:05:37 CEST 2021
;; MSG SIZE rcvd: 279
telnet
Interactive network communication
telnet www.google.com 80
Trying 172.217.23.196...
Connected to www.google.com.
Escape character is '^]'.
GET / HTTP/1.0↵
↵
HTTP/1.0 200 OK
Date: Sun, 04 Apr 2021 18:12:56 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=212=Tuyy…; expires=Mon, …; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
<!doctype html><html …
nc
net-cat TCP+UDP communication (easy for scripting)-C
to use CR+LF as a newline
net-cat TCP+UDP komunikace (dobře se skriptuje)-C
odesílá jako konce řádků CR+LF
nc -C www.google.com 80
GET / HTTP/1.0↵
↵
HTTP/1.0 200 OK
…
printf '%s\r\n' "GET / HTTP/1.0" "" | nc www.google.com 80
HTTP/1.0 200 OK
…
nc www.google.com 80 <<REQ
> GET / HTTP/1.0^M
> ^M
> REQ
HTTP/1.0 200 OK
…
Press CTRL
+V
followed by Enter
to input CR
character (^M
)
Stiskněte CTRL
+V
a Enter
pro vložení znaku CR
(^M
)
curl
Tool for URL manipulation (no redirect by default, -L
)
Nástroj pro práci s URL (standardně neřeší přesměrování, -L
)
wget
Download data from web server (redirect by default)
Stahování dat z webu (řeší přesměrování)
ab
Apache benchmark - performance statistics
Apache benchmark - statistiky výkonu
Server must implement GET and HEAD methods, other methods are optional.
Server musí podporovat metody GET a HEAD, ostatní metody volitelně.
1xx
- Informational Request received, processing continues2xx
- Success Request was successfully received, understood, and accepted3xx
- Redirection Further action needs to be taken by the user agent in order to fulfill the request4xx
- Client Error Client seems to have erred (incorrect syntax, permissions, …)5xx
- Server Error Server is aware that it has erred or is incapable of performing the requestUnrecognized status code must be interpreted as x00
Pokud klient některému kódu nerozumí,
považuje jej za kód x00
nc
nc -C www.google.com 80
GET / HTTP/1.0↵
↵
telnet
telnet www.google.com 80
Trying 172.217.23.196...
Connected to www.google.com.
Escape character is '^]'.
GET / HTTP/1.0↵
↵
HTTP/1.0 200 OK
Date: Mon, 05 Apr 2021 07:35:04 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=212=4LgD…; expires=Tue, … GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="cs"><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
The charset is specified in HTTP header (ISO-8859-1 [ISO Latin 1]) and in HTML header (UTF-8) as well. The HTTP header information takes precendece over content information.
V HTTP hlavičce je uvedeno kódování ISO-8859-1 (ISO Latin 1) a v HTML hlavičce pak UTF-8. Platí informace z HTTP, skutečně je kódování ISO Latin 1.
Host
header must be ignoredHost
header field, the host is determined by the Host
header400 Bad Request
error messageHost
header field, the server may attempt to use heuristics E.g., examination of the URI path for something unique to a particular host/
Host
ignorovat a použít název hostitele z URIHost
, použije název hostitele z hlavičky400 Bad Request
Host
, může se pokusit určit hostitele jinak/
nc -C www.sony.com 80 <<REQ
GET / HTTP/1.0
User-Agent: netcat
REQ
HTTP/1.0 400 Bad Request
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 209
Expires: Mon, 05 Apr 2021 08:40:16 GMT
Date: Mon, 05 Apr 2021 08:40:16 GMT
Connection: close
<HTML><HEAD>
<TITLE>Invalid URL</TITLE>…
nc -C www.sony.com 80 <<REQ
GET http://www.sony.com/ HTTP/1.0
User-Agent: netcat
REQ
HTTP/1.0 302 Moved Temporarily
Server: AkamaiGHost
Content-Length: 0
Location: http://www.sony.com/en/
…
Host:
header It works (Host
here is optional but thanks to that it works)
HTTP/1.0 s hlavičkou Host:
Funguje (Host
hlavička je nepovinná, ale díky ní to funguje)
nc -C www.sony.com 80 <<REQ
GET / HTTP/1.0
Host: www.sony.com
User-Agent: netcat
REQ
HTTP/1.0 302 Moved Temporarily
Server: AkamaiGHost
Content-Length: 0
Location: http://www.sony.com/en/
…
Host:
header It works according to this mandatory Host
header
HTTP/1.1 s hlavičkou Host:
Funguje podle adresy
nc -C www.sony.com 80 <<REQ
GET / HTTP/1.1
Host: www.sony.cz
User-Agent: netcat
REQ
HTTP/1.1 301 Moved Permanently
Server: AkamaiGHost
Content-Length: 0
Location: https://www.sony.cz/
…
http://www.sony.com (HTTP/1.1) → http://www.sony.com/en/ (HTTP/1.1) → https://www.sony.com/en/ (HTTP/2)
curl -sL -i http://www.sony.com
HTTP/1.1 302 Moved Temporarily
Server: AkamaiGHost
Content-Length: 0
Location: http://www.sony.com/en/
…
HTTP/1.1 301 Moved Permanently
Server: AkamaiGHost
Content-Length: 0
Location: https://www.sony.com/en/
…
HTTP/2 200
accept-ranges: bytes
content-type: text/html
last-modified: Wed, 31 Mar 2021 15:51:55 GMT
server: Apache
content-length: 121443
…
<!DOCTYPE html>
<html lang="en">
…
-i
= include headers
-s
= silent (no progress bar)
-L
= location redirect
nc 51.75.147.44 3128 <<REQ
GET http://www.google.com/ HTTP/1.0
REQ
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Mon, 05 Apr 2021 09:51:55 GMT
Content-Type: text/html; charset=ISO-8859-1
Connection: close
Expires: -1
Cache-Control: private, max-age=0
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=212=NhTY…; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
<!doctype html><html … lang="de"><head>
Proxy-Authorization
header with login credentials when proxy server requires authenticationBasic base64(user:pass)
echo -n 'lukas:secretpassword' | base64
bHVrYXM6c2VjcmV0cGFzc3dvcmQ=
Proxy-Autorization: Basic bHVrYXM6c2VjcmV0cGFzc3dvcmQ=
base64 -d <<< 'bHVrYXM6c2VjcmV0cGFzc3dvcmQ='
lukas:secretpassword
Proxy-Authorization
s přihlašovacími údajiBasic base64(user:pass)
echo -n 'lukas:tajneheslo' | base64
bHVrYXM6dGFqbmVoZXNsbw==
Proxy-Autorization: Basic bHVrYXM6dGFqbmVoZXNsbw==
base64 -d <<< 'bHVrYXM6dGFqbmVoZXNsbw=='
lukas:tajneheslo
Transfer-Encoding: chunked
Transfer-Encoding: chunked
nc www.google.com 80 <<REQ
> GET / HTTP/1.1
> Host: www.google.com
> Connection: Close
>
> REQ
HTTP/1.1 200 OK
Date: Mon, 05 Apr 2021 11:30:32 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=212=Fr7p …; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
51ef
<!doctype html><html … }},ea=da(1
f9
),fa=da(2);p("sb",ea);p … ;ia=c
6e70
+1},ja=[],ia=0;p("logger",{ … ;})();</script> </body></html>
0
If-Modified-Since
) or partial (byte range, Range
)* part of REST (Representational State Transfer)
* součást REST (Representational State Transfer)
*
"), the request is intended to apply to the server in general (ping)*
, jedná se o spíš o ping, než žádost o informaceAllowMethods
(mod_allowmethods
) Except TRACE method
<Location />
AllowMethods GET POST OPTIONS
</Location>
TraceEnable
(core
)
TraceEnable on
AllowMethods
(mod_allowmethods
) Kromě metody TRACE
<Location />
AllowMethods GET POST OPTIONS
</Location>
TraceEnable
(core
)
TraceEnable on
OPTIONS / HTTP/1.0
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2011 15:01:38 GMT
Server: Apache
Allow: GET,HEAD,POST,OPTIONS
Content-Length: 0
Connection: close
Content-Type: text/html
TRACE / HTTP/1.0
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2011 15:28:09 GMT
Server: Apache
Connection: close
Content-Type: message/http
TRACE / HTTP/1.0
The goal is to get familiar with basic network tools and tools to communicate using HTTP. It is good to use different tools; ones from low-level up to hi-level (web browser). You will use those tool during this course as well as in real life.
Cílem je vyzkoušet základní síťové nástroje a nástroje pro HTTP komunikaci. Je dobré se postupně seznámit s různými nástroji, od nejnižší úrovně až po webový prohlížeč. Tyto nástroje se vám budou hodit v celém kurzu i v praxi.
systemctl start service
systemctl stop service
apache2-test
lsof -i tcp
Port 80 = http, Port 8080 = http-alt
systemctl start service
systemctl stop service
apache2-test
lsof -i tcp
Port 80 = http, Port 8080 = http-alt
8080
TCP port8080
TCP port8080
8080
firefox
)
CTRL+R
, CTRL+SHIFT+R
wget
curl
nc
telnet
firefox
)wget
curl
nc
telnet
firefox
, wget
, and curl
toolscurl
, nc
, and telnet
tools
Warning! Chunk encoding is supported in HTTP/1.1 only
curl
and nc
tools
Header Range: bytes=79-99
firefox
, wget
, curl
curl
, nc
a telnet
Pozor, chunk encoding je podporován pouze v HTTP/1.1
curl
a nc
Hlavička Range: bytes=79-99
POST
method to /echo
URI
Data "a=10
" and "b=text
" as URI parameters
Text "hello
" as request body (5 bytes)
/etc/issue
file using PUT
method with /upload/issue
address
curl -X PUT --data-binary @/etc/issue …
POST
na /echo
URI
Data "a=10
" a "b=text
" jako parametry v URI
Text "hello
" v těle požadavku (5 B)
PUT
nahrajte na server soubor /etc/issue
pod adresou /upload/issue
curl -X PUT --data-binary @/etc/issue …
TRACE
method and see full responseTRACE
pošlete libovolný požadavek na server podívejte se na odpověď