顯示具有 HTTP/2 標籤的文章。 顯示所有文章
顯示具有 HTTP/2 標籤的文章。 顯示所有文章

2025年6月13日 星期五

[研究]HTTP/2中間設備支援疑問

[研究]HTTP/2中間設備支援疑問

2025-06-13

確認  Web Server  支援也啟用了 HTTP/2,那瀏覽器從 Internet 連到 Web Server 經過的 Router, Switch Hub, Load Balancer, Mail SPAM, WAF, ... 等設備是否都要支援 HTTP/2 才能使用 HTTP/2 連線 ?

ChatGPT 說:

不需要所有設備都支援 HTTP/2,才能從瀏覽器成功建立 HTTP/2 連線到 Web Server。實際上,只要中間設備不會干擾或破壞 HTTP/2 的協定特性,即使它們本身不具備 HTTP/2 的特性,也仍然可以讓 HTTP/2 正常運作。

以下是詳細說明:

✅ 需支援 HTTP/2 的條件:

  • Client(瀏覽器):必須支援 HTTP/2,目前主流瀏覽器(Chrome、Edge、Firefox、Safari)都支援。
  • Web Server(含 HTTPS):必須啟用 HTTP/2。多數情況下 HTTP/2 需要搭配 TLS(HTTPS)才能在瀏覽器中啟用。

❗ 中間設備(Router, Switch, Load Balancer, WAF, Mail SPAM...)需考慮的點:

設備類型是否需支援 HTTP/2說明
Router / Switch / 普通 Hub❌ 不需支援屬於 L2/L3 層,只要不進行 L7 應用層封包解析,就不會影響 HTTP/2 傳輸。
Load Balancer(負載平衡器)⚠️ 視模式而定- 若是 L4 負載平衡(例如 TCP 層轉送),不需理解 HTTP/2,無須支援。
- 若是 L7 負載平衡(例如根據 URI 轉導),必須能正確處理 HTTP/2 封包。
WAF(Web Application Firewall)⚠️ 視支援度而定- 若 WAF 不支援 HTTP/2,會降級或拒絕連線。
- 若支援,則能正常轉發 HTTP/2。
Spam/Mail Gateway❌ 不相關它處理的是電子郵件(SMTP),和 HTTP/2 沒有關聯。
TLS Termination Proxy(終止 TLS 的設備)✅ 必須支援因為 HTTP/2 通常跑在 TLS 上,如果 TLS 終止設備無法理解 HTTP/2,就只能降級為 HTTP/1.1。


✅ 總結結論:

  • 只有處理到 L7 應用層、TLS Termination、或 做協定解包分析的設備(例如 WAF、L7 Load Balancer)需要支援或容忍 HTTP/2。
  • 只做封包轉發或路由的設備(Router/Switch)不需要支援 HTTP/2,只要它們不阻擋或修改封包即可。
  • 若任何中間設備(例如老舊 WAF)阻擋、修改、降級 HTTP/2 連線,瀏覽器會自動降級為 HTTP/1.1。

(完)


2025年6月12日 星期四

[研究]h2spec 2.6.0(HTTP/2 協定符合性測試工具)試用

[研究]h2spec 2.6.0(HTTP/2 協定符合性測試工具)試用

2025-06-12

h2spec官方網站,h2spec v2.6.0 於 2020-08-04 釋出

https://github.com/summerwind/h2spec

下載

https://github.com/summerwind/h2spec/releases

h2spec_windows_amd64.zip 

實際使用,預設不會告訴你有那些參數

C:\h2spec_windows_amd64>h2spec.exe
Generic tests for HTTP/2 server
  1. Starting HTTP/2
    × 1: Sends a client connection preface

Error: dial tcp 127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.

C:\h2spec_windows_amd64>

實際使用,拿 www.hinet.net 試驗一下

-t:執行所有測試(包含 HTTP/2 要求與錯誤處理)

-k:忽略 TLS 憑證錯誤(對測試 staging/dev 伺服器很實用)

-p 443:指定 HTTPS 連接埠

-h:目標主機(可以是 domain 或 IP)

