Skip to content

Instantly share code, notes, and snippets.

@xtrasimplicity
Created April 23, 2024 00:57
Show Gist options
  • Save xtrasimplicity/131754c19f6f8ca70191092110138fde to your computer and use it in GitHub Desktop.
Save xtrasimplicity/131754c19f6f8ca70191092110138fde to your computer and use it in GitHub Desktop.
Action1 - Installed Web Browser Extensions (Data Source)
# Find all user profiles
$users = Get-ChildItem C:\Users -Directory -Exclude '*Public*', '*Default*'
function Get-Extension-Name-For-Edge($extensionId) {
$url = "https://microsoftedge.microsoft.com/addons/detail/$($extensionId)"
$WebRequest = Invoke-WebRequest -Uri $url -ErrorAction Stop -UseBasicParsing
if ($WebRequest.StatusCode -ne 200) {
return "Unknown - $($extensionId)";
}
$matches = Select-String -Pattern "<title>(.*)</title>" -InputObject $WebRequest.Content
$extensionTitle = $matches.Matches.groups[0].Value.toString().Replace("<title>", "").Replace("</title>", "")
if ($extensionTitle -imatch "- Microsoft Edge Addons") { $extensionTitle = $extensionTitle.Replace("- Microsoft Edge Addons", "") }
$extensionTitle
}
function Get-ChromeExtensions-For-User($user) {
$extensions = New-Object -TypeName System.Collections.ArrayList;
if (Test-Path "C:\Users\$($user.name)\AppData\Local\Google\Chrome\User Data\Default\Extensions") {
$checks = Get-ChildItem -Path "C:\Users\$($user.name)\AppData\Local\Google\Chrome\User Data\Default\Extensions" -Directory -Exclude 'nmmhkkegccagdldgiimedpiccmgmieda', 'mhjfbmdgcfjbbpaeojofohoefgiehjai', 'pkedcjkdefgpdelpbcmbmeomcjbeemfm', "Temp" -Verbose -ErrorAction Stop
} else {
$Title = Write-Output "no extensions found"
}
Foreach ($check in $checks) {
$url = "https://chrome.google.com/webstore/detail/" + $($check.name) + "?hl=en-us"
$WebRequest = Invoke-WebRequest -Uri $url -ErrorAction Stop -UseBasicParsing
$matches = Select-String -Pattern "<title>(.*)</title>" -InputObject $WebRequest.Content
$extensionTitle = $matches.Matches.groups[0].Value.toString().Replace("<title>", "").Replace("</title>", "")
if ($WebRequest.StatusCode -eq 200) {
# Get the HTML Page Title but remove ' – Chrome Web Store'
if (-not ([string]::IsNullOrEmpty($extensionTitle))) {
$ExtTitle = $extensionTitle
if ($ExtTitle -match '\s-\s.*$') {
$Title = $ExtTitle -replace '\s-\s.*$', ""
$extType = 'ChromeStore'
} else {
$Title = $ExtTitle
}
}
$extensions.add([PSCustomObject] [Ordered]@{
Browser = "Chrome"
ExtensionTitle = $Title
User = $User
ExtensionId = $check.name
})
}
}
$extensions
}
function Get-EdgeExtensions-For-User($user) {
$extensions = New-Object -TypeName System.Collections.ArrayList;
$extensionPath = "C:\Users\$($user.name)\AppData\Local\Microsoft\Edge\User Data\Default\Extensions"
if (-not (Test-Path $extensionPath)) {
return
}
foreach($extension in Get-ChildItem -Path $extensionPath -Filter manifest.json -Recurse) {
$extensionId = ($extension.DirectoryName.Replace($extensionPath, "") -split "\\")[1]
If (($extensionID -eq $null) -or ($extensionId.Length -le 0)) { return; }
$ext = Get-Content -Path $extension.Fullname | ConvertFrom-Json | Select-Object Author, Name, Description, Browser_Action
$extensionName = if ($ext.name -imatch "__MSG_") { Get-Extension-Name-For-Edge $extensionId } else { $ext.name }
$extensions.Add([PSCustomObject] [Ordered]@{
Browser = "Edge"
ExtensionTitle = $extensionName
User = $User.name
ExtensionId = $extensionId
})
}
$extensions
}
function Get-FirefoxExtensions-For-User($user) {
$extensions = New-Object -TypeName System.Collections.ArrayList;
$profilesRoot = "C:\Users\$($user.name)\AppData\Roaming\Mozilla\Firefox\Profiles"
if (-not (Test-Path $profilesRoot)) { return }
$extensionJsonFiles = Get-ChildItem -Path $profilesRoot -Filter extensions.json -Recurse
foreach($jsonFile in $extensionJsonFiles) {
$content = (Get-Content -Path $jsonFile.FullName | ConvertFrom-Json).addons
foreach($addon in $content) {
$extensions.Add([PSCustomObject] [Ordered]@{
Browser = "Firefox"
ExtensionTitle = $addon.defaultLocale.name
User = $User.name
ExtensionId = $addon.id
})
}
}
$extensions
}
$extensions = New-Object -TypeName System.Collections.ArrayList;
foreach($user in $users) {
$extensions = $extensions + (Get-ChromeExtensions-For-User $user)
$extensions = $extensions + (Get-EdgeExtensions-For-User $user)
$extensions = $extensions + (Get-FirefoxExtensions-For-User $user)
}
# Output the results
$result = New-Object System.Collections.ArrayList
$i = 0
$extensions | Where { $_.ExtensionId -ne $null } | ForEach-Object {
$currentOutput = "" | Select-Object Browser, ExtensionTitle, User, ExtensionId, A1_Key
$currentOutput.Browser = $_.Browser
$currentOutput.ExtensionTitle = $_.ExtensionTitle
$currentOutput.User = $_.User
$currentOutput.ExtensionId = $_.ExtensionId
$currentOutput.A1_Key = $i
$result.Add($currentOutput) | Out-Null
$i++
}
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment