From 0d2c059ead3aa27d80403fd636ece7c423d161c7 Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Tue, 14 May 2024 15:12:54 +0200 Subject: [PATCH 1/2] Add obfuscator-io-deobfuscator.vm Introduce `VM-Install-Node-Tool` to easily create packages that use `npm` to install tools published on the JavaScript Package Registry. Use `VM-Install-Node-Tool` to add `obfuscator-io-deobfuscator`. --- packages/common.vm/common.vm.nuspec | 2 +- .../common.vm/tools/vm.common/vm.common.psm1 | 20 +++++++++++++++++++ .../obfuscator-io-deobfuscator.vm.nuspec | 13 ++++++++++++ .../tools/chocolateyinstall.ps1 | 7 +++++++ .../tools/chocolateyuninstall.ps1 | 7 +++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 packages/obfuscator-io-deobfuscator.vm/obfuscator-io-deobfuscator.vm.nuspec create mode 100644 packages/obfuscator-io-deobfuscator.vm/tools/chocolateyinstall.ps1 create mode 100644 packages/obfuscator-io-deobfuscator.vm/tools/chocolateyuninstall.ps1 diff --git a/packages/common.vm/common.vm.nuspec b/packages/common.vm/common.vm.nuspec index d45420aa2..01dc50779 100755 --- a/packages/common.vm/common.vm.nuspec +++ b/packages/common.vm/common.vm.nuspec @@ -2,7 +2,7 @@ common.vm - 0.0.0.20240509 + 0.0.0.20240514 Common libraries for VM-packages Mandiant diff --git a/packages/common.vm/tools/vm.common/vm.common.psm1 b/packages/common.vm/tools/vm.common/vm.common.psm1 index 039f56e5c..71eabf443 100755 --- a/packages/common.vm/tools/vm.common/vm.common.psm1 +++ b/packages/common.vm/tools/vm.common/vm.common.psm1 @@ -454,6 +454,26 @@ function VM-Install-From-Zip { } } +function VM-Install-Node-Tool { + [CmdletBinding()] + [OutputType([System.Object[]])] + Param + ( + [Parameter(Mandatory=$true, Position=0)] + [string] $toolName, + [Parameter(Mandatory=$true, Position=1)] + [string] $category, + [Parameter(Mandatory=$false)] + [string] $arguments + ) + try { + npm install -g $toolName --no-update-notifier + VM-Install-Shortcut -toolName $toolName -category $category -arguments "$toolName $arguments" -powershell + } catch { + VM-Write-Log-Exception $_ + } +} + function VM-Install-Node-Tool-From-Zip { [CmdletBinding()] [OutputType([System.Object[]])] diff --git a/packages/obfuscator-io-deobfuscator.vm/obfuscator-io-deobfuscator.vm.nuspec b/packages/obfuscator-io-deobfuscator.vm/obfuscator-io-deobfuscator.vm.nuspec new file mode 100644 index 000000000..0a9f66db8 --- /dev/null +++ b/packages/obfuscator-io-deobfuscator.vm/obfuscator-io-deobfuscator.vm.nuspec @@ -0,0 +1,13 @@ + + + + obfuscator-io-deobfuscator.vm + 0.0.0.20240514 + ben-sb + A deobfuscator for scripts obfuscated by Obfuscator.io + + + + + + diff --git a/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyinstall.ps1 b/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyinstall.ps1 new file mode 100644 index 000000000..267688cea --- /dev/null +++ b/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyinstall.ps1 @@ -0,0 +1,7 @@ +$ErrorActionPreference = 'Stop' +Import-Module vm.common -Force -DisableNameChecking + +$toolName = 'obfuscator-io-deobfuscator' +$category = 'Javascript' + +VM-Install-Node-Tool -toolName $toolName -category $category -arguments "--help" diff --git a/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyuninstall.ps1 b/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyuninstall.ps1 new file mode 100644 index 000000000..60e8aa54b --- /dev/null +++ b/packages/obfuscator-io-deobfuscator.vm/tools/chocolateyuninstall.ps1 @@ -0,0 +1,7 @@ +$ErrorActionPreference = 'Continue' +Import-Module vm.common -Force -DisableNameChecking + +$toolName = 'obfuscator-io-deobfuscator' +$category = 'Javascript' + +VM-Remove-Tool-Shortcut $toolName $category From bb9c77e7871079dfd0aea94f88788fb1fee4380c Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Wed, 15 May 2024 12:43:04 +0200 Subject: [PATCH 2/2] Simplify VM-Install-Node-Tool-From-Zip code Simplify the code of the `VM-Install-Node-Tool-From-Zip` function helper and keep it consistent with the recently introduced helper function: `VM-Install-Node-Tool` --- packages/common.vm/tools/vm.common/vm.common.psm1 | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/common.vm/tools/vm.common/vm.common.psm1 b/packages/common.vm/tools/vm.common/vm.common.psm1 index 71eabf443..54c78421a 100755 --- a/packages/common.vm/tools/vm.common/vm.common.psm1 +++ b/packages/common.vm/tools/vm.common/vm.common.psm1 @@ -493,17 +493,10 @@ function VM-Install-Node-Tool-From-Zip { [Parameter(Mandatory=$false)] [bool] $innerFolder=$true # Default to true as most node apps are GH repos (ZIP with inner folder) ) - # Install dependencies with npm when running shortcut as we ignore errors below - $powershellCommand = "npm install; node $command" + $toolDir = (VM-Install-From-Zip $toolName $category $zipUrl $zipSha256 -innerFolder $innerFolder -powershellCommand "node $command")[0] - $toolDir = (VM-Install-From-Zip $toolName $category $zipUrl $zipSha256 -innerFolder $innerFolder -powershellCommand $powershellCommand)[0] - - # Prevent the following warning from failing the package: "npm WARN deprecated request@2.79.0" - $ErrorActionPreference = 'Continue' - # Get absolute path as npm may not be in PATH until Powershell is restarted - $npmPath = Join-Path ${Env:ProgramFiles} "\nodejs\npm.cmd" -Resolve # Install tool dependencies with npm - Set-Location $toolDir; & "$npmPath" install | Out-Null + Set-Location $toolDir; npm install --no-update-notifier } # This functions returns $executablePath