PowerShell下载Google Drive公开文件脚本失效:如何绕过确认
如何通过PowerShell下载公开Google Drive文件并执行?
问题背景
原本用于下载DNS Filter的.msi安装文件的PowerShell脚本已失效,原因是Google Drive在2023年11月至2024年1月期间调整了公开可执行文件的下载机制。此前通过&confirm=t参数可自动绕过病毒扫描确认提示,但现在执行脚本会下载到包含病毒扫描警告的HTML页面,而非目标.msi文件。
原失效脚本片段:
#DNS Filter Variables # $dnspath = "C:\Program Files\dnsfilter.msi"; # $dnsurl = "https://drive.google.com/uc?export=download&id=1NE0W0-zDEejLjxUSVEAK5ZPx2sDGeRIZ&confirm=t"; Set-ExecutionPolicy Unrestricted -Scope CurrentUser Write-Output "Downloading current DNS Filter file" Invoke-RestMethod -uri $dnsurl -OutFile $dnspath
解决方案
现在需要先获取Google Drive返回的警告页面,解析其中的动态下载参数,再发起实际下载请求。修改后的脚本如下:
# DNS Filter 配置 $dnspath = "C:\Program Files\dnsfilter.msi" $dnsurl = "https://drive.google.com/uc?export=download&id=1NE0W0-zDEejLjxUSVEAK5ZPx2sDGeRIZ" # 设置执行策略(强制跳过确认) Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force # 获取病毒扫描警告页面 Write-Output "获取下载确认信息" $htmlContent = Invoke-RestMethod -Uri $dnsurl # 解析页面中的下载表单 $downloadForm = $htmlContent | Select-Xml -XPath "//form[@id='download-form']" | Select-Object -ExpandProperty Node $actualDownloadUrl = $downloadForm.action $formParameters = @{} # 提取表单中的所有参数(包括动态生成的uuid) $downloadForm.input | ForEach-Object { if ($_.name) { $formParameters[$_.name] = $_.value } } # 发起实际下载请求 Write-Output "开始下载DNS Filter安装文件" Invoke-RestMethod -Uri $actualDownloadUrl -OutFile $dnspath -Body $formParameters -Method Get
原理说明
Google Drive现在对公开的可执行文件强制要求通过带有动态生成的uuid参数的链接下载,静态的confirm=t参数已无法绕过警告。修改后的脚本会:
- 先请求原UC地址,获取包含警告提示的HTML页面
- 解析页面中的下载表单,提取实际下载地址和所有必要参数(包括动态uuid)
- 使用这些参数发起请求,直接获取目标.msi文件
内容的提问来源于stack exchange,提问作者Dustin1280
相关产品推荐
相关产品推荐

