[P2602][F1] SSH port 7022 verified on fenix+maurik, w-zombi payload ssh_port7022.ps1
This commit is contained in:
@@ -7,34 +7,40 @@ function Log-Msg {
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "INSTALANDO Y HABILITANDO OPENSSH SERVER NATIVO"
|
||||
Log-Msg "CONFIGURANDO SSH EN PUERTO 7022"
|
||||
Log-Msg "=========================================================="
|
||||
|
||||
$cfg = "C:\ProgramData\ssh\sshd_config"
|
||||
|
||||
try {
|
||||
$sshCheck = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
|
||||
if ($sshCheck.State -ne 'Installed') {
|
||||
Log-Msg "Instalando caracteristica OpenSSH.Server (esto puede tomar un minuto)..."
|
||||
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 | Out-Null
|
||||
} else {
|
||||
Log-Msg "OpenSSH.Server ya se encuentra instalado."
|
||||
}
|
||||
# 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"
|
||||
|
||||
Log-Msg "Configurando servicio sshd en Inicio Automatico..."
|
||||
Set-Service -Name sshd -StartupType 'Automatic'
|
||||
Start-Service sshd -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"
|
||||
|
||||
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
|
||||
Log-Msg "Abriendo puerto TCP 22 en el Firewall local..."
|
||||
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null
|
||||
}
|
||||
# Reiniciar servicio
|
||||
Stop-Service sshd -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Service sshd
|
||||
Log-Msg "Servicio sshd reiniciado OK"
|
||||
|
||||
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object InterfaceAlias -notmatch 'Loopback').IPAddress
|
||||
Log-Msg "OpenSSH Server instalado y corriendo en el puerto 22."
|
||||
Log-Msg "Conectar via: ssh Administrador@$($ip[0])"
|
||||
$port = (Get-Content $cfg | Select-String "^Port").ToString().Trim()
|
||||
Log-Msg "Verificacion: $port"
|
||||
} catch {
|
||||
Log-Msg "Fallo al instalar SSH: $_"
|
||||
Log-Msg "ERROR: $_"
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "OPERACION COMPLETADA. Ahora SSH esta disponible."
|
||||
Log-Msg "OPERACION COMPLETADA"
|
||||
Log-Msg "=========================================================="
|
||||
exit
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
# 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"
|
||||
|
||||
# Reiniciar servicio
|
||||
Stop-Service sshd -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Service sshd
|
||||
Log-Msg "Servicio sshd reiniciado OK"
|
||||
|
||||
$port = (Get-Content $cfg | Select-String "^Port").ToString().Trim()
|
||||
Log-Msg "Verificacion: $port"
|
||||
} catch {
|
||||
Log-Msg "ERROR: $_"
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "OPERACION COMPLETADA"
|
||||
Log-Msg "=========================================================="
|
||||
exit
|
||||
Reference in New Issue
Block a user