My Portfolio
Here's my bigger milestones & contributions
Here's my bigger milestones & contributions
Write-Host @"
______ _____ ______ _ _ _
| ___ \/ ___| | ___| | | | | (_)
| |_/ /\ `--. | |_ _ __ _ _ ___| |_ _ __ __ _| |_ _ ___ _ __
| __/ `--. \ | _| '__| | | / __| __| '__/ _` | __| |/ _ \| '_ \
| | /\__/ / | | | | | |_| \__ \ |_| | | (_| | |_| | (_) | | | |
\_| \____/ \_| |_| \__,_|___/\__|_| \__,_|\__|_|\___/|_| |_|
"@ -ForegroundColor Cyan
# This function generates three random flags, places them in random locations on the C drive, and prompts the user to find and input them.
function Start-DigitalWasteland {
# Generate flags
$flags = 1..3 | ForEach-Object { [guid]::NewGuid().ToString() }
# Get file paths on C drive at random
$randomPaths = 1..3 | ForEach-Object {
$folder = Get-ChildItem -Path C:\ -Directory -Recurse | Get-Random
"$($folder.FullName)\flag$_.txt"
}
# Create flags
for ($i = 0; $i -lt $flags.Length; $i++) {
$flags[$i] | Out-File -FilePath $randomPaths[$i]
}
Write-Host "PS Frustration Game activated, you have 10 Minutes." -ForegroundColor Red
# Prompt user to enter flags
$userFlags = Read-Host "Enter all three flags (comma separated)"
# Validate flags (in any order)
$userFlagsArray = $userFlags.Split(',').Trim()
if ($userFlagsArray | Sort-Object -Unique | Compare-Object -ReferenceObject ($flags | Sort-Object -Unique) -SyncWindow 0 -PassThru | Measure-Object).Count -eq 0 {
Write-Host "Congratulations! You successfully diffused the malware." -ForegroundColor Green
Cleanup-Flags -Paths $randomPaths
} else {
# Malware detonates
Detonate-Malware -Paths $randomPaths
}
}
# Main Function: Detonates the Malware
# This function is triggered if the user fails to input the correct flags, simulating a destructive outcome.
function Detonate-Malware {
param (
[string[]]$Paths
)
Write-Host "Game Over. The malware has detonated!" -ForegroundColor Red
Cleanup-Flags -Paths $Paths
}
# Cleanup Function: Removes the flag files after the game ends
# This ensures no remnants of the game are left on the system.
function Cleanup-Flags {
param (
[string[]]$Paths
)
foreach ($path in $Paths) {
Remove-Item -Path $path -ErrorAction SilentlyContinue
}
}
# Entry Point
# Starts the game by calling the main function.
Start-DigitalWasteland