Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[common] Add VM-Unzip-Recursively #1170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20241106</version>
<version>0.0.0.20241122</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
45 changes: 45 additions & 0 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,48 @@ function VM-Create-Ico {
$fs.Close()
return $iconLocation
}

# Unzip the ZIP `$desktop\drive-download*.zip` and the ZIPs (files with extension `.7z` and `.zip`) inside it.
# Try without password and with passwords "infected" and "flare.
# Delete extracted ZIPS after unzipping them.
# Useful to extract zipped labs downloaded from GDrive keeping the folder structure.
function VM-Unzip-Recursively {
$desktop = Join-Path ${Env:UserProfile} "Desktop"
$zip = Get-Item "$desktop\drive-download*.zip"
if (-Not (Test-Path $zip)) {
Write-Host "[-] ERROR FINDING '$zip'" -ForegroundColor Red
return
}

# Unzip main ZIP
$out = & 7z x $zip -o"$desktop" -y -ba -bb
if (-not $?) {
Write-Host "[-] ERROR UNZIPPING '$zip'" -ForegroundColor Red
return
}

Write-Host "[+] UNZIPPED '$zip'" -ForegroundColor Green
# Unzip extracted ZIPs (files with extension `.7z` and `.zip`)
ForEach ($line in $out.Split([Environment]::NewLine)) {
# Line example: "- MACC\Labs\apple.7z"
if (($line -like "- *.7z") -or ($line -like "- *.zip")) {
$file = $line.substring(2) # remove "- "
$fileDir = Split-Path $file -Parent
& 7z e $file -y -o"$fileDir" -pinfected 2>&1>$null
if (-not $?) {
& 7z e $file -y -o"$fileDir" -pflare 2>&1>$null
}
if (-not $?) {
& 7z e $file -y -o"$fileDir" -p 2>&1>$null
}
if (-not $?) {
Write-Host " [-] ERROR UNZIPPING '$file'" -ForegroundColor Red
return
}

# Remove ZIP after extracting it
Remove-Item $file -Force
Write-Host " [+] UNZIPPED '$file'" -ForegroundColor Green
}
}
}
Loading