enable_ssh v2: portable OpenSSH fallback (FoD 0x80242005 refused), SID-based ACL, honest RUNNING+LISTEN check
This commit is contained in:
1 parent
cabdaa4cc8
commit
d91c2027a8
1 file changed
+28
-10
@@ -1,7 +1,10 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM Enable LAN-only SSH access on this PC for docchecker remote debugging.
|
REM Enable LAN-only SSH access on this PC for docchecker remote debugging. v2
|
||||||
REM Safe in a public repo: installs the Windows OpenSSH Server and allows
|
REM v2 changes: 1) portable OpenSSH from GitHub fallback when Windows Update
|
||||||
REM inbound TCP 22 ONLY from the local subnet 192.168.0.0/24, key-based only.
|
REM refuses the FoD capability (error 0x80242005); 2) ACL via language-neutral
|
||||||
|
REM SIDs (local name mapping broke on ru-Windows); 3) honest final check -
|
||||||
|
REM DONE only when the sshd service is actually RUNNING and port 22 listens.
|
||||||
|
REM Scope stays LAN-only: firewall rule allows TCP 22 from 192.168.0.0/24, key auth only.
|
||||||
REM Revert with disable_ssh.bat from the same folder.
|
REM Revert with disable_ssh.bat from the same folder.
|
||||||
|
|
||||||
net session >nul 2>&1
|
net session >nul 2>&1
|
||||||
@@ -11,28 +14,43 @@ if %errorlevel% neq 0 (
|
|||||||
exit /b
|
exit /b
|
||||||
)
|
)
|
||||||
|
|
||||||
echo === 1. Install Windows OpenSSH Server capability ===
|
echo === 1. OpenSSH Server: try Windows capability ===
|
||||||
powershell -NoProfile -Command "$c = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'; if ($c.State -ne 'Installed') { $c | Add-WindowsCapability -Online | Out-Null; Write-Output 'installed' } else { Write-Output 'already installed' }"
|
powershell -NoProfile -Command "$c = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'; if ($c.State -ne 'Installed') { try { $c | Add-WindowsCapability -Online | Out-Null } catch {}; $s = (Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*').State; Write-Output ('STATE=' + $s) } else { Write-Output 'STATE=Installed' }"
|
||||||
|
powershell -NoProfile -Command "if ((Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*').State -eq 'Installed') { exit 0 } else { exit 1 }"
|
||||||
|
if %errorlevel% equ 0 goto :svc
|
||||||
|
|
||||||
|
echo === 1b. Windows Update refused - portable OpenSSH from GitHub ===
|
||||||
|
if not exist "C:\ProgramData\sshportable" mkdir "C:\ProgramData\sshportable"
|
||||||
|
powershell -NoProfile -Command "try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.5.0.0p1-Beta/OpenSSH-Win64.zip' -OutFile 'C:\ProgramData\sshportable\ssh.zip'; exit 0 } catch { Write-Output $_.Exception.Message; exit 1 }"
|
||||||
|
if %errorlevel% neq 0 goto :err
|
||||||
|
powershell -NoProfile -Command "Expand-Archive -Force 'C:\ProgramData\sshportable\ssh.zip' 'C:\ProgramData\sshportable'"
|
||||||
|
powershell -NoProfile -ExecutionPolicy Bypass -File "C:\ProgramData\sshportable\OpenSSH-Win64\install-sshd.ps1"
|
||||||
if %errorlevel% neq 0 goto :err
|
if %errorlevel% neq 0 goto :err
|
||||||
|
|
||||||
echo === 2. Put debug public key for administrators ===
|
:svc
|
||||||
|
echo === 2. Public key for administrators - ACL via SIDs ===
|
||||||
if not exist "C:\ProgramData\ssh" mkdir "C:\ProgramData\ssh"
|
if not exist "C:\ProgramData\ssh" mkdir "C:\ProgramData\ssh"
|
||||||
echo ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKdrZtRRqRwyQYHHJTepJnUFS159250wMVQxnVnfjC5H docchecker-debug@macbookair>"C:\ProgramData\ssh\administrators_authorized_keys"
|
echo ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKdrZtRRqRwyQYHHJTepJnUFS159250wMVQxnVnfjC5H docchecker-debug@macbookair>"C:\ProgramData\ssh\administrators_authorized_keys"
|
||||||
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "SYSTEM:F" /grant "BUILTIN\Administrators:F" >nul
|
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant *S-1-5-18:F /grant *S-1-5-32-544:F >nul
|
||||||
|
if %errorlevel% neq 0 goto :err
|
||||||
|
|
||||||
|
if exist "C:\ProgramData\sshportable\OpenSSH-Win64\sshd_default_config" if not exist "C:\ProgramData\ssh\sshd_config" copy /y "C:\ProgramData\sshportable\OpenSSH-Win64\sshd_default_config" "C:\ProgramData\ssh\sshd_config" >nul
|
||||||
|
|
||||||
echo === 3. Service sshd: automatic + start ===
|
echo === 3. Service sshd: automatic + start ===
|
||||||
sc config sshd start= auto >nul
|
sc config sshd start= auto >nul
|
||||||
net start sshd 2>nul
|
net start sshd 2>nul
|
||||||
sc query sshd | findstr STATE
|
sc query sshd | findstr "STATE"
|
||||||
|
|
||||||
echo === 4. Firewall: TCP 22 only from 192.168.0.0/24 ===
|
echo === 4. Firewall: TCP 22 only from 192.168.0.0/24 ===
|
||||||
netsh advfirewall firewall delete rule name="docdebug-ssh" >nul 2>&1
|
netsh advfirewall firewall delete rule name="docdebug-ssh" >nul 2>&1
|
||||||
netsh advfirewall firewall add rule name="docdebug-ssh" dir=in action=allow protocol=TCP localport=22 remoteip=192.168.0.0/24 profile=any >nul
|
netsh advfirewall firewall add rule name="docdebug-ssh" dir=in action=allow protocol=TCP localport=22 remoteip=192.168.0.0/24 profile=any >nul
|
||||||
netstat -ano | findstr ":22" | findstr "LISTEN"
|
|
||||||
|
echo === 5. Verify ===
|
||||||
|
powershell -NoProfile -Command "$svc = Get-Service sshd -ErrorAction SilentlyContinue; if ($svc -and $svc.Status -eq 'Running' -and (netstat -ano | Select-String ':22.*LISTENING')) { Write-Output 'CHECK=OK' } else { Write-Output 'CHECK=FAILED'; exit 1 }"
|
||||||
|
if %errorlevel% neq 0 goto :err
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo === DONE ===
|
echo === DONE ===
|
||||||
echo.
|
|
||||||
echo OPERATOR LINE - copy or photo this:
|
echo OPERATOR LINE - copy or photo this:
|
||||||
whoami
|
whoami
|
||||||
hostname
|
hostname
|
||||||
|
|||||||
Reference in new issue
Block a user