C:\h2spec_windows_amd64>h2spec.exe -t -k -p 443 -h www.hinet.net
Generic tests for HTTP/2 server
  1. Starting HTTP/2
    ✔ 1: Sends a client connection preface

  2. Streams and Multiplexing
    ✔ 1: Sends a PRIORITY frame on idle stream
    ✔ 2: Sends a WINDOW_UPDATE frame on half-closed (remote) stream
    ✔ 3: Sends a PRIORITY frame on half-closed (remote) stream
    ✔ 4: Sends a RST_STREAM frame on half-closed (remote) stream
    ✔ 5: Sends a PRIORITY frame on closed stream

  3. Frame Definitions
    3.1. DATA
      ✔ 1: Sends a DATA frame
      ✔ 2: Sends multiple DATA frames
      ✔ 3: Sends a DATA frame with padding

    3.2. HEADERS
      ✔ 1: Sends a HEADERS frame
      ✔ 2: Sends a HEADERS frame with padding
      ✔ 3: Sends a HEADERS frame with priority

    3.3. PRIORITY
      ✔ 1: Sends a PRIORITY frame with priority 1
      ✔ 2: Sends a PRIORITY frame with priority 256
      ✔ 3: Sends a PRIORITY frame with stream dependency
      ✔ 4: Sends a PRIORITY frame with exclusive
      ✔ 5: Sends a PRIORITY frame for an idle stream, then send a HEADER frame for a lower stream ID

    3.4. RST_STREAM
      ✔ 1: Sends a RST_STREAM frame

    3.5. SETTINGS
      ✔ 1: Sends a SETTINGS frame

    3.7. PING
      ✔ 1: Sends a PING frame

    3.8. GOAWAY
      ✔ 1: Sends a GOAWAY frame

    3.9. WINDOW_UPDATE
      ✔ 1: Sends a WINDOW_UPDATE frame with stream ID 0
      ✔ 2: Sends a WINDOW_UPDATE frame with stream ID 1

    3.10. CONTINUATION
      ✔ 1: Sends a CONTINUATION frame
      ✔ 2: Sends multiple CONTINUATION frames

  4. HTTP Message Exchanges
    ✔ 1: Sends a GET request
    ✔ 2: Sends a HEAD request
    ✔ 3: Sends a POST request
    using source address 10.3.121.11:52517m
    × 4: Sends a POST request with trailers
      -> The endpoint MUST respond to the request.
         Expected: HEADERS Frame (stream_id:1)
           Actual: Connection closed

  5. HPACK
    ✔ 1: Sends a indexed header field representation
    ✔ 2: Sends a literal header field with incremental indexing - indexed name
    ✔ 3: Sends a literal header field with incremental indexing - indexed name (with Huffman coding)
    ✔ 4: Sends a literal header field with incremental indexing - new name
    ✔ 5: Sends a literal header field with incremental indexing - new name (with Huffman coding)
    ✔ 6: Sends a literal header field without indexing - indexed name
    ✔ 7: Sends a literal header field without indexing - indexed name (with Huffman coding)
    ✔ 8: Sends a literal header field without indexing - new name
    ✔ 9: Sends a literal header field without indexing - new name (huffman encoded)
    ✔ 10: Sends a literal header field never indexed - indexed name
    ✔ 11: Sends a literal header field never indexed - indexed name (huffman encoded)
    ✔ 12: Sends a literal header field never indexed - new name
    ✔ 13: Sends a literal header field never indexed - new name (huffman encoded)
    ✔ 14: Sends a dynamic table size update
    ✔ 15: Sends multiple dynamic table size update

Hypertext Transfer Protocol Version 2 (HTTP/2)
  3. Starting HTTP/2
    3.5. HTTP/2 Connection Preface
      ✔ 1: Sends client connection preface
      ✔ 2: Sends invalid connection preface

  4. HTTP Frames
    4.1. Frame Format
      ✔ 1: Sends a frame with unknown type
      ✔ 2: Sends a frame with undefined flag
      ✔ 3: Sends a frame with reserved field bit

    4.2. Frame Size
        1: Sends a DATA frame with 2^14 octets in length

訊息太多了,敝人只是想簡單知道 Web Server 目前提供支援的 HTTP 版本。

(完)

2025年6月10日 星期二

[研究]相同 ASP.NET WebForm 網站,走 HTTPS,本機測 HTTP/2,Internet 測 HTTP/1.1

[研究]同一個 ASP.NET WebForm 網站,走 HTTPS,本機測 HTTP/2,Internet 測 HTTP/1.1

2025-06-10

