Files
dtic-DIIAA/payload.ps1
T

78 lines
4.4 KiB
PowerShell

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") -and (Get-Content "C:\sql_installed.txt") -eq "OK") { exit }
Log-Msg "=========================================================="
Log-Msg "INYECTANDO PARCHES DE REGISTRO PROFUNDOS PARA IDIOMA (SPAIN-3082 / 0C0A)"
Log-Msg "=========================================================="
# SQL Server en Server Core chequea estrictamente estas claves del registro para el 'LanguageMismatch'
$installLang = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "InstallLanguage").InstallLanguage
if ($installLang -ne "0C0A" -and !(Test-Path "C:\reboot_lock.txt")) {
try {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "InstallLanguage" -Value "0C0A"
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "Default" -Value "0C0A"
Set-WinSystemLocale -SystemLocale es-ES
Set-WinUserLanguageList -LanguageList es-ES -Force
Set-Content -Path "C:\reboot_lock.txt" -Value "BLOQUEO DE REINICIO INFINITO"
Log-Msg "Claves de registro de Idioma inyectadas a 0C0A (Espanol)."
Log-Msg "REINICIO OBLIGATORIO PREVENTIVO DETECTADO. El OS necesita reiniciar."
Log-Msg "Reiniciando servidor DB01 en 3 segundos..."
Start-Sleep -Seconds 3
Restart-Computer -Force
exit
} catch {
Log-Msg "Fallo al inyectar claves de registro obligatorias: $_"
}
}
if (Test-Path "C:\reboot_lock.txt") {
Log-Msg "Reinicio previo ejecutado. El OS revertio el registro InstallLanguage a $installLang. Rompiendo bucle infinito."
}
$locale = Get-WinSystemLocale
Log-Msg "=========================================================="
Log-Msg "SISTEMA COMPATIBLE ($($locale.Name) / 0C0A). 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."
}