Command-Line

如何使用 OpenBSD 基礎工具從網站獲取 HTTPS 響應?

  • March 4, 2022

使用類似curlwget很容易“獲取” HTTP GET 請求的響應的工具,但是預設情況下這兩個工具都沒有安裝在 OpenBSD 上,並且編寫一個可移植的 shell 腳本,不能假設它們安裝在另一台機器上。

我想要一種“安全”的方式來使用預設安裝的工具將伺服器響應(例如 wikipedia.org )發送到我的終端安全意味著響應不應該是明文,而是在到達我的機器的途中使用 HTTP/2 和 TLS 1.3/TLS 1.2(當然,如果伺服器支持)等目前標準加密。

您無需指定是否需要標頭、響應程式碼或有關 TLS 協議的細節。

正如已經回答的那樣,您可以使用ftp. -d打開開關為您提供ftp了一些有關 HTTP(S) 級別的資訊:

$ ftp -d -o /dev/null https://en.wikipedia.org
host en.wikipedia.org, port https, path , save as /dev/null, auth none.
Trying 91.198.174.192...
Requesting https://en.wikipedia.org
GET / HTTP/1.1
Connection: close
Host: en.wikipedia.org
User-Agent: OpenBSD ftp

received 'HTTP/1.1 301 Moved Permanently'
received 'Date: Thu, 03 Mar 2022 10:42:56 GMT'
received 'Server: mw1324.eqiad.wmnet'
received 'X-Content-Type-Options: nosniff'
received 'P3p: CP="See https://en.wikipedia.org/wiki/Special:CentralAutoLogin/P3P for more info."'
received 'Vary: Accept-Encoding,X-Forwarded-Proto,Cookie,Authorization'
received 'Cache-Control: s-maxage=1200, must-revalidate, max-age=0'
received 'Last-Modified: Thu, 03 Mar 2022 10:42:56 GMT'
received 'Location: https://en.wikipedia.org/wiki/Main_Page'
Redirected to https://en.wikipedia.org/wiki/Main_Page
host en.wikipedia.org, port https, path wiki/Main_Page, save as /dev/null, auth none.
Trying 91.198.174.192...
Requesting https://en.wikipedia.org/wiki/Main_Page
GET /wiki/Main_Page HTTP/1.1
Connection: close
Host: en.wikipedia.org
User-Agent: OpenBSD ftp

received 'HTTP/1.1 200 OK'
received 'Date: Thu, 03 Mar 2022 07:48:57 GMT'
received 'Server: mw1393.eqiad.wmnet'
received 'X-Content-Type-Options: nosniff'
received 'P3p: CP="See https://en.wikipedia.org/wiki/Special:CentralAutoLogin/P3P for more info."'
received 'Content-Language: en'
received 'Vary: Accept-Encoding,Cookie,Authorization'
received 'Last-Modified: Thu, 03 Mar 2022 07:48:56 GMT'
received 'Content-Type: text/html; charset=UTF-8'
received 'Age: 11005'
received 'X-Cache: cp3052 hit, cp3058 hit/120231'
received 'X-Cache-Status: hit-front'
received 'Server-Timing: cache;desc="hit-front", host;desc="cp3058"'
received 'Strict-Transport-Security: max-age=106384710; includeSubDomains; preload'
received 'Report-To: { "group": "wm_nel", "max_age": 86400, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }'
received 'NEL: { "report_to": "wm_nel", "max_age": 86400, "failure_fraction": 0.05, "success_fraction": 0.0}'
received 'Permissions-Policy: interest-cohort=()'
received 'Set-Cookie: WMF-Last-Access=03-Mar-2022;Path=/;HttpOnly;secure;Expires=Mon, 04 Apr 2022 00:00:00 GMT'
received 'Set-Cookie: WMF-Last-Access-Global=03-Mar-2022;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Mon, 04 Apr 2022 00:00:00 GMT'
received 'X-Client-IP: 148.69.164.57'
received 'Cache-Control: private, s-maxage=0, max-age=0, must-revalidate'
received 'Set-Cookie: GeoIP=PT:06:Coimbra:40.21:-8.42:v4; Path=/; secure; Domain=.wikipedia.org'
received 'Accept-Ranges: bytes'
received 'Content-Length: 84542'
received 'Connection: close'
100% |*******************************************************************************************************************************************************| 84542       00:00
84542 bytes received in 0.22 seconds (368.47 KB/s)

有關 TLS 的更多具體資訊,我會使用openssl,它也在基本系統上:

$ openssl s_client -connect en.wikipedia.org:443 < /dev/null

(...)

New, TLSv1/SSLv3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 256 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
   Protocol  : TLSv1.3
   Cipher    : TLS_AES_256_GCM_SHA384
   Session-ID:
   Session-ID-ctx:
   Master-Key:
   Start Time: 1646305125
   Timeout   : 7200 (sec)
   Verify return code: 0 (ok)
---
DONE

引用自:https://unix.stackexchange.com/questions/691632