gpt4 book ai didi

Powershell WebClient 放弃遇到 SNI 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:51 24 4
gpt4 key购买 nike

有没有人找到一种方法来强制 Powershell TLS 客户端不使用 SNI,或者在服务器出现 SNI 错误后继续连接?

我正在尝试让一个 powershell 脚本从我们的 DHCP 服务器下载一个大的网络列表,并将其格式化以导入到另一个系统。

我可以使用浏览器下载数据 - 观察与 Wireshark 的连接,我看到浏览器开始 TLS 握手,发送 SNI 指示,服务器响应“TLS 警报(级别:警告,描述:无法识别的名称) ",浏览器继续使用 TLS 连接,下载成功。

为了调试请求,我通过本地代理(burp 套件,它是一个 Java 应用程序)运行连接,因此我可以看到加密隧道和 HTTP 请求的内容。这导致连接失败并且代理立即返回错误。显然,Java TLS 代码不愿意继续连接浏览器从容应对的 TLS 错误。如果我强制代理不在请求中包含服务器名称标识 (SNI),它会起作用(请参阅下面注释掉的调试代码)。

最后,从混合中删除代理,似乎 Powershell 使用的网络代码也不愿意继续过去的错误 - 它发送相同的 SNI 指示符,接收相同的 TLS 错误,然后挂起 - 不再有数据包交换直到 100 秒过去,然后连接用 FIN 数据包关闭,Powershells 返回超时错误:

使用“2”个参数调用“DownloadFile”时出现异常:“操作已超时”

我使用的代码是这样的:

$webclient = new-object System.Net.WebClient

#DEBUG for now - send requests through proxy

#$proxy = new-object System.Net.WebProxy
#$proxy.Address = "http://localhost:8080"
#$webclient.proxy = $proxy

# have to do this to ignore invalid certs from proxy
#[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

#Also have to force the JRE running the proxy to not send SNI in the request - invoke as
#java -Djsse.enableSNIExtension=false -jar c:\Users\MarkS\Burp\burpsuite_pro_v1.6.09.jar

#end DEBUG

$server = $(
$input = Read-Host "server to connect to [our-DHCP-server-name]"
if($input) {$input} else {"our-DHCP-server-name"}
)

$current_id = [Environment]::Username
$user_id = $(
$input = Read-Host "user ID to connect as [$current_id]"
if($input) {$input} else {$current_id}
)

$password = Read-Host -AsSecureString 'password to connect with'

$pscreds = new-object System.Management.Automation.PSCredential($user_id,$password)
$webclient.Credentials = new-object System.Net.NetworkCredential($user_id, $pscreds.GetNetworkCredential().Password)

#connect...

$tempfile = [System.IO.Path]::GetTempFileName()
$tempfile

#...and download
#NOTE - don't use XML - server returns badly malformed XML
$url = "https://$server/wapi/v1.2.1/network?_max_results=10000000&_return_type=json-pretty&_return_fields%2B=extattrs"


$webclient.DownloadFile($url, $tempfile)

非常感谢!

最佳答案

我有一个解决方案。更多的解决方法恰好对我有用;它仍然不是通用解决方案。

添加:

[System.Net.ServicePointManager]::SecurityProtocol = 'Ssl3'

在连接尝试之前将强制客户端仅使用 SSLv3(此服务器配置为支持),这会阻止 SNI 发挥作用,因为它是一个仅限 TLS 的功能。

当然,这对尝试连接到仅支持 TLS 的服务器的任何人都没有帮助,而且只要我们的服务器仍然支持 SSLv3,它只会对我有帮助...

关于Powershell WebClient 放弃遇到 SNI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27449975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com