[P2602][F1] sysacadweb SSH 7022 verified, nodo updated (IP 10.0.10.12), Win32-OpenSSH legacy
This commit is contained in:
@@ -1,46 +1,27 @@
|
||||
function Log-Msg {
|
||||
param([string]$Message)
|
||||
Write-Host $Message -ForegroundColor Cyan
|
||||
try {
|
||||
Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg=$Message} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null
|
||||
} catch {}
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "CONFIGURANDO SSH EN PUERTO 7022"
|
||||
Log-Msg "=========================================================="
|
||||
|
||||
$cfg = "C:\ProgramData\ssh\sshd_config"
|
||||
Write-Host "=== Cambiando SSH a puerto 7022 ===" -ForegroundColor Green
|
||||
Write-Host "Config: $cfg"
|
||||
|
||||
try {
|
||||
# Leer config, quitar cualquier linea Port anterior
|
||||
$lines = Get-Content $cfg | Where-Object { $_ -notmatch '^\s*#?\s*Port\s+\d+' }
|
||||
|
||||
# Agregar Port 7022 al inicio
|
||||
$lines = @("Port 7022") + $lines
|
||||
|
||||
# Escribir config limpia
|
||||
$lines | Set-Content $cfg -Force
|
||||
Log-Msg "sshd_config actualizado: Port 7022"
|
||||
# Backup
|
||||
Copy-Item $cfg "$cfg.bak" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Firewall: agregar 7022, quitar 22
|
||||
New-NetFirewallRule -Name 'SSH-7022' -DisplayName 'SSH 7022' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 7022 -ErrorAction SilentlyContinue | Out-Null
|
||||
Remove-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -ErrorAction SilentlyContinue
|
||||
Log-Msg "Firewall actualizado: 7022 abierto, 22 cerrado"
|
||||
# Leer, reemplazar, escribir
|
||||
$content = Get-Content $cfg
|
||||
$content = $content -replace '^\s*#?\s*Port\s+\d+', 'Port 7022'
|
||||
$found = $content | Select-String '^Port 7022'
|
||||
if (-not $found) { $content = @("Port 7022") + $content }
|
||||
$content | Set-Content $cfg -Force
|
||||
|
||||
# Reiniciar servicio
|
||||
Stop-Service sshd -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Service sshd
|
||||
Log-Msg "Servicio sshd reiniciado OK"
|
||||
Write-Host "Verificacion:" -ForegroundColor Yellow
|
||||
Get-Content $cfg | Select-String "Port"
|
||||
|
||||
$port = (Get-Content $cfg | Select-String "^Port").ToString().Trim()
|
||||
Log-Msg "Verificacion: $port"
|
||||
} catch {
|
||||
Log-Msg "ERROR: $_"
|
||||
}
|
||||
Write-Host "`nReiniciando sshd..." -ForegroundColor Yellow
|
||||
Stop-Service sshd -Force
|
||||
Start-Sleep -Seconds 3
|
||||
Start-Service sshd
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "OPERACION COMPLETADA"
|
||||
Log-Msg "=========================================================="
|
||||
exit
|
||||
Write-Host "`n=== netstat ===" -ForegroundColor Yellow
|
||||
netstat -an | Select-String "LISTEN" | Select-String "7022"
|
||||
|
||||
Write-Host "`n=== LISTO ===" -ForegroundColor Green
|
||||
Read-Host "Presione ENTER"
|
||||
|
||||
Reference in New Issue
Block a user