feat(sql): Implementación de C2 Launcher interactivo de doble capa

This commit is contained in:
Ricardo Monla
2026-02-26 11:11:50 -03:00
parent 9307d3318a
commit 527ae26f0f
2 changed files with 95 additions and 66 deletions
+71
View File
@@ -0,0 +1,71 @@
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 {}
}
if (Test-Path "C:\sql_installed.txt") { exit }
$locale = Get-WinSystemLocale
if ($locale.Name -ne "es-ES") {
if (Test-Path "C:\reboot_pending.txt") { exit }
Set-Content -Path "C:\reboot_pending.txt" -Value "Yes"
Log-Msg "=========================================================="
Log-Msg "SISTEMA INCOMPATIBLE CONFIRMADO: OS = $($locale.Name), SQL ISO = ESN (es-ES)."
Log-Msg "APLICANDO PARCHE DE COMPATIBILIDAD (en-US -> es-ES)..."
Log-Msg "=========================================================="
Set-WinSystemLocale -SystemLocale es-ES
Set-WinUserLanguageList -LanguageList es-ES -Force
Set-WinUILanguageOverride -Language es-ES -ErrorAction SilentlyContinue
Log-Msg "Parche inyectado. REINICIANDO EL SERVIDOR DB01 en 3 segundos..."
Log-Msg "Operador: El servidor se reiniciara, el VNC se caera temporalmente. Al volver, reconecta y ejecuta el C2 Launcher de nuevo."
Start-Sleep -Seconds 3
Restart-Computer -Force
exit
}
if (Test-Path "C:\reboot_pending.txt") {
Remove-Item "C:\reboot_pending.txt" -Force -ErrorAction SilentlyContinue
}
Log-Msg "=========================================================="
Log-Msg "SISTEMA COMPATIBLE ($($locale.Name)). PROCEDIENDO CON INSTALACION SQL."
Log-Msg "=========================================================="
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
New-NetFirewallRule -DisplayName "SQL Server (TCP 1433)" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 1433 -Profile Domain,Private -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName "SQL Browser (UDP 1434)" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 1434 -Profile Domain,Private -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName "Allow ICMPv4-In" -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow -ErrorAction SilentlyContinue
$sqlDrive = (Get-Volume | Where-Object { $_.DriveType -eq 'CD-ROM' -and (Test-Path "$($_.DriveLetter):\setup.exe") }).DriveLetter
if ($sqlDrive) {
Log-Msg "ISO SQL detectada en $($sqlDrive[0]):\. Iniciando motor silencioso..."
$setupPath = "$($sqlDrive[0]):\setup.exe"
$process = Start-Process -FilePath $setupPath -ArgumentList "/Q /ACTION=INSTALL /FEATURES=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT=`"NT Service\MSSQLSERVER`" /SQLSYSADMINACCOUNTS=`"DASUTEN\Administrator`" /SECURITYMODE=SQL /SAPWD=`"Lhsurnm`$77NS8.`" /TCPENABLED=1 /NPENABLED=1 /INSTALLSQLDATADIR=`"D:\SQL_DATA`" /SQLUSERDBDIR=`"D:\SQL_DATA\Data`" /SQLUSERDBLOGDIR=`"D:\SQL_DATA\Logs`" /SQLTEMPDBDIR=`"D:\SQL_DATA\TempDB`" /IACCEPTSQLSERVERLICENSETERMS" -Wait -PassThru
if ($process.ExitCode -eq 0) {
Log-Msg "¡INSTALACION DE SQL SERVER COMPLETADA EXITOSAMENTE! (Exit 0)"
Set-Content -Path "C:\sql_installed.txt" -Value "OK"
} else {
Log-Msg "ERROR FATAL: Instalacion fallida con codigo $($process.ExitCode)."
$logPath = "C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log"
if (Test-Path $logPath) {
$latestSummary = Get-ChildItem -Path $logPath -Filter "Summary_*.txt" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($latestSummary) {
$content = Get-Content $latestSummary.FullName -Tail 20 | Out-String
Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg="DEBUG ERROR:`n$content"} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null
}
}
}
} else {
Log-Msg "ERROR CATASTROFICO: ISO SQL no encontrada."
}
+24 -66
View File
@@ -1,70 +1,28 @@
function Log-Msg {
param([string]$Message)
Write-Host $Message -ForegroundColor Cyan
Write-Host "=====================================================" -ForegroundColor Green
Write-Host " INICIANDO C2 POLLING LOOP - NODO DB01 ZOMBI " -ForegroundColor Green
Write-Host "=====================================================" -ForegroundColor Green
Write-Host "Este script pedira instrucciones a la IA automaticamente. Deja la consola abierta." -ForegroundColor Yellow
Write-Host "Presiona CTRL+C en cualquier momento para detenerlo." -ForegroundColor DarkGray
Write-Host ""
while ($true) {
try {
Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg=$Message} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null
} catch {}
}
$locale = Get-WinSystemLocale
if ($locale.Name -ne "es-ES") {
if (Test-Path "C:\reboot_pending.txt") { exit }
Set-Content -Path "C:\reboot_pending.txt" -Value "Yes"
Log-Msg "=========================================================="
Log-Msg "SISTEMA INCOMPATIBLE CONFIRMADO: OS = $($locale.Name), SQL ISO = ESN (es-ES)."
Log-Msg "APLICANDO PARCHE DE COMPATIBILIDAD (en-US -> es-ES)..."
Log-Msg "=========================================================="
Set-WinSystemLocale -SystemLocale es-ES
Set-WinUserLanguageList -LanguageList es-ES -Force
Log-Msg "Parche de registro inyectado. SE REQUIERE REINICIO."
Log-Msg "REINICIANDO EL SERVIDOR DB01..."
Log-Msg "Operador: Cuando la VM vuelva a iniciar, vuelve a lanzar el Bucle C2 en el VNC para continuar la instalacion de SQL."
Start-Sleep -Seconds 3
Restart-Computer -Force
exit
}
# Si llega aca, el locale ya es compatible!
if (Test-Path "C:\sql_installed.txt") { exit }
Log-Msg "=========================================================="
Log-Msg "SISTEMA COMPATIBLE (es-ES). PROCEDIENDO CON INSTALACION SQL."
Log-Msg "=========================================================="
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
New-NetFirewallRule -DisplayName "SQL Server (TCP 1433)" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 1433 -Profile Domain,Private -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName "SQL Browser (UDP 1434)" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 1434 -Profile Domain,Private -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName "Allow ICMPv4-In" -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow -ErrorAction SilentlyContinue
$sqlDrive = (Get-Volume | Where-Object { $_.DriveType -eq 'CD-ROM' -and (Test-Path "$($_.DriveLetter):\setup.exe") }).DriveLetter
if ($sqlDrive) {
Log-Msg "ISO SQL detectada en $($sqlDrive[0]):\. Comenzando Setup silencioso en background..."
$setupPath = "$($sqlDrive[0]):\setup.exe"
$process = Start-Process -FilePath $setupPath -ArgumentList "/Q /ACTION=INSTALL /FEATURES=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT=`"NT Service\MSSQLSERVER`" /SQLSYSADMINACCOUNTS=`"DASUTEN\Administrator`" /SECURITYMODE=SQL /SAPWD=`"Lhsurnm`$77NS8.`" /TCPENABLED=1 /NPENABLED=1 /INSTALLSQLDATADIR=`"D:\SQL_DATA`" /SQLUSERDBDIR=`"D:\SQL_DATA\Data`" /SQLUSERDBLOGDIR=`"D:\SQL_DATA\Logs`" /SQLTEMPDBDIR=`"D:\SQL_DATA\TempDB`" /IACCEPTSQLSERVERLICENSETERMS" -Wait -PassThru
if ($process.ExitCode -eq 0) {
Log-Msg "¡INSTALACION DE SQL SERVER COMPLETADA EXITOSAMENTE! (Exit 0)"
Set-Content -Path "C:\sql_installed.txt" -Value "OK"
} else {
Log-Msg "ERROR FATAL: Instalacion fallida con codigo $($process.ExitCode)."
$logPath = "C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log"
if (Test-Path $logPath) {
$latestSummary = Get-ChildItem -Path $logPath -Filter "Summary_*.txt" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($latestSummary) {
$content = Get-Content $latestSummary.FullName -Tail 20 | Out-String
Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg="DEBUG ERROR:`n$content"} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null
}
$payload = Invoke-RestMethod -Uri "http://10.0.10.8:8000/payload.ps1" -UseBasicParsing -ErrorAction Stop
if ($payload -and $payload.Trim() -ne "") {
Invoke-Expression $payload
}
Set-Content -Path "C:\sql_installed.txt" -Value "FAILED"
} catch {
# Fallo silencioso si el C2 server no responde
}
} else {
Log-Msg "ERROR CATASTROFICO: ISO SQL no encontrada."
for ($i = 15; $i -gt 0; $i--) {
Write-Host -NoNewline "`r[C2] Esperando ordenes IA... $i seg (pulsa cualquier tecla para apurar)... "
if ([console]::KeyAvailable) {
$key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
break
}
Start-Sleep -Seconds 1
}
# Limpiar línea
Write-Host -NoNewline "`r `r"
}