-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveStoredBrowserPasswords.ps1
More file actions
246 lines (213 loc) · 8.57 KB
/
removeStoredBrowserPasswords.ps1
File metadata and controls
246 lines (213 loc) · 8.57 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<#
.SYNOPSIS
Sicherung und Entfernen gespeicherter Passwörter von Edge (Chromium) und Firefox für den aktuellen Benutzer.
.DESCRIPTION
- Erstellt ein Backup-Verzeichnis auf dem Desktop: "BrowserPasswordBackup_YYYYMMDD_HHMMSS"
- Sichert relevante Dateien (Edge: "Login Data" usw.; Firefox: "logins.json", "key4.db" ...)
- Entfernt die Originaldateien (optional: nur Vorschau, wenn -Perform nicht gesetzt)
- Gibt am Ende eine Zusammenfassung aus.
.PARAMETER Perform
Wenn gesetzt, werden die Dateien tatsächlich gelöscht. Wenn nicht gesetzt, läuft das Skript im "Vorschau"-Modus und zeigt an, was es tun würde.
.PARAMETER KillBrowsers
Wenn gesetzt, werden vor der Bereinigung alle laufenden Edge- und Firefox-Prozesse beendet.
.PARAMETER Aggressive
Wenn gesetzt, werden zusätzlich weitere Dateien/Ordner entfernt, die nicht direkt Passwörter betreffen, aber z.B. Cache, HSTS/STS usw.
.EXAMPLE
.\Remove-BrowserPasswords.ps1 -Perform
powershell -ExecutionPolicy Bypass -File .\removeStoredBrowserPasswords.ps1
#>
[CmdletBinding()]
param(
[switch]$Perform,
[switch]$KillBrowsers,
[switch]$Aggressive
)
Write-Host "`n=== Browser-Datenbereinigung (Edge + Firefox) ===`n" -ForegroundColor Cyan
function New-BackupFolder {
$ts = Get-Date -Format "yyyyMMdd_HHmmss"
$path = Join-Path $env:USERPROFILE "Desktop\BrowserDataBackup_$ts"
New-Item -ItemType Directory -Path $path -Force | Out-Null
return $path
}
function Add-Action {
param([ref]$List,[string]$Browser,[string]$Profile,[string]$Path,[string]$Kind,[bool]$Removed,[bool]$BackedUp)
$List.Value.Add([pscustomobject]@{
Browser = $Browser
Profile = $Profile
Item = $Path
Type = $Kind
BackedUp = $BackedUp
Removed = $Removed
}) | Out-Null
}
function Copy-Safe {
param([string]$Source,[string]$BackupRoot)
if (-not (Test-Path $Source)) { return $false, $null }
try {
$name = Split-Path $Source -Leaf
$guid = [guid]::NewGuid().ToString().Substring(0,8)
$dest = Join-Path $BackupRoot ($name + "_" + $guid)
if ((Get-Item $Source) -is [System.IO.DirectoryInfo]) {
Copy-Item $Source $dest -Recurse -Force -ErrorAction Stop
} else {
Copy-Item $Source $dest -Force -ErrorAction Stop
}
return $true, $dest
} catch { return $false, $null }
}
function Remove-Target {
param([string]$Path,[switch]$DoRemove)
if (-not (Test-Path $Path)) { return $false }
if ($DoRemove) {
try {
Remove-Item $Path -Recurse -Force -ErrorAction Stop
return $true
} catch { return $false }
} else {
return $false
}
}
# Optional: laufende Prozesse beenden
if ($KillBrowsers) {
Write-Host "Beende Browserprozesse..." -ForegroundColor Yellow
foreach ($p in @("msedge","msedgewebview2","firefox")) {
Get-Process $p -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
}
}
$backupRoot = New-BackupFolder
Write-Host "Backup-Ordner: $backupRoot`n" -ForegroundColor Green
# Sammelliste
$actions = New-Object System.Collections.Generic.List[object]
# -------------------- EDGE (Chromium) --------------------
$edgeUserData = Join-Path $env:LOCALAPPDATA "Microsoft\Edge\User Data"
if (Test-Path $edgeUserData) {
$edgeProfiles = Get-ChildItem $edgeUserData -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^(Default|Profile \d+)$' }
foreach ($p in $edgeProfiles) {
$browser = "Edge"
$profile = $p.Name
# Dateien/Ordner, die Auto-Login/Session/History/Cache beeinflussen
$edgeFiles = @(
# Passwörter & Autofill
(Join-Path $p.FullName "Login Data"),
(Join-Path $p.FullName "Login Data-journal"),
(Join-Path $p.FullName "Web Data"),
(Join-Path $p.FullName "Web Data-journal"),
# Cookies (Chromium >= 114 liegt unter Network\Cookies)
(Join-Path $p.FullName "Cookies"),
(Join-Path $p.FullName "Cookies-journal"),
(Join-Path $p.FullName "Network\Cookies"),
(Join-Path $p.FullName "Network\Cookies-journal"),
# Sitzungen/Wiederherstellung
(Join-Path $p.FullName "Sessions"),
(Join-Path $p.FullName "Last Session"),
(Join-Path $p.FullName "Last Tabs"),
# Verlauf
(Join-Path $p.FullName "History"),
(Join-Path $p.FullName "History-journal")
)
$edgeDirs = @(
# Cache & Code Cache
(Join-Path $p.FullName "Cache"),
(Join-Path $p.FullName "Code Cache"),
(Join-Path $p.FullName "GPUCache"),
# Site Storage
(Join-Path $p.FullName "Local Storage"),
(Join-Path $p.FullName "IndexedDB"),
(Join-Path $p.FullName "Session Storage"),
(Join-Path $p.FullName "Service Worker"),
(Join-Path $p.FullName "File System"),
(Join-Path $p.FullName "databases"),
(Join-Path $p.FullName "Storage"),
(Join-Path $p.FullName "WebStorage")
)
if ($Aggressive) {
$edgeDirs += @(
(Join-Path $p.FullName "blob_storage"),
(Join-Path $p.FullName "ShaderCache"),
(Join-Path $p.FullName "TransportSecurity")
)
}
foreach ($item in ($edgeFiles + $edgeDirs)) {
if (-not (Test-Path $item)) { continue }
$bkOk,$bkPath = Copy-Safe -Source $item -BackupRoot $backupRoot
$rmOk = Remove-Target -Path $item -DoRemove:$Perform
if ((Get-Item $item) -is [System.IO.DirectoryInfo]) {
$kind = "Folder"
} else {
$kind = "File"
}
Add-Action -List ([ref]$actions) -Browser $browser -Profile $profile -Path $item -Kind $kind -Removed $rmOk -BackedUp $bkOk
}
}
} else {
Write-Host "Edge-Profilpfad nicht gefunden: $edgeUserData" -ForegroundColor DarkYellow
}
# -------------------- FIREFOX --------------------
$ffRoot = Join-Path $env:APPDATA "Mozilla\Firefox\Profiles"
if (Test-Path $ffRoot) {
$ffProfiles = Get-ChildItem $ffRoot -Directory -ErrorAction SilentlyContinue
foreach ($p in $ffProfiles) {
$browser = "Firefox"
$profile = $p.Name
$ffFiles = @(
# Passwörter
(Join-Path $p.FullName "logins.json"),
(Join-Path $p.FullName "logins.json.bak"),
(Join-Path $p.FullName "key4.db"),
(Join-Path $p.FullName "signons.sqlite"), # sehr alt
# Cookies/Verlauf/AutoFill/Sitzungen
(Join-Path $p.FullName "cookies.sqlite"),
(Join-Path $p.FullName "cookies.sqlite-shm"),
(Join-Path $p.FullName "cookies.sqlite-wal"),
(Join-Path $p.FullName "places.sqlite"), # Verlauf/Bookmarks
(Join-Path $p.FullName "formhistory.sqlite"), # Form-Autofill
(Join-Path $p.FullName "sessionstore.jsonlz4")
)
$ffDirs = @(
(Join-Path $p.FullName "sessionstore-backups"),
(Join-Path $p.FullName "cache2"),
(Join-Path $p.FullName "storage"), # LocalStorage/IndexedDB/ServiceWorker
(Join-Path $p.FullName "jumpListCache"),
(Join-Path $p.FullName "startupCache"),
(Join-Path $p.FullName "thumbnails")
)
if ($Aggressive) {
$ffFiles += @(
(Join-Path $p.FullName "favicons.sqlite"),
(Join-Path $p.FullName "siteSecurityServiceState.txt") # HSTS/STS
)
$ffDirs += @(
(Join-Path $p.FullName "safebrowsing"),
(Join-Path $p.FullName "serviceworker")
)
}
foreach ($item in ($ffFiles + $ffDirs)) {
if (-not (Test-Path $item)) { continue }
$bkOk,$bkPath = Copy-Safe -Source $item -BackupRoot $backupRoot
$rmOk = Remove-Target -Path $item -DoRemove:$Perform
if ((Get-Item $item) -is [System.IO.DirectoryInfo]) {
$kind = "Folder"
} else {
$kind = "File"
}
Add-Action -List ([ref]$actions) -Browser $browser -Profile $profile -Path $item -Kind $kind -Removed $rmOk -BackedUp $bkOk
}
}
} else {
Write-Host "Firefox-Profilpfad nicht gefunden: $ffRoot" -ForegroundColor DarkYellow
}
# -------------------- Ausgabe --------------------
if ($actions.Count -eq 0) {
Write-Host "`nKeine relevanten Dateien/Ordner gefunden." -ForegroundColor Yellow
} else {
Write-Host "`nAktionen:" -ForegroundColor Cyan
$actions | Sort-Object Browser,Profile,Item | Format-Table -AutoSize Browser,Profile,Type,Item,BackedUp,Removed
}
if (-not $Perform) {
Write-Host "`nHinweis: Vorschau-Modus – es wurde NICHTS gelöscht." -ForegroundColor Yellow
Write-Host "Zum Ausführen mit Löschen: .\removeBrowserData.ps1 -Perform [-KillBrowsers] [-Aggressive]" -ForegroundColor Gray
} else {
Write-Host "`nBereinigung abgeschlossen. Backup unter: $backupRoot" -ForegroundColor Green
Write-Host "Tipp: In Edge ggf. bei dem Profil oben rechts abmelden bzw. Sync deaktivieren, sonst werden Daten wiederhergestellt." -ForegroundColor DarkGray
}