Create large file with random data with Powershell

$path      = "C:\Temp\random20GB.bin"
$sizeBytes = [long]20GB
$chunkSize = [int]64MB

$buffer = New-Object byte[] $chunkSize
$rng    = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$fs     = [System.IO.File]::Open($path, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)

try {
    $written = [long]0
    while ($written -lt $sizeBytes) {
        $toWrite = [int][Math]::Min([long]$chunkSize, $sizeBytes - $written)
        $rng.GetBytes($buffer)
        $fs.Write($buffer, 0, $toWrite)
        $written += $toWrite
        Write-Progress -Activity "Generating file" `
            -Status ("{0:N1} / {1:N1} GB" -f ($written/1GB), ($sizeBytes/1GB)) `
            -PercentComplete (($written / $sizeBytes) * 100)
    }
}
finally {
    $fs.Close()
    $rng.Dispose()
}

Turn Bat file into EXE file and let it run as a service to set registry keys

First we create a bat file that will do 2 things

  1. It will loop every 10 seconds
  2. It will call another bat file. We do this in case we need to make changes, we don’t need to build the EXE file every time
  3. We call it c:\path\set_reg_loader.bat
:loop
call c:\path\set_reg.bat
timeout /t 10 /nobreak
GOTO :loop

The we create the c:\path\set_reg.bat file that actually do the registry stuff

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Personalization" /v "Server1.dk was here" /t REG_DWORD /d 1 /f

Now we create the exe file

  1. Run C:\Windows\System32\iexpress.exe as Administrator

You can decide if you want to save the project

Now you have a nice EXE file that will go undetected by most security systems

Create the windows service that will run the exe file.

Start a CMD as administrator

sc create SetReg binPath= "C:\path\set_reg.EXE" DisplayName= SetRegDisplayname start= Auto obj= "NT AUTHORITY\System"

We now have a EXE file that runs as a service as Local System

You can’t access this shared folder because your organization’s security policies block unauthenticated guest access

A fix for that is to change the registry

Registry : Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters

DWORD: AllowInsecureGuestAuth = 1

In Windows 11 the DWORD entry might not be there. Then just create it, it will still work.