VM-Packages icon indicating copy to clipboard operation
VM-Packages copied to clipboard

Configuration: Add Cyberchef to Chrome settings

Open Ana06 opened this issue 1 year ago • 2 comments

Details

Add the following to the cyberchef.vm (needs https://github.com/mandiant/VM-Packages/issues/296):

  • Add CyberChef to bookmark bar in Chrome
  • Add Cyberchef to chrome://settings/onStartup

~~Add the following to googlechrome.vm (to be created in #469):~~

  • ~~Set Chrome to default for .html files~~
  • ~~Set Chrome as default browser (Default apps)~~

Ana06 avatar Oct 26 '23 08:10 Ana06

adding CyberChef to bookmark bar is a bit tricky, as when fresh installation, the Google Chrome's bookmarks file and related user default directories are not created yet. The following code snippet works when the bookmarks file exists:

# https://stackoverflow.com/questions/10813221/adding-bookmark-to-web-browser-from-external-applications
function Add-Chrome-Bookmark {
    Param
    (
        [Parameter(Mandatory=$true, Position=0)]
        [string] $bookMarkName,
        [Parameter(Mandatory=$true, Position=1)]
        [string] $bookMarkUrl
    )
    $fileBookmarks="$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Bookmarks"
    $dirBookmarks = Split-Path $fileBookmarks
    # initial installation does not have the directories
    if (Test-Path $dirBookmarks) {
        $dataBookmarks=Get-Content $fileBookmarks -Encoding UTF8| Out-String |ConvertFrom-Json
    } else {
        New-Item -ItemType Directory -Force -Path $dirBookmarks # this does not work
        $dataBookmarks= "{'roots': {'bookmark_bar': {'children': []}}}" | ConvertFrom-Json
    }
    function createNewChromeBookmark ($Bookmarks, [string]$BookmarkName, [string]$BookmarkURL) {
        function getBookmarkIDs($object){
            $object | ForEach-Object{
                "{0:0000}" -f [int]($_.id);
                if([bool]($_.PSobject.Properties.name -match "children")){
                    GetBookmarkIDs($_.children);
                }
            }
        };
        $nextBookmarkID = [int](getBookmarkIDs -object $Bookmarks.roots.bookmark_bar|Sort-Object -Descending|Select-Object -First 1) + 1
        $currentChomeTime=[System.DateTimeOffset]::Now.ToUnixTimeMilliseconds()*10000;
        $newBookmark= [PSCustomObject]@{
            date_added=$currentChomeTime
            guid=[guid]::NewGuid()
            id=$nextBookMarkID
            name="$BookmarkName"
            type="url"
            url="$BookmarkURL"
        }
        return $newBookmark;
    }
    $newBookmark = createNewChromeBookmark -Bookmarks $dataBookmarks -BookmarkName $bookMarkName -BookmarkURL $bookMarkUrl
    $dataBookmarks.roots.bookmark_bar.children += $newBookmark;
    # [+] Error: The maximum depth allowed for serialization is 100.
    $dataBookmarksJSON = ConvertTo-Json -InputObject $dataBookmarks -Depth 100
    Set-Content -Path $fileBookmarks -Value $dataBookmarksJSON -Encoding UTF8
}

if the script tries to create the directory structure, upon opening the Chrome, the files are overwritten as of my testing

binjo avatar Dec 11 '23 10:12 binjo

Extracting Google Chrome part to the following issues to allow more focused discussions in every of them:

  • https://github.com/mandiant/VM-Packages/issues/823
  • https://github.com/mandiant/VM-Packages/issues/822

Ana06 avatar Jan 11 '24 16:01 Ana06