Windows Server 2019 Standard + IIS + ASP.NET + WebForm + HTTPS (不提供 HTTP)





********************************************************************************

ChatGPT 說:

1. IIS 支援 HTTP/2,但可能經過中間設備或未正確協商
若你從外部透過以下途徑連線網站,有可能協議被降級:
  • 防火牆 / Proxy / SSL Offloading
  • CDN(Cloudflare、Azure Front Door、F5 等)
  • 負載平衡器 / Application Gateway
這些中介設備有些支援 HTTP/2、有些僅支援 HTTP/1.1,有些會對外說 HTTP/2,但與後端 IIS 通訊仍為 HTTP/1.1。

使用 curl -I --http2 https://你的網址 看實際協定協商狀況。

2. ALPN 協商失敗
HTTP/2 的協商是透過 TLS 擴展的 ALPN(Application-Layer Protocol Negotiation)完成的。若:
  • 客戶端不支援 ALPN(例如:老版本 curl)
  • TLS 設定過舊
  • Cipher Suite 不支援
則會退回 HTTP/1.1。

********************************************************************************

kali :Linux 測試沒發現 WAF,但實際是有過 WAF 的。

┌──(kali㉿kali)-[~]
└─$ wafw00f https://(遮蔽)/

                 ?              ,.   (   .      )        .      "
         __        ??          ("     )  )'     ,'        )  . (`     '`
    (___()'`;   ???          .; )  ' (( (" )    ;(,     ((  (  ;)  "  )")
    /,___ /`                 _"., ,._'_.,)_(..,( . )_  _' )_') (. _..( ' )
    \\   \\                 |____|____|____|____|____|____|____|____|____|

                                ~ WAFW00F : v2.3.1 ~
                    ~ Sniffing Web Application Firewalls since 2014 ~

[*] Checking https://(遮蔽)/
[+] Generic Detection results:
[-] No WAF detected by the generic detection
[~] Number of requests: 7
                                                                             
┌──(kali㉿kali)-[~]
└─$ 




(完)

[研究]Windows Server 2019 + IIS + ASP.NET 的 Web Server 如何啟用 HTTP/2

[研究]Windows Server 2019 + IIS + ASP.NET 的 Web Server 如何啟用 HTTP/2

2025-06-09

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19

********************************************************************************

Windows Server 2019 + IIS + ASP.NET 的 Web Server 如何啟用 HTTP/2

ChatGPT 說:

在 Windows Server 2019 + IIS + ASP.NET 環境中啟用 HTTP/2,可以透過以下步驟進行設定。Windows Server 2019 的 IIS(版本 10.0)預設已支援 HTTP/2,只要使用的是 HTTPS(TLS)連線即可啟用。

1. 確認系統與 IIS 條件

  • Windows Server 2016或更新版本
  • IIS 10.0 或以上 ✔️
  • 已安裝 HTTPS 憑證(TLS/SSL) ✔️
  • HTTP/2 在 IIS 中只適用於 HTTPS,不支援純 HTTP 連線。
  • ASP.NET 應用無需額外修改支援 HTTP/2,由 IIS 處理協定層。

2. 檢查 IIS 是否已啟用 HTTP/2

IIS 10 on Windows Server 2019 預設開啟 HTTP/2

(下圖) FireFox可判斷是否是 HTTP/2


(下圖) FireFox + Windows Serer 2019 IIS + ASP.NET WebForm 測試


(下圖) Chrome 目前版本好像無法判斷是否是 HTTP/2



(下圖) curl 發現是自簽憑證,無法判斷是否是 HTTP/2


┌──(kali㉿kali)-[~]
└─$ curl -I https://192.168.128.131/         
curl: (35) GnuTLS, handshake failed: Key usage violation in certificate has been detected.
                                                                             
┌──(kali㉿kali)-[~]
└─$ curl -I https://192.168.128.131/default.htm
curl: (35) GnuTLS, handshake failed: Key usage violation in certificate has been detected.
                                                                             
┌──(kali㉿kali)-[~]
└─$ curl -I -k https://192.168.128.131/        
curl: (35) GnuTLS, handshake failed: Key usage violation in certificate has been detected.
                                                                             
┌──(kali㉿kali)-[~]
└─$ 


********************************************************************************

補充:

手動確認或修改 IIS 是否啟動 HTTP/2:

A. 開啟登錄編輯器:

Win + R → 輸入 regedit

B. 瀏覽至:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS\Parameters

C. 檢查或建立以下 DWORD 值:

EnableHttp2    值設為 1(啟用)

EnableHttp2Cleartext    值設為 0(禁用 HTTP/2 over HTTP)

如果這些鍵不存在,可以手動新增:

名稱 類型 數值

EnableHttp2 DWORD (32-bit) 1

EnableHttp2Cleartext DWORD (32-bit) 0

修改後,重新啟動 HTTP 服務或整台伺服器:

iisreset

3. 確認 HTTPS 綁定

請確認你已在 IIS 管理員中:

為網站設定了有效的 SSL 憑證。

在網站的綁定設定中使用 HTTPS + 對應的 Port(通常是 443)。


(完)

相關



2025年6月9日 星期一

[研究]Web Server 支援 HTTP/2 的條件?

[研究]Web Server 支援 HTTP/2 的條件? 

2025-06-09

ChatGPT 說:

Web Server 要支援 HTTP/2,需滿足以下條件:

🔧 一、Web Server 軟體本身要支援 HTTP/2

常見支援 HTTP/2 的 Web Server:

Web ServerHTTP/2 支援情況
Apache (httpd)自 2.4.17 起支援(需啟用 mod_http2)
Nginx自 1.9.5 起支援(需使用 OpenSSL 1.0.2+)
IIS自 Windows Server 2016 / Windows 10 起內建支援
LiteSpeed支援
Caddy預設支援
Tomcat需搭配 HTTP/2 upgrade handler 或 proxy 使用

📜 二、使用的 TLS/SSL 憑證(HTTPS)

  • 雖然 HTTP/2 在標準中不強制使用 TLS(即 HTTPS),但幾乎所有主要瀏覽器 都只在 HTTPS 連線上啟用 HTTP/2。
  • 所以:部署 HTTPS 是實務上啟用 HTTP/2 的必要條件。

🔗 三、OpenSSL 或類似加密函式庫版本(伺服器端)

某些 Web Server 需要依賴 OpenSSL,HTTP/2 支援需 OpenSSL 版本為:

  • 最低需 OpenSSL 1.0.2
  • 更佳為 OpenSSL 1.1.1 或 OpenSSL 3.x

⚙️ 四、瀏覽器與客戶端支援

  • 大部分現代瀏覽器(Chrome, Firefox, Edge, Safari)都支援 HTTP/2。
  • 但若用戶端不支援,伺服器會自動回退到 HTTP/1.1。
  • 敝人補充:詳見 https://caniuse.com/http2

✅ 五、伺服器設定是否有正確啟用 HTTP/2

例如:

  • Apache: 需加入 Protocols h2 http/1.1 並載入 mod_http2
  • Nginx: listen 443 ssl http2;
  • IIS: 只需確保是 Windows 10/Server 2016 以上版本,並啟用 HTTP/2

🧪 六、驗證方式

可以使用以下方式確認是否成功啟用 HTTP/2:

(完)

[研究]curl檢測HTTP/2

[研究]curl檢測HTTP/2

2025-06-09

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19

********************************************************************************

Rocky Linux 9.5

[root@localhost ~]# curl --version
curl 7.76.1 (x86_64-redhat-linux-gnu) libcurl/7.76.1 OpenSSL/3.2.2 zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.1 (+libidn2/2.3.0) libssh/0.10.4/openssl/zlib nghttp2/1.43.0
Release-Date: 2021-04-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
[root@localhost ~]# 

實際測試

[root@localhost ~]# curl --http2 -I https://www.google.com
HTTP/2 200 
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-ga9b8uHP7ceHEfCj8jv6_g' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
accept-ch: Sec-CH-Prefers-Color-Scheme
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
date: Mon, 09 Jun 2025 02:03:34 GMT
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
expires: Mon, 09 Jun 2025 02:03:34 GMT
cache-control: private
set-cookie: AEC=AVh_V2gfgkYCKISRWird9OU6SF1DejA9SVueWn_2ZCWmbLz7CT3gqkADUwo; expires=Sat, 06-Dec-2025 02:03:34 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
set-cookie: NID=524=nyA2xsX3MvlZfj3A2zFxdpXMe6u2YEd5HPht_oMx0aFfi57DLiz-DUHObv-FSWlI2EJqAHnEQ7vuJwtE_DeGrWXCeDmwEZ4Xs_YRU28J-RYGj3p4WFceIHLt19YcNpr8uPwO-uOzk1w5mXX_6WE76UYmAQP8vjTyeqOg9FnJ-Za2n38Ysj4hurWofK7G0hX2FqY53F6u4MGYXJA; expires=Tue, 09-Dec-2025 02:03:34 GMT; path=/; domain=.google.com; HttpOnly
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

[root@localhost ~]# 


實際測試

[root@localhost ~]# curl --http2 -I https://www.hinet.net
HTTP/2 403 
server: HiNetCDN
date: Mon, 09 Jun 2025 02:05:46 GMT
content-type: text/plain
content-length: 10
x-request-id: 6723b1b39de9f1c01bb75b84c4dccd8d
x-cache: RULE

[root@localhost ~]# 


Windows Server 2019繁體中文標準版,不支援 HTTP/2檢查

C:\>curl --version
curl 8.9.1 (Windows) libcurl/8.9.1 Schannel zlib/1.3 WinIDN
Release-Date: 2024-07-31
Protocols: dict file ftp ftps http https imap imaps ipfs ipns mqtt pop3 pop3s smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets

C:\>


Windows Server 2025繁體中文標準版,不支援 HTTP/2檢查

C:\>curl --version
curl 8.12.1 (Windows) libcurl/8.12.1 Schannel zlib/1.3 WinIDN
Release-Date: 2025-02-13
Protocols: dict file ftp ftps http https imap imaps ipfs ipns mqtt pop3 pop3s smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets

C:\>

Kali 2025.1c 支援 HTTP/2檢查

[root@localhost ~]# 
┌──(kali㉿kali)-[~]
└─$ curl --version
curl 8.12.1 (x86_64-pc-linux-gnu) libcurl/8.12.1 GnuTLS/3.8.9 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.2 libssh2/1.11.1 nghttp2/1.64.0 ngtcp2/1.9.1 nghttp3/1.6.0 librtmp/2.3 OpenLDAP/2.6.9
Release-Date: 2025-02-13, security patched: 8.12.1-2
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
                                                                             
┌──(kali㉿kali)-[~]
└─$ 


Kali 2025.1c 的 curl 檢測 Windows Server 2025 的 IIS 10.0 安裝自簽憑證

┌──(kali㉿kali)-[~]
└─$ curl --http2 -I https://192.168.128.144/
curl: (60) server verification failed: certificate signer not trusted. (CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none)
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the webpage mentioned above.
                                                                             
┌──(kali㉿kali)-[~]
└─$ curl --http2 -I http://192.168.128.144/ 
HTTP/1.1 200 OK
Content-Length: 703
Content-Type: text/html
Last-Modified: Mon, 09 Jun 2025 03:51:03 GMT
Accept-Ranges: bytes
ETag: "8bc6eab8f1d8db1:0"
Server: Microsoft-IIS/10.0
Date: Mon, 09 Jun 2025 03:58:13 GMT

                                                                             
┌──(kali㉿kali)-[~]
└─$ 


Kali 2025.1c 的 curl 檢測 Windows Server 2025 的 IIS 10.0 安裝自簽憑證

┌──(kali㉿kali)-[~]
└─$ curl --http2 -I -k https://192.168.128.131/        
curl: (35) GnuTLS, handshake failed: Key usage violation in certificate has been detected.
                                                                                                        
┌──(kali㉿kali)-[~]
└─$

Windows Server 2025 的 IIS 10.0 改用正式憑證,Kali Linux 的 /etc/hosts 中設定網址和 IP 對應;

Win + R → 輸入 regedit

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters

新增:

名稱 類型 數值

EnableHttp2 DWORD (32-bit) 1

命令提示字元(系統管理員)執行 iisreset

┌──(kali㉿kali)-[~]
└─$ curl --http2 -I -k https://(遮蔽)/ 
HTTP/2 200 
content-length: 703
content-type: text/html
last-modified: Mon, 09 Jun 2025 07:49:53 GMT
accept-ranges: bytes
etag: "af791a1613d9db1:0"
server: Microsoft-IIS/10.0
date: Mon, 09 Jun 2025 08:19:21 GMT

                                                                                                        
┌──(kali㉿kali)-[~]
└─$ 


(完)

相關