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

Add chrome.extensions.vm #1139

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
13 changes: 13 additions & 0 deletions packages/chrome.extensions.vm/chrome.extensions.vm.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>chrome.extensions.vm</id>
<version>0.0.0.20240930</version>
<authors>Mandiant</authors>
<description>A package for multiple useful chrome extensions from the Chrome webstore.</description>
<dependencies>
<dependency id="common.vm" />
<dependency id="googlechrome.vm" />
</dependencies>
</metadata>
</package>
91 changes: 91 additions & 0 deletions packages/chrome.extensions.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
$ErrorActionPreference = 'Stop'
Import-Module vm.common -Force -DisableNameChecking

try {
$extensions = @(
# MetaMask
'nkbihfbeogaeaoehlefnkodbefgpgknn'
# Phantom
'bfnaelmomeimhlpmgjnjophhpkkoljpa'
# BNB Chain Wallet
'fhbohimaelbohpjbbldcngcnapndodjp'
# Avira Password Manager
'caljgklbbfbcjjanaijlacgncafpegll'
# KeePassXC-Browser
'oboonakemofpalcgghocfoadofidjkkk'
# Yoroi
'ffnbelfdoeiohenkjibnmadjiehjhajb'
# XDEFI Wallet
'hmeobnfnfcmdkdcmlblgagmfpfboieaf'
# ...
)

# Installing the extensions under `ExtensionInstallForcelist` so it can be installed
# and enabled silently, without user interaction. By default, this registry key does
# not exist and it is not used within Flare-VM.
# Ref: https://chromeenterprise.google/policies/?policy=ExtensionInstallForcelist

$regKeyPath = "HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\ExtensionInstallForcelist"
$updateUrl = "https://clients2.google.com/service/update2/crx"

New-Item -Path $regKeyPath -Force -ea 0 | Out-Null
$valueName = 1
Foreach ($extensionId in $extensions)
{
New-ItemProperty -Path "$regKeyPath" -Name "$valueName" -Type String -Value "$extensionId;$updateUrl" -Force -ea 0 | Out-Null
$valueName += 1
}

$maximumTries = 5
$chromePath = "${Env:ProgramFiles}\Google\Chrome\Application\chrome.exe"
$extensionsDir = "${Env:LocalAppData}\Google\Chrome\User Data\Default\Extensions"

# Stop Chrome if it is already running.
Stop-Process -Force -Name Chrome -ea 0

# Start Chrome to load the extensions.
$chromeProcess = Start-Process -FilePath $chromePath -passthru

$tries = 0
$loaded = $false
while ((-not $loaded) -and ($tries -ne $maximumTries))
{
# Wait for the extensions to be loaded.
Start-Sleep -Seconds 30

# Make sure all of the extensions are loaded.
$loaded = $true
Foreach ($extensionId in $extensions)
{
$extensionPath = Join-Path $extensionsDir $extensionId
if (-not (Test-Path -Path $extensionPath))
{
$loaded = $false
break
}
}

$tries += 1
}

# Close Chrome gracefully.
if ($chromeProcess.CloseMainWindow())
{
Wait-Process -Id $chromeProcess.Id | Out-Null
}
else
{
# Force kill the process instead.
Stop-Process -Force -Id $chromeProcess.Id | Out-Null
}

if (-not $loaded)
{
# Uninstall the extensions if Chrome is unable to load it.
Remove-Item -Path $regKeyPath -Recurse -Force -ea 0
throw "Chrome is unable to load the extensions"
}

} catch {
VM-Write-Log-Exception $_
}
8 changes: 8 additions & 0 deletions packages/chrome.extensions.vm/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ErrorActionPreference = 'Continue'
Import-Module vm.common -Force -DisableNameChecking

# It is safe to delete this registry key as it does not exist by default and it is
# not used within Flare-VM.

$regKeyPath = "HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\ExtensionInstallForcelist"
Remove-Item -Path $regKeyPath -Recurse -Force -ea 0
d35ha marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions scripts/test/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class UsesInvalidCategory(Lint):
"python3.vm",
"x64dbgpy.vm",
"vscode.extension.",
"chrome.extensions.vm",
]

root_path = os.path.abspath(os.path.join(__file__, "../../.."))
Expand Down
Loading