Skip to content

Instantly share code, notes, and snippets.

@ZEBAS204
Created February 26, 2024 03:22
Show Gist options
  • Save ZEBAS204/a484fed7f6eab53c84bedd5c610cca23 to your computer and use it in GitHub Desktop.
Save ZEBAS204/a484fed7f6eab53c84bedd5c610cca23 to your computer and use it in GitHub Desktop.
Automatically update the firewall rules to bypass adobe license checks
;;;===,,,@echo off
;;;===,,,findstr /v "^;;;===,,," "%~f0" > "%~dp0ps.ps1"
;;;===,,,PowerShell.exe -ExecutionPolicy Bypass -Command "& '%~dp0ps.ps1'"
;;;===,,,del /s /q "%~dp0ps.ps1" >NUL 2>&1
;;;===,,,pause
<#
This script uses the gist of @omeganoob (https://gist.github.com/omeganoob/8b917cd900d6032b8e9ff3acf495c5db)
to automatically parse the IPs and update the Windows Firewall's Outbound Rules of "Adobe Unlicensed Pop-up"
that's automatically generated when installing any adobe builds of our favorite russian guy.
Also, this script automatically enables this firewall rule in case somehow it was disabled.
Note: this script DOES NOT replace the current blocked IPs, instead it adds the new ones, this means that
any unused IP will not be removed.
#>
param (
[switch]
[Parameter()]
$Elevated
)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
Write-Host 'This script needs administrator rights.'
if ($Elevated) {
Write-Host 'Failed to elevate privileges, aborting.'
} else {
Start-Process powershell.exe -Wait -Verb RunAs -ArgumentList ('-ExecutionPolicy ByPass -noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit
}
Read-Host 'Press any key to exit...'
exit
}
# *****************************
# * Actual script starts here *
# *****************************
$FirewallRuleName = 'Adobe Unlicensed Pop-up'
$DownloadFileName = 'adobe_hosts' # used to point to, any name allowed
$GithubRawDownloadURI = 'https://gist.github.com/omeganoob/8b917cd900d6032b8e9ff3acf495c5db/raw/adobe_hosts'
$UsingPlaceholderIP = $false
if (-not $(Get-NetFirewallRule -DisplayName $FirewallRuleName) 2>$null)
{
Write-Host "The outbound firewall rule named '$FirewallRuleName' does not exist.`nThis script specifically targets that rule."
$addFirewallRule = (Read-Host -Prompt 'Do you want to create it? (Y/N)') -eq 'y'
if ($addFirewallRule)
{
Write-Host "Creating rule '$FirewallRuleName'...`n"
# 203.0.113.0/24 is a placeholder IP (TEST-NET-3)
New-NetFirewallRule -DisplayName $FirewallRuleName -Direction Outbound -Action Block -RemoteAddress "203.0.113.0" -Enabled False
$UsingPlaceholderIP = $true
}
else
{
Read-Host "Exiting...`nPress any key to exit..."
exit
}
}
function Get-File
{
param (
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.Uri]
$Uri,
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]
$TargetFile,
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[Int32]
$BufferSize = 1,
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[ValidateSet('KB, MB')]
[String]
$BufferUnit = 'MB',
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[ValidateSet('KB, MB')]
[Int32]
$Timeout = 10000
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5) -and ((Get-Service -Name BITS).StartType -ne [System.ServiceProcess.ServiceStartMode]::Disabled)
if ($useBitTransfer)
{
Write-Information -MessageData 'Using a fallback BitTransfer method since you are running Windows PowerShell'
Start-BitsTransfer -Source $Uri -Destination "$($TargetFile.FullName)"
}
else
{
$request = [System.Net.HttpWebRequest]::Create($Uri)
$request.set_Timeout($Timeout) #15 second timeout
$response = $request.GetResponse()
$totalLength = [System.Math]::Floor($response.get_ContentLength() / 1024)
$responseStream = $response.GetResponseStream()
$targetStream = New-Object -TypeName ([System.IO.FileStream]) -ArgumentList "$($TargetFile.FullName)", Create
switch ($BufferUnit)
{
'KB' { $BufferSize = $BufferSize * 1024 }
'MB' { $BufferSize = $BufferSize * 1024 * 1024 }
Default { $BufferSize = 1024 * 1024 }
}
Write-Verbose -Message "Buffer size: $BufferSize B ($($BufferSize/("1$BufferUnit")) $BufferUnit)"
$buffer = New-Object byte[] $BufferSize
$count = $responseStream.Read($buffer, 0, $buffer.length)
$downloadedBytes = $count
$downloadedFileName = $Uri -split '/' | Select-Object -Last 1
while ($count -gt 0)
{
$targetStream.Write($buffer, 0, $count)
$count = $responseStream.Read($buffer, 0, $buffer.length)
$downloadedBytes = $downloadedBytes + $count
Write-Progress -Activity "Downloading file '$downloadedFileName'" -Status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes / 1024)) / $totalLength) * 100)
}
Write-Progress -Activity "Finished downloading file '$downloadedFileName'"
$targetStream.Flush()
$targetStream.Close()
$targetStream.Dispose()
$responseStream.Dispose()
}
}
# Set current directory to TEMP
Push-Location -LiteralPath $env:TEMP
try
{
# Unique directory name based on time
New-Item -Type Directory -Name "AdobeLicenseFirewall-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" |
Convert-Path |
Set-Location
}
catch
{
Write-Output $_
Read-Host "Error creating temp folder.`nPress any key to exit..."
exit
}
Write-Host 'Downloading the latest host file, please wait...'
try
{
$filePath = Join-Path -Path $PWD -ChildPath $DownloadFileName
Get-File -Uri $GithubRawDownloadURI -TargetFile $filePath
}
catch
{
Write-Output $_
Read-Host "Error while downloading host file.`nPress any key to exit..."
exit
}
function Add-Ips
{
$regexIPAddress = '^0\.0\.0\.0\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
$firewallIps = (Get-NetFirewallRule -DisplayName $FirewallRuleName | Get-NetFirewallAddressFilter ).RemoteAddress
write-verbose "Firewall IPs:`n '$firewallIps'"
$newIPs = @()
$addIPs = @()
Select-String -Path $DownloadFileName -Pattern $regexIPAddress | ForEach-Object { $newIPs += @($_.Matches.Groups[1].Value) }
if ($UsingPlaceholderIP)
{
write-verbose 'Removing placeholder IP 203.0.113.0'
$addIPs = $newIPs | Select-Object -Unique | Sort-Object
}
else
{
$addIPs = $($firewallIps; $newIPs) | Select-Object -Unique | Sort-Object
}
write-host "Adding new ips:`n'$newIPs'"
write-verbose "Final IP string:`n '$addIPs'"
Set-NetFirewallRule -DisplayName $FirewallRuleName -RemoteAddress $addIPs
}
Add-Ips
# Always enable firewall rule
Enable-NetFirewallRule -DisplayName $FirewallRuleName
Read-Host "`nDone.`nPress any key to exit..."
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment