Skip to content

Instantly share code, notes, and snippets.

@MHaggis
Created May 10, 2023 16:42
Show Gist options
  • Save MHaggis/e4ca32613ee5e2a52512fce4ab5c6ec6 to your computer and use it in GitHub Desktop.
Save MHaggis/e4ca32613ee5e2a52512fce4ab5c6ec6 to your computer and use it in GitHub Desktop.
# Define the typical path of the Snake Queue File
$filePath = "$env:windir\registration\"
# Create the folder if it doesn't exist
$null = New-Item -Path $filePath -ItemType Directory -Force
# Generate a random GUID
$guid = [guid]::NewGuid().ToString()
# Define the file name using the generated GUID and the regex pattern
$fileName = "$guid.$guid.crmlog"
# Create the file
$file = New-Item -Path $filePath -Name $fileName -ItemType "file"
# Set the file attributes to hidden, system, and archive
$file.Attributes = "Hidden", "System", "Archive"
function CalculateEntropy($bytes) {
$byteCounts = @{}
foreach ($byte in $bytes) {
if ($byteCounts.ContainsKey($byte)) {
$byteCounts[$byte]++
} else {
$byteCounts[$byte] = 1
}
}
$entropy = 0
$totalBytes = $bytes.Count
foreach ($byteCount in $byteCounts.Values) {
$probability = $byteCount / $totalBytes
$entropy -= $probability * [Math]::Log($probability, 2)
}
return $entropy
}
$minimumEntropy = 7
# Generate bytes with entropy above the minimum required
do {
$randomBytes = New-Object Byte[] 0x1000
(New-Object Random).NextBytes($randomBytes)
$entropy = CalculateEntropy($randomBytes)
} while ($entropy -le $minimumEntropy)
# Write the random bytes with high entropy to the file
[System.IO.File]::WriteAllBytes($file.FullName, $randomBytes)
# Output the file path
Write-Host "File created with entropy above 7: $($file.FullName)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment