簡體   English   中英

HTTPS 通過squid代理使用Curl請求

[英]HTTPS request using Curl through squid proxy

我正在嘗試通過魷魚代理使用 Curl 發出 HTTPS 請求。 我知道 squid 代理可以工作,因為我已經為我的瀏覽器設置了它並且工作正常。 我已經嘗試使用這里的幾乎所有答案並搜索了其他幾個網站,但沒有任何結果。

一些示例搜索和結果:1) 使用內聯基本身份驗證: curl -x https://user:pass@host:port https://www.google.com -v

結果: Establish HTTP proxy tunnel to www.google.com:443 Proxy auth using Basic with user 'username' CONNECT www.google.com:443 HTTP/1.1 Host: www.google.com:443 Proxy-Authorization: Basic abaskldfja1fiopweifj= User-Agent: curl/7.47.0 Proxy-Connection: Keep-Alive Recv failure: Connection reset by peer Received HTTP code 0 from proxy after CONNECT Closing connection 0 curl: (56) Recv failure: Connection reset by peer

2)使用環境變量( https_proxyhttp_proxy ):相同的結果

3) 將憑據放入參數中: curl -x https://host:port https://www.google.com -v --proxy-user user:pass :結果相同

關於我可能做錯了什么的任何猜測?

您沒有提供足夠的信息來確定您遇到問題的原因。

例如:

你的squid https代理是怎么配置的? 代理是在 splice 還是 bump 模式下運行?

您絕對確定您的代理正在工作嗎?

您是否嘗試通過 http 或 https 連接到任何其他網站?

他們是否設置了任何其他代理身份驗證選項? 限制IP地址可以使用代理? 您配置了什么身份驗證選項? 它在沒有啟用身份驗證的情況下工作嗎?

對於它的價值,出於我自己的原因,我需要做同樣的事情。 我首先在“拼接所有”模式下配置代理,結果僅顯示標題:

$ curl -x 10.10.1.1:3128 -I https://www.google.com/
HTTP/1.1 200 Connection established

HTTP/2 200
content-type: text/html; charset=ISO-8859-1
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
date: Mon, 04 Apr 2022 12:14:56 GMT
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
expires: Mon, 04 Apr 2022 12:14:56 GMT
cache-control: private
[snip]

接下來,我將代理配置為“拼接白名單,否則碰撞”模式並再次嘗試:

# curl -x 10.10.1.1:3128 -I https://www.google.com/
HTTP/1.1 200 Connection established

curl: (60) SSL certificate problem: self signed certificate in certificate chain
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 web page mentioned above.

這是預料之中的。

使用 -k 選項允許它工作(忽略證書錯誤):

# curl -x 10.10.1.1:3128 -I https://www.google.com/ -k
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Mon, 04 Apr 2022 12:34:21 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Expires: Mon, 04 Apr 2022 12:34:21 GMT
Cache-Control: private
[snip]

或使用 https 代理設置中定義的證書:

$ curl -x 10.10.1.1:3128 --cacert ~/test/my-MITM.crt -I https://www.google.com/
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Mon, 04 Apr 2022 12:35:06 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Expires: Mon, 04 Apr 2022 12:35:06 GMT
Cache-Control: private
[snip]

接下來,我啟用了身份驗證(仍然處於顛簸模式,忽略證書錯誤)並且它不喜歡那樣,正如預期的那樣

$ curl -x 10.10.1.1:3128 -k -I https://www.google.com/
HTTP/1.1 407 Proxy Authentication Required
Server: squid/4.15
Mime-Version: 1.0
Date: Mon, 04 Apr 2022 12:40:46 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3532
X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
Proxy-Authenticate: Basic realm="Please enter your credentials to access the proxy"
X-Cache: MISS from pfsense
X-Cache-Lookup: NONE from pfsense:3128
Via: 1.1 pfsense (squid/4.15)
Connection: keep-alive

curl: (56) Received HTTP code 407 from proxy after CONNECT

因此,讓我們嘗試進行身份驗證:

$ curl -x hello:world@10.10.1.1:3128 -k -I https://www.google.com/
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Mon, 04 Apr 2022 12:43:09 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Expires: Mon, 04 Apr 2022 12:43:09 GMT
Cache-Control: private
[snip]

我們很好。

由於您的錯誤與我所看到的不符,我想我會再嘗試一次練習。 我沒有將協議指定為代理服務器定義的一部分,而是將其添加到:

$ curl -x https://hello:world@10.10.1.1:3128 -k -I https://www.google.com/
curl: (35) error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number

啊。 有趣的。 讓我們了解一些細節:

$ curl -x https://hello:world@10.10.1.1:3128 -k -I https://www.google.com/ -v
*   Trying 10.10.1.1...
* TCP_NODELAY set
* Connected to 10.10.1.1 (10.10.1.1) port 3128 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number
* Closing connection 0
curl: (35) error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number

這看起來更接近你的錯誤。

最終測試,為代理服務器指定 http 而不是 https

$ curl -x http://hello:world@10.10.1.1:3128 -k -I https://www.google.com/
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Mon, 04 Apr 2022 12:51:27 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Expires: Mon, 04 Apr 2022 12:51:27 GMT
Cache-Control: private
[snip]

你有它,這對我來說已經足夠了。

我在這里猜測,但看起來如果您將協議指定為代理字符串的一部分,它將嘗試使用該協議與代理服務器通信。 所以使用 http://,或者像我做原創作品那樣不指定它就好了,但是一旦我說 https:...☠️☠️☠️

我希望這對任何對這一點瑣事感興趣的人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM