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 googlechrome to VM-Packages #779

Closed
wants to merge 12 commits into from
Closed

Conversation

binjo
Copy link
Contributor

@binjo binjo commented Dec 11, 2023

To address issue #469, added:

  1. download/install Chrome by checking if installer's signature is valid
  2. add associations for opening url/html file in Chrome
  3. disable Chrome auto-update related services and registries

To address issue mandiant#469, added:
1. download/install Chrome by checking if installer's signature is valid
2. add associations for opening url/html file in Chrome
3. disable Chrome auto-update related services and registries
@binjo binjo requested a review from Ana06 December 11, 2023 08:26
1. fix lint issues
2. correct the tool category
3. remove shortcut on desktop
To address issue mandiant#469, added:
1. download/install Chrome by checking if installer's signature is valid
2. add associations for opening url/html file in Chrome
3. disable Chrome auto-update related services and registries
Copy link
Member

@Ana06 Ana06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work @binjo!

packages/googlechrome.vm/googlechrome.vm.nuspec Outdated Show resolved Hide resolved
- **If the package is out of date please check [Version History](#versionhistory) for the latest submitted version. If you have a question, please ask it in [Chocolatey Community Package Discussions](https://github.com/chocolatey-community/chocolatey-packages/discussions) or raise an issue on the [Chocolatey Community Packages Repository](https://github.com/chocolatey-community/chocolatey-packages/issues) if you have problems with the package. Disqus comments will generally not be responded to.**
]]></description>
<dependencies>
<dependency id="chocolatey-core.extension" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Why do we need this dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Get-PackageCacheLocation method is exported from chocolatey-core.extension

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about downloading the installer to the %TEMP%directory instead as we do in other packages?

Join-Path ${Env:TEMP} $installerName

This way we don't need an extra dependency

packages/googlechrome.vm/tools/chocolateyinstall.ps1 Outdated Show resolved Hide resolved
packages/googlechrome.vm/tools/chocolateyinstall.ps1 Outdated Show resolved Hide resolved
try {
if ($sigValid) {
$toolName = 'Google Chrome'
$category = 'Utilities'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using the category? I think we don't need to add Chrome to any category, just install it in the system, as it is a dependency for other tools (cyberchef) not really an analysis tool.

Copy link
Contributor Author

@binjo binjo Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lint required the $category, otherwise the CI won't be happy 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the package to the exclusions for this linter rule instead: https://github.com/mandiant/VM-Packages/blob/main/scripts/test/lint.py#L308 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still here 👀

packages/googlechrome.vm/tools/chocolateyinstall.ps1 Outdated Show resolved Hide resolved
packages/googlechrome.vm/tools/chocolateyinstall.ps1 Outdated Show resolved Hide resolved
binjo and others added 4 commits December 12, 2023 17:01
Co-authored-by: Ana María Martínez Gómez <[email protected]>
Co-authored-by: Ana María Martínez Gómez <[email protected]>
packages/googlechrome.vm/tools/chocolateyinstall.ps1 Outdated Show resolved Hide resolved
$installer = 'googlechromeinstaller.msi'
$packageArgs = @{
packageName = $env:ChocolateyPackageName
file = Join-Path $downloadDir $installer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should save this to a variable to access it as $installerFile instead of $packageArgs['file']. A bit nicer and easier to read.

- **If the package is out of date please check [Version History](#versionhistory) for the latest submitted version. If you have a question, please ask it in [Chocolatey Community Package Discussions](https://github.com/chocolatey-community/chocolatey-packages/discussions) or raise an issue on the [Chocolatey Community Packages Repository](https://github.com/chocolatey-community/chocolatey-packages/issues) if you have problems with the package. Disqus comments will generally not be responded to.**
]]></description>
<dependencies>
<dependency id="chocolatey-core.extension" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about downloading the installer to the %TEMP%directory instead as we do in other packages?

Join-Path ${Env:TEMP} $installerName

This way we don't need an extra dependency

try {
if ($sigValid) {
$toolName = 'Google Chrome'
$category = 'Utilities'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the package to the exclusions for this linter rule instead: https://github.com/mandiant/VM-Packages/blob/main/scripts/test/lint.py#L308 😉

Set-PTA ChromeHTML http
Set-PTA ChromeHTML https
Set-FTA ChromeHTML .htm
Set-FTA ChromeHTML .html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not working perfectly. After installing the package, opening an .html file shows:
Screenshot 2023-12-12 at 12 14 22

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my testing env seems working, after installing cyberchef.vm, the default opening .html file is Chrome without the prompt as yours.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested again in a tested environment and opening the cyberchef lnk to the html file shows this pop up. @binjo how is your testing environment set up?

Disable-Chrome-Updates

# Delete Desktop shortcut
$desktopShortcut = Join-Path ${Env:Public} "Desktop\$toolName.lnk"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct path is

Suggested change
$desktopShortcut = Join-Path ${Env:Public} "Desktop\$toolName.lnk"
$desktopShortcut = Join-Path ${Env:UserProfile} "Desktop\$toolName.lnk"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$Env:Public is correct one, the installer created .lnk is in the public folder, however I just noticed when open the Chrome for the first time, it will create another .lnk which is in $Env:UserProfile 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a good opportunity to add a VM-Delete-Desktop-Shortcut function that just checks both directories. Maybe not required for this PR but that function has been on my list for a while

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested again, the installer created .lnk file is in the public folder, after install cyberchef.vm and open the .html file, a new Chrome .lnk shortcut file appeared in $Env:UserProfile. This looks infeasible for post install deletion.

Copy link
Member

@Ana06 Ana06 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could open chrome in the installer, close it, and then delete the lnk. But it seems the link also appears if I run Stop-Process -Name explorer -Force. Strange 😩

packages/googlechrome.vm/tools/chocolateyuninstall.ps1 Outdated Show resolved Hide resolved
try {
if ($sigValid) {
$toolName = 'Google Chrome'
$category = 'Utilities'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still here 👀

# Download the installer
$packageArgs['file'] = Get-ChocolateyWebFile @packageArgs

$sigValid = (Get-AuthenticodeSignature -FilePath $packageArgs['file']).Status -eq 'Valid'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is enough with checking that it has a valid signature of if we need to check that the signer certificate comes from Google Chrome as well? @vm-packages opinions? (We can extract this signature to a helper for other tools in the future, so it is a general question)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another function that has been on my list; VM-Assert-Signature. I think we should maybe open a PR for this function and hash it out there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think I'd be ok with just checking if it is Valid since that will check it against CAs, so self signed binaries wont be shown as valid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@day1player I think we should either introduce VM-Assert-Signature or a helper function to install tools using the signature instead of the hash.

@Ana06 Ana06 added 🆕 package New package request/idea/PR 🌀 FLARE-VM A package or feature to be used by FLARE-VM 🌀 COMMANDO-VM A package or future to be used by COMMANDO VM labels Dec 12, 2023
}

# https://github.com/chocolatey-community/chocolatey-packages/blob/master/extensions/chocolatey-core.extension/extensions/Get-PackageCacheLocation.ps1
function Get-PackageCacheLocation {
Copy link
Member

@Ana06 Ana06 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this function needed? I think this is equivalent to using Join-Path ${Env:TEMP} $installerName directly as we do in other packages

Set-PTA ChromeHTML http
Set-PTA ChromeHTML https
Set-FTA ChromeHTML .htm
Set-FTA ChromeHTML .html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested again in a tested environment and opening the cyberchef lnk to the html file shows this pop up. @binjo how is your testing environment set up?

Disable-Chrome-Updates

# Delete Desktop shortcut
$desktopShortcut = Join-Path ${Env:Public} "Desktop\$toolName.lnk"
Copy link
Member

@Ana06 Ana06 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could open chrome in the installer, close it, and then delete the lnk. But it seems the link also appears if I run Stop-Process -Name explorer -Force. Strange 😩

<id>googlechrome.vm</id>
<version>0.0.0.20231210</version>
<authors>Mandiant</authors>
<description>Chrome is a fast, simple, and secure web browser, built for the modern web.</description>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] I would short this description

<metadata>
<id>googlechrome.vm</id>
<version>0.0.0.20231210</version>
<authors>Mandiant</authors>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should contain the authors of the tool

Suggested change
<authors>Mandiant</authors>
<authors>Google LLC.</authors>

$installer = 'googlechromeinstaller.msi'
$packageArgs = @{
packageName = $env:ChocolateyPackageName
file = Join-Path $downloadDir $installer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation Get-ChocolateyWebFile needs fileFullPath. Maybe it works because it is the second argument. 🤔

. $toolsPath\helpers.ps1

$downloadDir = Get-PackageCacheLocation
$installer = 'googlechromeinstaller.msi'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] I would remove this variable as it is only used once

Comment on lines +16 to +18
fileType = 'MSI'
silentArgs = "/quiet /norestart /l*v `"$($env:TEMP)\$($env:chocolateyPackageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
validExitCodes = @(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fileType = 'MSI'
silentArgs = "/quiet /norestart /l*v `"$($env:TEMP)\$($env:chocolateyPackageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
validExitCodes = @(0)

I think we should use different arguments for Install-ChocolateyInstallPackage and Get-ChocolateyWebFile as they don't really overlap and it makes more difficult to read the code.

Comment on lines +16 to +18
fileType = 'MSI'
silentArgs = "/quiet /norestart /l*v `"$($env:TEMP)\$($env:chocolateyPackageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
validExitCodes = @(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validExitCodes = @(0)is the default, so it can be removed

Set-FTA ChromeHTML .html

VM-Write-Log "INFO" "Disable update settings"
Disable-Chrome-Updates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binjo disabling updates was not part of the open issues related to chrome, why do you think is needed?

Does anyone has any concern with possible side-effects? 🤔

@Ana06
Copy link
Member

Ana06 commented Jan 11, 2024

I have extracted the signature validation and creation of chrome #824 to this PR: #824

I have extracted the rest of the discussions in this PR to the following issues:

I think this will make the review/discussion process a bit easier. 😉

@Ana06 Ana06 closed this Jan 11, 2024
@binjo binjo deleted the add-googlechrome branch March 25, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌀 COMMANDO-VM A package or future to be used by COMMANDO VM 🌀 FLARE-VM A package or feature to be used by FLARE-VM 🆕 package New package request/idea/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants