dev-resources.site
for different kinds of informations.
TLS Fingerprint 保護的網站
Published at
8/16/2024
Categories
tls
ja3
fingerprint
curl
Author
codemee
Author
7 person written this
codemee
open
從保哥的臉書貼文看到 OpenAI 網站有特別的保護, 經過推論與驗證後, 發現是使用了 TLS Fingerprint 保護。簡單的來說, HTTPS 協定在真正傳輸資料前會有一段驗證程序, 伺服器端會送出電子憑證讓瀏覽器確認它的確是欲連接網站的伺服器, 而 TLS Fingerprint 則是讓伺服器在驗證程序中從客戶端送過來的設定資料以 JA3 等演算法計算出電子指紋來區別瀏覽器的種類。curl 由於採用了 openssl 程式庫進行驗證程序, 傳送的設定資料和其它瀏覽器明顯都不一樣, 伺服端很容易識別出來。若用 curl 連接 OpenAI 的文章會得到:
$ curl -I https://openai.com/index/introducing-structured-outputs-in-the-api/
HTTP/2 403
....
Python 的 requests 套件也一樣使用了 openssl 程式庫, 所以也會得到同樣的錯誤:
>>> import requests
>>> requests.get('https://openai.com/index/introducing-struc
... tured-outputs-in-the-api/')
<Response [403]>
如果要取得正確的網頁內容, 就要仿照瀏覽器的方式傳送一模一樣的設定資料進行驗證程序, 相關細節可以參考這篇文章。目前已經有善心人士幫我們解決這個問題, 你可以使用修改過不使用 openssl 程式庫的 curl 版本--curl-impersonate:
$ ./curl_safari15_5 -I https://openai.com/index/introducing-structured-outputs-in-the-api/
HTTP/2 200
除了有 curl 指令本身以外, 他也幫你準備好了扮演不同版本的各式瀏覽器的腳本, 像是上例就是假扮 Safari 15.5, 對於伺服器來說, 這個腳本的行為就像是真正的瀏覽器一樣。
如果要使用 Python 取得正確的網頁, 則可以使用 curl_cffi 套件, 他的作用就跟 curl-impersonate 一樣:
>>> from curl_cffi import requests
>>> requests.get('https://openai.com/index/introducing-struc
... tured-outputs-in-the-api/')
<Response [403]>
>>> r = requests.get('https://openai.com/index/introducing-s
... tructured-outputs-in-the-api/', impersonate="edge101")
>>> r.status_code
200
加上 impersonate 引數就可以指定要扮演的瀏覽器, 正確取回網頁內容了。
curl Article's
30 articles in total
How to Ignore cURL SSL Errors
read article
How to Use cURL to Download Files?
read article
Unlocking the Power of cURL Set Headers for Web Development
read article
The Essential Guide to cURL Set Headers for Developers
read article
What is HTTP 405 Error? (Method Not Allowed)
read article
Boost Your Network Control with Curl SOCKS5 Proxies
read article
How to Use cURL GET Requests
read article
Unlock Efficient IP Management with Curl Proxy
read article
How Does Curl Work and Enhance File Transfers Across Platforms
read article
How Does Curl Work to Simplify Data Transfers and Testing
read article
cURL vs Wget: Key Differences Explained
read article
How to Make DELETE Requests Using the curl_init() Function in PHP
read article
Using htmlq to filter web data
read article
Harder HTB: Using only the terminal
read article
Vault CLI in Containers
read article
How to Route cURL Requests Through a Proxy Server
read article
TLS Fingerprint 保護的網站
currently reading
Manage Telegram Webhooks Using curl
read article
Introducing CurlDock: Simplify API Testing with Docker and Curl
read article
CURL - All methods and Usage ✅
read article
uploading to s3 with bash
read article
Curl on FTP
read article
Build your own curl in Golang
read article
Build Your Own curl - Rust
read article
Download file using curl
read article
How to Use cURL For Web Scraping
read article
Maintain a Healthy Sense of Caution Whenever Running a `curl|bash` Command
read article
How to Use a Proxy in PHP with cURL
read article
Curl: Redirect output to file
read article
How to use cURL in PHP
read article
Featured ones: