docs: armonización masiva de bitácoras, categorización de nodos y diagnóstico srv-dasu
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
$cfg = "C:\ProgramData\ssh\sshd_config"
|
||||
Write-Host "=== Cambiando SSH a puerto 7022 ===" -ForegroundColor Green
|
||||
Write-Host "Config: $cfg"
|
||||
|
||||
# Backup
|
||||
Copy-Item $cfg "$cfg.bak" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# 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
|
||||
|
||||
Write-Host "Verificacion:" -ForegroundColor Yellow
|
||||
Get-Content $cfg | Select-String "Port"
|
||||
|
||||
Write-Host "`nReiniciando sshd..." -ForegroundColor Yellow
|
||||
Stop-Service sshd -Force
|
||||
Start-Sleep -Seconds 3
|
||||
Start-Service sshd
|
||||
|
||||
Write-Host "`n=== netstat ===" -ForegroundColor Yellow
|
||||
netstat -an | Select-String "LISTEN" | Select-String "7022"
|
||||
|
||||
Write-Host "`n=== LISTO ===" -ForegroundColor Green
|
||||
Read-Host "Presione ENTER"
|
||||
@@ -0,0 +1,49 @@
|
||||
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 "INSTALANDO OPENSSH (con fix TEMP)"
|
||||
Log-Msg "=========================================================="
|
||||
|
||||
try {
|
||||
# Fix TEMP: usar carpeta de sistema en vez de la del usuario
|
||||
$env:TEMP = "C:\Windows\Temp"
|
||||
$env:TMP = "C:\Windows\Temp"
|
||||
Log-Msg "TEMP redirigido a C:\Windows\Temp"
|
||||
|
||||
$cap = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
|
||||
if ($cap.State -eq 'Installed') {
|
||||
Log-Msg "OpenSSH Server ya instalado."
|
||||
} else {
|
||||
Log-Msg "Instalando OpenSSH.Server..."
|
||||
Add-WindowsCapability -Online -Name $cap.Name
|
||||
Log-Msg "Instalado OK."
|
||||
}
|
||||
|
||||
Set-Service sshd -StartupType Automatic
|
||||
Start-Service sshd -ErrorAction SilentlyContinue
|
||||
Log-Msg "Servicio sshd configurado e iniciado."
|
||||
|
||||
# Puerto 7022
|
||||
$cfg = "C:\ProgramData\ssh\sshd_config"
|
||||
$lines = Get-Content $cfg | Where-Object { $_ -notmatch '^\s*#?\s*Port\s+\d+' }
|
||||
@("Port 7022") + $lines | Set-Content $cfg -Force
|
||||
New-NetFirewallRule -Name 'SSH-7022' -DisplayName 'SSH 7022' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 7022 -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
Stop-Service sshd -Force
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Service sshd
|
||||
Log-Msg "OpenSSH configurado en puerto 7022"
|
||||
|
||||
} catch {
|
||||
Log-Msg "ERROR: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "OPERACION COMPLETADA"
|
||||
Log-Msg "=========================================================="
|
||||
@@ -0,0 +1,106 @@
|
||||
$ErrorActionPreference = "Continue"
|
||||
$env:TEMP = "C:\Windows\Temp"
|
||||
$env:TMP = "C:\Windows\Temp"
|
||||
|
||||
function Log($msg) {
|
||||
$ts = Get-Date -Format "HH:mm:ss"
|
||||
Write-Host "[$ts] $msg" -ForegroundColor Cyan
|
||||
try { Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg="[$env:COMPUTERNAME] $msg"} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null } catch {}
|
||||
}
|
||||
|
||||
$hn = $env:COMPUTERNAME
|
||||
$os = (Get-WmiObject Win32_OperatingSystem).Caption
|
||||
$sshPort = 7022
|
||||
|
||||
Log "=========================================="
|
||||
Log "W-ZOMBI SETUP — $hn"
|
||||
Log "OS: $os"
|
||||
Log "=========================================="
|
||||
|
||||
# --- PASO 1: Detectar e instalar OpenSSH ---
|
||||
$sshInstalled = $false
|
||||
|
||||
# Verificar si sshd ya existe
|
||||
if (Get-Service sshd -ErrorAction SilentlyContinue) {
|
||||
Log "PASO 1: sshd ya existe."
|
||||
$sshInstalled = $true
|
||||
} elseif ($os -match "200[38]|Vista|XP") {
|
||||
# Legacy: Win32-OpenSSH manual
|
||||
Log "PASO 1: OS Legacy ($os) — instalando Win32-OpenSSH..."
|
||||
$zip = "C:\OpenSSH-Win64.zip"
|
||||
$dir = "C:\OpenSSH-Win64"
|
||||
try {
|
||||
(New-Object Net.WebClient).DownloadFile("http://10.0.10.8:8000/payloads/OpenSSH-Win64.zip", $zip)
|
||||
$shell = New-Object -ComObject Shell.Application
|
||||
$shell.NameSpace("C:\").CopyHere($shell.NameSpace($zip).Items(), 0x14)
|
||||
& "$dir\install-sshd.ps1" 2>&1 | Out-Null
|
||||
& "$dir\ssh-keygen.exe" -A 2>&1 | Out-Null
|
||||
Set-Service sshd -StartupType Automatic
|
||||
$sshInstalled = $true
|
||||
Log "Win32-OpenSSH instalado OK."
|
||||
} catch {
|
||||
Log "ERROR Legacy: $($_.Exception.Message)"
|
||||
}
|
||||
} else {
|
||||
# Moderno: Add-WindowsCapability (Win10/2016+)
|
||||
Log "PASO 1: OS Moderno — instalando via Add-WindowsCapability..."
|
||||
try {
|
||||
$cap = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
|
||||
if ($cap.State -ne 'Installed') {
|
||||
Add-WindowsCapability -Online -Name $cap.Name | Out-Null
|
||||
}
|
||||
Set-Service sshd -StartupType Automatic
|
||||
Start-Service sshd -ErrorAction SilentlyContinue
|
||||
$sshInstalled = $true
|
||||
Log "OpenSSH Server instalado OK."
|
||||
} catch {
|
||||
Log "ERROR Moderno: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $sshInstalled) {
|
||||
Log "FALLO: No se pudo instalar SSH. Abortando."
|
||||
return
|
||||
}
|
||||
|
||||
# --- PASO 2: Configurar puerto 7022 ---
|
||||
Log "PASO 2: Configurando puerto $sshPort..."
|
||||
|
||||
$cfgPaths = @("C:\ProgramData\ssh\sshd_config", "C:\OpenSSH-Win64\sshd_config")
|
||||
$cfgPath = $cfgPaths | Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
|
||||
if ($cfgPath) {
|
||||
$lines = Get-Content $cfgPath | Where-Object { $_ -notmatch '^\s*#?\s*Port\s+\d+' }
|
||||
@("Port $sshPort") + $lines | Set-Content $cfgPath -Force
|
||||
Log "Config: $cfgPath -> Port $sshPort"
|
||||
} else {
|
||||
Log "WARN: No se encontro sshd_config"
|
||||
}
|
||||
|
||||
# --- PASO 3: Firewall ---
|
||||
Log "PASO 3: Firewall..."
|
||||
try {
|
||||
New-NetFirewallRule -Name "SSH-$sshPort" -DisplayName "SSH $sshPort" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort $sshPort -ErrorAction SilentlyContinue | Out-Null
|
||||
} catch {
|
||||
netsh advfirewall firewall add rule name="SSH-$sshPort" dir=in action=allow protocol=TCP localport=$sshPort 2>&1 | Out-Null
|
||||
}
|
||||
Log "Firewall: puerto $sshPort abierto"
|
||||
|
||||
# --- PASO 4: Reiniciar sshd ---
|
||||
Log "PASO 4: Reiniciando sshd..."
|
||||
Stop-Service sshd -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Service sshd -ErrorAction SilentlyContinue
|
||||
Log "sshd reiniciado."
|
||||
|
||||
# --- PASO 5: Verificar ---
|
||||
$listening = netstat -an | Select-String ":$sshPort\s+.*LISTEN"
|
||||
if ($listening) {
|
||||
Log "VERIFICADO: $hn escuchando en puerto $sshPort"
|
||||
} else {
|
||||
Log "WARN: Puerto $sshPort no detectado en netstat"
|
||||
}
|
||||
|
||||
Log "=========================================="
|
||||
Log "SETUP COMPLETADO — $hn : $sshPort"
|
||||
Log "=========================================="
|
||||
Reference in New Issue
Block a user