156 lines
6.6 KiB
Batchfile
156 lines
6.6 KiB
Batchfile
@echo off & setlocal enableextensions
|
|
title Reset AnyDesk (patched)
|
|
|
|
reg query HKEY_USERS\S-1-5-19 >NUL 2>&1 || (echo Please run as administrator.& pause >NUL & exit /b 1)
|
|
chcp 437 >NUL
|
|
|
|
echo ============================================================
|
|
echo WARNING:
|
|
echo - This script will change your MAC. In dynamic IPs there is
|
|
echo no issues but if you have static IP and is bound to your
|
|
echo MAC you might lose internet connection.
|
|
echo - All passwords saved for AnyDesk sessions will be lost.
|
|
echo ============================================================
|
|
echo.
|
|
choice /M "Continue"
|
|
if errorlevel 2 exit /b 0
|
|
echo.
|
|
|
|
set "PD=%ALLUSERSPROFILE%\AnyDesk"
|
|
set "AD=%APPDATA%\AnyDesk"
|
|
set "AnyDesk1=%SystemDrive%\Program Files (x86)\AnyDesk\AnyDesk.exe"
|
|
set "AnyDesk2=%SystemDrive%\Program Files\AnyDesk\AnyDesk.exe"
|
|
|
|
echo [*] Stopping AnyDesk service and process...
|
|
call :stop_any
|
|
|
|
echo [*] Backing up user.conf and thumbnails to %%TEMP%%...
|
|
if exist "%AD%\user.conf" copy /y "%AD%\user.conf" "%temp%\user.conf" >NUL
|
|
rd /s /q "%temp%\ad_thumbnails" 2>NUL
|
|
if exist "%AD%\thumbnails" xcopy /c /e /h /r /y /i /k "%AD%\thumbnails" "%temp%\ad_thumbnails" >NUL
|
|
|
|
echo [*] Waiting for AnyDesk lock files to release...
|
|
set /a _i=0
|
|
:wait_locks
|
|
set "_locked="
|
|
for %%F in ("%PD%\service.conf.lock" "%PD%\system.conf.lock" "%AD%\user.conf.lock") do (
|
|
2>NUL (>>%%F echo.) || set "_locked=1"
|
|
)
|
|
if defined _locked (
|
|
set /a _i+=1
|
|
if %_i% lss 10 ( timeout /t 1 /nobreak >NUL & goto wait_locks )
|
|
)
|
|
|
|
echo [*] Wiping AnyDesk config folders...
|
|
rd /s /q "%PD%" 2>NUL
|
|
rd /s /q "%AD%" 2>NUL
|
|
|
|
echo [*] Removing AnyDesk registry fingerprint (if present)...
|
|
reg delete "HKLM\SOFTWARE\philandro Software GmbH\AnyDesk" /f >NUL 2>&1
|
|
|
|
call :randomize_mac
|
|
|
|
echo [*] Waiting 10s for network to reconnect...
|
|
timeout /t 10 /nobreak >NUL
|
|
|
|
echo [*] Starting AnyDesk to generate a new ID...
|
|
call :start_any
|
|
|
|
echo [*] Waiting for AnyDesk to obtain a new ID...
|
|
set /a _j=0
|
|
:lic
|
|
timeout /t 2 /nobreak >NUL
|
|
if exist "%PD%\system.conf" findstr /C:"ad.anynet.id=" "%PD%\system.conf" >NUL && goto got_id
|
|
set /a _j+=1
|
|
if %_j% lss 30 goto lic
|
|
echo.
|
|
echo [!] Timed out waiting for a new AnyDesk ID.
|
|
echo Check internet connectivity and firewall (*.net.anydesk.com).
|
|
echo.
|
|
pause
|
|
goto :eof
|
|
|
|
:got_id
|
|
for /f "tokens=2 delims==" %%A in ('findstr /C:"ad.anynet.id=" "%PD%\system.conf"') do set "NEWID=%%A"
|
|
echo [*] New ID obtained: %NEWID%
|
|
echo [*] Stopping AnyDesk to restore user settings...
|
|
call :stop_any
|
|
|
|
echo [*] Restoring user.conf and thumbnails...
|
|
if exist "%temp%\user.conf" (
|
|
if not exist "%AD%" mkdir "%AD%"
|
|
move /y "%temp%\user.conf" "%AD%\user.conf" >NUL
|
|
)
|
|
if exist "%temp%\ad_thumbnails" (
|
|
xcopy /c /e /h /r /y /i /k "%temp%\ad_thumbnails" "%AD%\thumbnails" >NUL
|
|
rd /s /q "%temp%\ad_thumbnails"
|
|
)
|
|
|
|
echo [*] Starting AnyDesk...
|
|
call :start_any
|
|
|
|
echo.
|
|
echo ============================================================
|
|
echo Script is finished. You can continue using AnyDesk.
|
|
echo New AnyDesk ID: %NEWID%
|
|
echo ============================================================
|
|
echo.
|
|
pause
|
|
goto :eof
|
|
|
|
:start_any
|
|
sc start AnyDesk >NUL 2>&1
|
|
if %errorlevel%==1056 goto :sa_launch
|
|
if %errorlevel%==0 goto :sa_launch
|
|
timeout /t 1 /nobreak >NUL
|
|
goto start_any
|
|
:sa_launch
|
|
if exist "%AnyDesk1%" start "" "%AnyDesk1%"
|
|
if exist "%AnyDesk2%" start "" "%AnyDesk2%"
|
|
exit /b
|
|
|
|
:randomize_mac
|
|
echo [*] Randomizing MAC on internet-facing adapter(s)...
|
|
set "PS1=%temp%\ad_mac_%RANDOM%.ps1"
|
|
> "%PS1%" echo $ErrorActionPreference = 'Continue'
|
|
>>"%PS1%" echo $base = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}'
|
|
>>"%PS1%" echo $excl = 'Hyper-V','VMware','VirtualBox','Virtual Adapter','Loopback','TAP','TUN','WAN Miniport','Bluetooth','Npcap','WireGuard','OpenVPN','Wintun','WSL','Docker','Pseudo-Interface'
|
|
>>"%PS1%" echo $gwIfs = (Get-NetRoute -DestinationPrefix '0.0.0.0/0' -ErrorAction SilentlyContinue ^| Sort-Object RouteMetric ^| Select-Object -ExpandProperty ifIndex -Unique)
|
|
>>"%PS1%" echo $cands = Get-NetAdapter -Physical ^| Where-Object { $_.Status -eq 'Up' -and $_.HardwareInterface -eq $true -and ($_.MediaType -eq '802.3' -or $_.MediaType -eq 'Native 802.11') }
|
|
>>"%PS1%" echo $cands = $cands ^| Where-Object { $desc = $_.InterfaceDescription; -not ($excl ^| Where-Object { $desc -like "*$_*" }) }
|
|
>>"%PS1%" echo $cands = $cands ^| Where-Object { $gwIfs -contains $_.ifIndex }
|
|
>>"%PS1%" echo if (-not $cands) { Write-Host '[!] No internet-facing physical adapter found (Wi-Fi/Ethernet with default gateway). Skipping MAC change.'; exit 0 }
|
|
>>"%PS1%" echo foreach ($a in $cands) {
|
|
>>"%PS1%" echo Write-Host ('[+] Target adapter: ' + $a.Name + ' (' + $a.InterfaceDescription + ') current MAC: ' + $a.MacAddress)
|
|
>>"%PS1%" echo $first = '{0:X2}' -f ((Get-Random -Minimum 0 -Maximum 64) * 4 -bor 2)
|
|
>>"%PS1%" echo $rest = -join (1..5 ^| ForEach-Object { '{0:X2}' -f (Get-Random -Minimum 0 -Maximum 256) })
|
|
>>"%PS1%" echo $mac = $first + $rest
|
|
>>"%PS1%" echo $pretty = ($mac -replace '(..)(?!$)','$1-')
|
|
>>"%PS1%" echo Write-Host ('[+] New MAC: ' + $pretty)
|
|
>>"%PS1%" echo $key = Get-ChildItem $base -ErrorAction SilentlyContinue ^| Where-Object { (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).NetCfgInstanceId -eq $a.InterfaceGuid } ^| Select-Object -First 1
|
|
>>"%PS1%" echo if (-not $key) { Write-Host '[!] Registry key not found for adapter, skipping.'; continue }
|
|
>>"%PS1%" echo try { Set-ItemProperty -Path $key.PSPath -Name NetworkAddress -Value $mac -Type String -ErrorAction Stop } catch { Write-Host ('[!] Failed to set NetworkAddress: ' + $_.Exception.Message); continue }
|
|
>>"%PS1%" echo Write-Host '[*] Disabling adapter...'
|
|
>>"%PS1%" echo Disable-NetAdapter -Name $a.Name -Confirm:$false -ErrorAction SilentlyContinue
|
|
>>"%PS1%" echo Start-Sleep -Seconds 2
|
|
>>"%PS1%" echo Write-Host '[*] Enabling adapter...'
|
|
>>"%PS1%" echo Enable-NetAdapter -Name $a.Name -Confirm:$false -ErrorAction SilentlyContinue
|
|
>>"%PS1%" echo Start-Sleep -Seconds 3
|
|
>>"%PS1%" echo $now = (Get-NetAdapter -Name $a.Name -ErrorAction SilentlyContinue).MacAddress
|
|
>>"%PS1%" echo if ($now -and ($now -replace '[:-]','') -ieq $mac) { Write-Host ('[OK] MAC applied: ' + $now) } else { Write-Host ('[!] Driver did not accept new MAC. Current: ' + $now + ' (update NIC driver or use a dedicated MAC changer)') }
|
|
>>"%PS1%" echo }
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%"
|
|
del /f /q "%PS1%" >NUL 2>&1
|
|
exit /b
|
|
|
|
:stop_any
|
|
sc stop AnyDesk >NUL 2>&1
|
|
if %errorlevel%==1062 goto :so_kill
|
|
if %errorlevel%==0 goto :so_kill
|
|
timeout /t 1 /nobreak >NUL
|
|
goto stop_any
|
|
:so_kill
|
|
taskkill /f /im "AnyDesk.exe" >NUL 2>&1
|
|
timeout /t 1 /nobreak >NUL
|
|
exit /b
|