neustes

Vollständiger Code der „Mobilen Datensonde“ – Ein Lernwerkzeug zur USB-Sicherheit

Autor: DerSchneider


Vorwort: Warum dieser Code?

Dieser Code wurde von mir ausschließlich zu Demonstrations- und Schulungszwecken erstellt. Meine Absicht ist es nicht, Schaden anzurichten oder sensible Daten zu kompromittieren. Im Gegenteil: Ich möchte das Sicherheitsbewusstsein im Umgang mit fremden USB-Geräten schärfen.

Die „Mobile Datensonde“ ist ein pädagogisches Werkzeug, das zeigt, wie schnell und einfach ein scheinbar harmloser USB-Stick dazu verwendet werden kann, ein System zu analysieren und wertvolle Informationen zu sammeln. Der Code ist bewusst transparent und ungefährlich gestaltet – er kopiert keine Dateiinhalte, verändert keine Systemeinstellungen und überträgt keine Daten ins Internet.

Mein Ziel: Dass Sie nach der Lektüre dieses Artikels und dem Test des Codes jeden fremden USB-Stick mit gesundem Misstrauen behandeln und die Risiken verstehen, die von scheinbar harmlosen Wechselmedien ausgehen.


Der vollständige Code

powershell

<#
.SYNOPSIS
Mobile Datensonde - Automatische Dateianalyse für USB-Sticks
.DESCRIPTION
Dieses Skript analysiert Dateien auf einem System und speichert die Ergebnisse
lokal auf dem USB-Stick. Es kann im Hintergrund laufen und ermöglicht die
Auswertung auf jedem beliebigen Windows-Rechner.

WARNUNG: Dies ist ein pädagogisches Werkzeug zur Sensibilisierung für
USB-Sicherheitsrisiken. Es kopiert keine Dateiinhalte, überträgt keine
Daten und verändert keine Systemeinstellungen.
.PARAMETER Mode
"collect" - Sammelt Daten und speichert sie auf dem Stick
"view" - Zeigt gesammelte Daten an
"auto" - Automatischer Modus (erkennt selbst)
.EXAMPLE
.\Datensonde.ps1 -Mode collect
.\Datensonde.ps1 -Mode view
#>

param(
[ValidateSet("collect", "view", "auto")]
[string]$Mode = "auto"
)

# ============================================
# KONFIGURATION
# ============================================

# Stammverzeichnis des Skripts (USB-Stick)
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path

# Verzeichnis für gesammelte Daten
$dataDir = Join-Path -Path $scriptRoot -ChildPath "Daten"
$logDir = Join-Path -Path $dataDir -ChildPath "Logs"
$reportDir = Join-Path -Path $dataDir -ChildPath "Berichte"

# Dateinamen für Datenbanken
$dbFile = Join-Path -Path $dataDir -ChildPath "DateiDatenbank.json"
$statsFile = Join-Path -Path $dataDir -ChildPath "SystemStatistiken.json"
$configFile = Join-Path -Path $dataDir -ChildPath "Konfiguration.json"

# ============================================
# HILFSFUNKTIONEN
# ============================================

function Initialize-Directories {
"""Erstellt alle benötigten Verzeichnisse."""
$dirs = @($dataDir, $logDir, $reportDir)
foreach ($dir in $dirs) {
if (-not (Test-Path $dir)) {
New-Item -Path $dir -ItemType Directory -Force | Out-Null
Write-Host "Verzeichnis erstellt: $dir" -ForegroundColor Green
}
}
}

function Get-USBDriveInfo {
"""Ermittelt Informationen über den USB-Stick."""
$drive = Get-PSDrive -Name $scriptRoot.Substring(0, 2).TrimEnd(':\')
if ($drive) {
return @{
Name = $drive.Name
Root = $drive.Root
Free = [math]::Round($drive.Free / 1GB, 2)
Used = [math]::Round($drive.Used / 1GB, 2)
Total = [math]::Round(($drive.Free + $drive.Used) / 1GB, 2)
}
}
return $null
}

function Write-Log {
param(
[string]$Message,
[string]$Level = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[$timestamp] [$Level] $Message"

$logFile = Join-Path -Path $logDir -ChildPath "Datensonde_$(Get-Date -Format 'yyyyMMdd').log"
Add-Content -Path $logFile -Value $logEntry -Encoding UTF8

switch ($Level) {
"ERROR" { Write-Host $logEntry -ForegroundColor Red }
"WARN" { Write-Host $logEntry -ForegroundColor Yellow }
"INFO" { Write-Host $logEntry -ForegroundColor Cyan }
default { Write-Host $logEntry }
}
}

function Test-UsbStick {
"""Prüft, ob das Skript von einem USB-Stick ausgeführt wird."""
$drive = Get-PSDrive -Name $scriptRoot.Substring(0, 2).TrimEnd(':\')
if ($drive -and $drive.DriveType -eq 'Removable') {
return $true
}
return $false
}

# ============================================
# KATEGORISIERUNG
# ============================================

$categories = @{
"Musik" = @(".mp3", ".wav", ".flac", ".aac", ".ogg", ".wma", ".m4a", ".aiff")
"Videos" = @(".mp4", ".avi", ".mkv", ".mov", ".wmv", ".flv", ".webm", ".m4v", ".mpg")
"Bilder" = @(".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg", ".webp", ".ico")
"Dokumente" = @(".pdf", ".docx", ".xlsx", ".pptx", ".txt", ".rtf", ".odt", ".ods", ".odp", ".csv")
"Archive" = @(".zip", ".rar", ".7z", ".tar", ".gz", ".bz2", ".xz")
"Ausführbar" = @(".exe", ".msi", ".bat", ".cmd", ".ps1", ".vbs", ".js")
"System" = @(".dll", ".sys", ".drv", ".inf", ".ini", ".cfg", ".conf", ".log")
}

# ============================================
# SAMMELMODUS (COLLECT)
# ============================================

function Start-Collection {
"""Hauptfunktion für die Datensammlung."""

Write-Log "=== STARTE DATENSAMMLUNG ===" "INFO"

# Systeminformationen erfassen
$systemInfo = @{
Hostname = $env:COMPUTERNAME
Username = $env:USERNAME
Betriebssystem = (Get-CimInstance Win32_OperatingSystem).Caption
Systemtyp = $env:PROCESSOR_ARCHITECTURE
RAM = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
Datum = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
USBStick = Get-USBDriveInfo
}

Write-Log "System: $($systemInfo.Hostname) ($($systemInfo.Username))" "INFO"

# Laufwerke auswählen - NUR INTERNE LAUFWERKE, NICHT DER USB-STICK SELBST
$allDrives = Get-PSDrive -PSProvider 'FileSystem' |
Where-Object { $_.Used -gt 0 -and $_.DriveType -ne 'Removable' } |
Select-Object -ExpandProperty Root

if ($allDrives.Count -eq 0) {
Write-Log "Keine internen Laufwerke gefunden!" "WARN"
Write-Host "Keine internen Laufwerke zum Analysieren verfügbar." -ForegroundColor Yellow
return $null
}

Write-Log "Folgende Laufwerke verfügbar: $($allDrives -join ', ')" "INFO"

# Sammelkonfiguration
$config = @{
Laufwerke = $allDrives
Kategorien = $categories.Keys
MaximaleTiefe = 10
IgnoriereOrdner = @("Windows", "Program Files", "Program Files (x86)", "System32", "Temp", "Cache", "AppData")
MinimaleDateigroesseMB = 0
MaximalDateienProOrdner = 10000
Ausnahmen = @(".tmp", ".temp", ".cache", ".thumb", ".log")
}

# Konfiguration speichern
$config | ConvertTo-Json -Depth 10 | Set-Content -Path $configFile -Encoding UTF8
Write-Log "Konfiguration gespeichert" "INFO"

# Dateien sammeln
$allFiles = @()
$processedDirs = 0
$skippedDirs = 0
$totalFiles = 0
$errors = 0

foreach ($path in $allDrives) {
Write-Log "Durchsuche Laufwerk: $path" "INFO"
Write-Host "Durchsuche $path ..." -ForegroundColor Gray

try {
# Nur direkte Unterordner des Laufwerks durchsuchen (nicht den gesamten Baum auf einmal)
$dirs = Get-ChildItem -Path $path -Directory -ErrorAction SilentlyContinue

foreach ($dir in $dirs) {
# Prüfen, ob Ordner ignoriert werden soll
if ($config.IgnoriereOrdner -contains $dir.Name) {
Write-Log "Überspringe Ordner: $($dir.FullName)" "WARN"
$skippedDirs++
continue
}

Write-Log "Verarbeite: $($dir.FullName)" "INFO"
$processedDirs++

# Rekursive Suche mit Begrenzung
try {
$files = Get-ChildItem -Path $dir.FullName -Recurse -File -ErrorAction SilentlyContinue |
Where-Object {
$sizeOK = $_.Length -ge ($config.MinimaleDateigroesseMB * 1MB)
$extOK = $_.Extension -notin $config.Ausnahmen
$nameOK = $_.Name -notmatch '^(temp|tmp|cache|thumb)'
return $sizeOK -and $extOK -and $nameOK
}
} catch {
Write-Log "Fehler beim Durchsuchen von $($dir.FullName): $_" "ERROR"
$errors++
continue
}

$fileCount = $files.Count
$totalFiles += $fileCount
Write-Log " -> $fileCount Dateien gefunden" "INFO"

# Begrenzung pro Ordner, um Speicher zu schonen
$filesToProcess = $files | Select-Object -First $config.MaximalDateienProOrdner
if ($files.Count -gt $config.MaximalDateienProOrdner) {
Write-Log " -> Begrenze auf $($config.MaximalDateienProOrdner) Dateien" "WARN"
}

# Jede Datei analysieren
foreach ($file in $filesToProcess) {
try {
$fileInfo = @{
Pfad = $file.DirectoryName
Dateiname = $file.Name
VollständigerPfad = $file.FullName
Erweiterung = $file.Extension.ToLower()
GrößeBytes = $file.Length
GrößeMB = [math]::Round($file.Length / 1MB, 2)
GrößeGB = [math]::Round($file.Length / 1GB, 4)
Erstellungsdatum = $file.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")
Änderungsdatum = $file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
Zugriffsdatum = $file.LastAccessTime.ToString("yyyy-MM-dd HH:mm:ss")
System = $systemInfo.Hostname
Benutzer = $systemInfo.Username
Erfassungsdatum = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Kategorie = ""
DateiTyp = $file.Extension.TrimStart('.').ToUpper()
IstVersteckt = $file.Attributes -match "Hidden"
IstSystem = $file.Attributes -match "System"
IstArchiv = $file.Attributes -match "Archive"
}

# Kategorie zuweisen
foreach ($cat in $categories.Keys) {
if ($fileInfo.Erweiterung -in $categories[$cat]) {
$fileInfo.Kategorie = $cat
break
}
}

$allFiles += $fileInfo
} catch {
Write-Log "Fehler beim Verarbeiten von $($file.FullName): $_" "ERROR"
$errors++
}
}
}
} catch {
Write-Log "Fehler beim Durchsuchen von $path: $_" "ERROR"
$errors++
}
}

Write-Log "=== SAMMLUNG ABGESCHLOSSEN ===" "INFO"
Write-Host ""
Write-Host "Sammlungsstatistik:" -ForegroundColor Yellow
Write-Host " Verarbeitete Ordner: $processedDirs" -ForegroundColor Gray
Write-Host " Übersprungene Ordner: $skippedDirs" -ForegroundColor Gray
Write-Host " Gefundene Dateien: $totalFiles" -ForegroundColor Gray
Write-Host " Fehler: $errors" -ForegroundColor Gray

if ($allFiles.Count -eq 0) {
Write-Log "Keine Dateien gefunden!" "WARN"
Write-Host "Keine Dateien gefunden. Bitte prüfen Sie die Laufwerke." -ForegroundColor Yellow
return $null
}

# Datenbank speichern
try {
$jsonData = $allFiles | ConvertTo-Json -Depth 10
$jsonData | Set-Content -Path $dbFile -Encoding UTF8
$dbSize = [math]::Round(($jsonData.Length / 1MB), 2)
Write-Log "Datenbank gespeichert: $dbFile ($dbSize MB)" "INFO"
Write-Host "Datenbank gespeichert: $dbSize MB" -ForegroundColor Green
} catch {
Write-Log "Fehler beim Speichern der Datenbank: $_" "ERROR"
return $null
}

# Statistiken erstellen
$statistics = @{
System = $systemInfo
Erfassungsdatum = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
GesamtDateien = $allFiles.Count
Kategorien = @{}
TopDateien = $allFiles | Sort-Object -Property GrößeBytes -Descending | Select-Object -First 20
Erweiterungen = $allFiles | Group-Object -Property Erweiterung |
Select-Object Name, Count |
Sort-Object -Property Count -Descending |
Select-Object -First 10
GrößteOrdner = $allFiles | Group-Object -Property Pfad |
ForEach-Object {
@{
Pfad = $_.Name
Anzahl = $_.Count
GrößeGB = [math]::Round(($_.Group | Measure-Object -Property GrößeBytes -Sum).Sum / 1GB, 2)
}
} |
Sort-Object -Property GrößeGB -Descending |
Select-Object -First 10
DateiAlter = @{
JüngerAls1Monat = ($allFiles | Where-Object { [datetime]$_.Änderungsdatum -gt (Get-Date).AddMonths(-1) }).Count
JüngerAls6Monate = ($allFiles | Where-Object { [datetime]$_.Änderungsdatum -gt (Get-Date).AddMonths(-6) }).Count
ÄlterAls1Jahr = ($allFiles | Where-Object { [datetime]$_.Änderungsdatum -lt (Get-Date).AddYears(-1) }).Count
}
Fehler = $errors
VerarbeiteteOrdner = $processedDirs
ÜbersprungeneOrdner = $skippedDirs
DatenbankGrößeMB = $dbSize
}

# Kategorien-Statistik
foreach ($cat in $categories.Keys) {
$count = ($allFiles | Where-Object { $_.Kategorie -eq $cat }).Count
$size = [math]::Round(($allFiles | Where-Object { $_.Kategorie -eq $cat } |
Measure-Object -Property GrößeBytes -Sum).Sum / 1GB, 2)
$statistics.Kategorien[$cat] = @{
Anzahl = $count
GrößeGB = $size
Prozent = if ($allFiles.Count -gt 0) { [math]::Round(($count / $allFiles.Count) * 100, 1) } else { 0 }
}
}

# Statistiken speichern
try {
$statistics | ConvertTo-Json -Depth 10 | Set-Content -Path $statsFile -Encoding UTF8
Write-Log "Statistiken gespeichert: $statsFile" "INFO"
} catch {
Write-Log "Fehler beim Speichern der Statistiken: $_" "ERROR"
}

# Bericht erstellen
Generate-Report -Statistics $statistics -Files $allFiles

Write-Log "=== DATENSAMMLUNG ERFOLGREICH ABGESCHLOSSEN ===" "INFO"
Write-Host ""
Write-Host "DATENSAMMLUNG ABGESCHLOSSEN!" -ForegroundColor Green
Write-Host "$($allFiles.Count) Dateien erfasst" -ForegroundColor Green
Write-Host ""
Write-Host "Wechseln Sie den USB-Stick zu einem anderen Rechner" -ForegroundColor Yellow
Write-Host "und führen Sie das Skript erneut aus, um die Daten anzuzeigen." -ForegroundColor Yellow

return @{
Dateien = $allFiles
Statistiken = $statistics
SystemInfo = $systemInfo
}
}

# ============================================
# ANSICHTSMODUS (VIEW)
# ============================================

function Start-Viewer {
"""Startet den Viewer für die gesammelten Daten."""

Clear-Host
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " MOBILE DATENSONDE - VIEWER" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

# Prüfen, ob Datenbank existiert
if (-not (Test-Path $dbFile)) {
Write-Host "Keine Datenbank gefunden!" -ForegroundColor Red
Write-Host "Bitte führen Sie zuerst den Sammelmodus aus." -ForegroundColor Yellow
Read-Host "Drücken Sie Enter zum Beenden"
return
}

# Daten laden
Write-Host "Lade Datenbank..." -ForegroundColor Cyan
try {
$files = Get-Content -Path $dbFile -Encoding UTF8 | ConvertFrom-Json
Write-Host "$($files.Count) Dateien geladen" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host "Fehler beim Laden der Datenbank: $_" -ForegroundColor Red
Read-Host "Drücken Sie Enter zum Beenden"
return
}

# Statistiken laden
$stats = $null
if (Test-Path $statsFile) {
try {
$stats = Get-Content -Path $statsFile -Encoding UTF8 | ConvertFrom-Json
$systemInfo = $stats.System
Write-Host "System: $($systemInfo.Hostname) ($($systemInfo.Username))" -ForegroundColor Cyan
Write-Host "Erfassungsdatum: $($systemInfo.Datum)" -ForegroundColor Gray
Write-Host ""
} catch {
Write-Host "Warnung: Statistiken konnten nicht geladen werden." -ForegroundColor Yellow
}
}

# Menü anzeigen
do {
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "MENÜ" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "1) Zusammenfassung anzeigen" -ForegroundColor Green
Write-Host "2) Kategorien anzeigen" -ForegroundColor Green
Write-Host "3) Größte Dateien anzeigen" -ForegroundColor Green
Write-Host "4) Erweiterungen anzeigen" -ForegroundColor Green
Write-Host "5) Ordnerstruktur anzeigen" -ForegroundColor Green
Write-Host "6) Dateien suchen" -ForegroundColor Green
Write-Host "7) Berichte anzeigen" -ForegroundColor Green
Write-Host "8) Exportieren" -ForegroundColor Green
Write-Host "9) Beenden" -ForegroundColor Green
Write-Host ""

$choice = Read-Host "Ihre Auswahl"

switch ($choice) {
"1" { Show-Summary -Files $files -Stats $stats }
"2" { Show-Categories -Files $files -Stats $stats }
"3" { Show-TopFiles -Files $files }
"4" { Show-Extensions -Files $files }
"5" { Show-FolderStructure -Files $files }
"6" { Search-Files -Files $files }
"7" { Show-Reports }
"8" { Export-Data -Files $files -Stats $stats }
"9" { break }
default { Write-Host "Ungültige Auswahl!" -ForegroundColor Red }
}

if ($choice -ne "9") {
Write-Host ""
Read-Host "Drücken Sie Enter, um fortzufahren"
Clear-Host
}

} while ($choice -ne "9")
}

function Show-Summary {
param($Files, $Stats)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "ZUSAMMENFASSUNG" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

if ($Stats) {
Write-Host "Systeminformationen:" -ForegroundColor Cyan
Write-Host " Hostname: $($Stats.System.Hostname)" -ForegroundColor Gray
Write-Host " Benutzer: $($Stats.System.Username)" -ForegroundColor Gray
Write-Host " Betriebssystem: $($Stats.System.Betriebssystem)" -ForegroundColor Gray
Write-Host " RAM: $($Stats.System.RAM) GB" -ForegroundColor Gray
Write-Host " Erfassungsdatum: $($Stats.Erfassungsdatum)" -ForegroundColor Gray
Write-Host ""
Write-Host "Dateistatistik:" -ForegroundColor Cyan
Write-Host " Gesamt Dateien: $($Stats.GesamtDateien)" -ForegroundColor Yellow
$totalSizeGB = [math]::Round(($Files | Measure-Object -Property GrößeGB -Sum).Sum, 2)
Write-Host " Gesamtspeicherverbrauch: $totalSizeGB GB" -ForegroundColor Yellow
$avgSizeMB = [math]::Round(($Files | Measure-Object -Property GrößeMB -Average).Average, 2)
Write-Host " Durchschnittliche Dateigröße: $avgSizeMB MB" -ForegroundColor Yellow
Write-Host ""
Write-Host "Datei-Alter:" -ForegroundColor Cyan
Write-Host " Jünger als 1 Monat: $($Stats.DateiAlter.JüngerAls1Monat)" -ForegroundColor Gray
Write-Host " Jünger als 6 Monate: $($Stats.DateiAlter.JüngerAls6Monate)" -ForegroundColor Gray
Write-Host " Älter als 1 Jahr: $($Stats.DateiAlter.ÄlterAls1Jahr)" -ForegroundColor Gray
Write-Host ""
Write-Host "Verarbeitung:" -ForegroundColor Cyan
Write-Host " Verarbeitete Ordner: $($Stats.VerarbeiteteOrdner)" -ForegroundColor Gray
Write-Host " Übersprungene Ordner: $($Stats.ÜbersprungeneOrdner)" -ForegroundColor Gray
Write-Host " Fehler: $($Stats.Fehler)" -ForegroundColor Gray
Write-Host " Datenbankgröße: $($Stats.DatenbankGrößeMB) MB" -ForegroundColor Gray
} else {
Write-Host "Keine Statistiken verfügbar." -ForegroundColor Yellow
Write-Host "Gesamt Dateien: $($Files.Count)" -ForegroundColor Green
$totalSizeGB = [math]::Round(($Files | Measure-Object -Property GrößeGB -Sum).Sum, 2)
Write-Host "Gesamtspeicherverbrauch: $totalSizeGB GB" -ForegroundColor Green
}
}

function Show-Categories {
param($Files, $Stats)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "KATEGORIEN" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

if ($Stats -and $Stats.Kategorien) {
# Tabelle erstellen
Write-Host ("Kategorie".PadRight(15) + "Anzahl".PadRight(10) + "Größe (GB)".PadRight(15) + "Anteil") -ForegroundColor Cyan
Write-Host ("----------".PadRight(15) + "------".PadRight(10) + "----------".PadRight(15) + "------") -ForegroundColor Cyan

foreach ($cat in $Stats.Kategorien.PSObject.Properties) {
$name = $cat.Name.PadRight(15)
$count = $cat.Value.Anzahl.ToString().PadRight(10)
$size = $cat.Value.GrößeGB.ToString().PadRight(15)
$percent = $cat.Value.Prozent.ToString() + "%"
Write-Host "$name$count$size$percent" -ForegroundColor Green
}
Write-Host ""

# Balkendiagramm für Kategorien
Write-Host "Verteilung (Balkendiagramm):" -ForegroundColor Yellow
$maxCount = ($Stats.Kategorien.PSObject.Properties | Measure-Object -Property Value -Maximum).Maximum.Anzahl
if ($maxCount -gt 0) {
foreach ($cat in $Stats.Kategorien.PSObject.Properties | Sort-Object { $_.Value.Anzahl } -Descending) {
$barLength = [math]::Max(1, [math]::Round(($cat.Value.Anzahl / $maxCount) * 40))
$bar = "█" * $barLength
Write-Host "$($cat.Name.PadRight(12)): $bar ($($cat.Value.Anzahl))" -ForegroundColor Green
}
} else {
Write-Host "Keine Dateien in Kategorien gefunden." -ForegroundColor Yellow
}
} else {
# Manuelle Berechnung wenn keine Stats vorhanden
$categoriesGrouped = $Files | Group-Object -Property Kategorie | Where-Object { $_.Name -ne "" }
foreach ($group in $categoriesGrouped) {
$size = [math]::Round(($group.Group | Measure-Object -Property GrößeGB -Sum).Sum, 2)
Write-Host "$($group.Name): $($group.Count) Dateien, $size GB" -ForegroundColor Green
}
}
}

function Show-TopFiles {
param($Files)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "GRÖSSTE DATEIEN" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

$top = $Files | Sort-Object -Property GrößeGB -Descending | Select-Object -First 20

Write-Host ("Pos.".PadRight(5) + "Dateiname".PadRight(35) + "Größe (GB)".PadRight(15) + "Kategorie".PadRight(15) + "Pfad") -ForegroundColor Cyan
Write-Host ("----".PadRight(5) + "---------".PadRight(35) + "----------".PadRight(15) + "---------".PadRight(15) + "----") -ForegroundColor Cyan

$i = 1
foreach ($file in $top) {
$pos = "$i.".PadRight(5)
$name = if ($file.Dateiname.Length -gt 30) { $file.Dateiname.Substring(0, 27) + "..." } else { $file.Dateiname.PadRight(35) }
$size = $file.GrößeGB.ToString().PadRight(15)
$cat = ($file.Kategorie -as [string]).PadRight(15)
$path = if ($file.Pfad.Length -gt 30) { $file.Pfad.Substring(0, 27) + "..." } else { $file.Pfad.PadRight(30) }

Write-Host "$pos$name$size$cat$path" -ForegroundColor Green
$i++
}
}

function Show-Extensions {
param($Files)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "DATEI-ERWEITERUNGEN" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

$extensions = $Files | Group-Object -Property Erweiterung |
Where-Object { $_.Name -ne "" } |
Sort-Object -Property Count -Descending |
Select-Object -First 20

Write-Host ("Erweiterung".PadRight(15) + "Anzahl".PadRight(10) + "Größe (GB)".PadRight(15) + "Anteil") -ForegroundColor Cyan
Write-Host ("----------".PadRight(15) + "------".PadRight(10) + "----------".PadRight(15) + "------") -ForegroundColor Cyan

$totalFiles = $Files.Count
foreach ($ext in $extensions) {
$name = $ext.Name.PadRight(15)
$count = $ext.Count.ToString().PadRight(10)
$size = [math]::Round(($ext.Group | Measure-Object -Property GrößeGB -Sum).Sum, 2).ToString().PadRight(15)
$percent = [math]::Round(($ext.Count / $totalFiles) * 100, 1).ToString() + "%"

Write-Host "$name$count$size$percent" -ForegroundColor Green
}
}

function Show-FolderStructure {
param($Files)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "ORDNERSTRUKTUR" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

$folders = $Files | Group-Object -Property Pfad |
ForEach-Object {
@{
Pfad = $_.Name
Anzahl = $_.Count
GrößeGB = [math]::Round(($_.Group | Measure-Object -Property GrößeGB -Sum).Sum, 2)
}
} |
Sort-Object -Property GrößeGB -Descending |
Select-Object -First 10

foreach ($folder in $folders) {
Write-Host "`n$($folder.Pfad)" -ForegroundColor Cyan
Write-Host " Anzahl: $($folder.Anzahl) Dateien" -ForegroundColor Gray
Write-Host " Größe: $($folder.GrößeGB) GB" -ForegroundColor Gray
}
}

function Search-Files {
param($Files)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "DATEIEN SUCHEN" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

$searchTerm = Read-Host "Suchbegriff (Dateiname enthält)"

if ([string]::IsNullOrWhiteSpace($searchTerm)) {
Write-Host "Kein Suchbegriff eingegeben" -ForegroundColor Red
return
}

$results = $Files | Where-Object { $_.Dateiname -like "*$searchTerm*" }

if ($results.Count -eq 0) {
Write-Host "Keine Dateien gefunden" -ForegroundColor Yellow
return
}

Write-Host "`n$($results.Count) Dateien gefunden:" -ForegroundColor Green
Write-Host ""

$results | Select-Object -First 50 | ForEach-Object {
Write-Host "$($_.Dateiname)" -ForegroundColor Cyan
Write-Host " Pfad: $($_.Pfad)" -ForegroundColor Gray
Write-Host " Größe: $($_.GrößeMB) MB" -ForegroundColor Gray
Write-Host " Änderungsdatum: $($_.Änderungsdatum)" -ForegroundColor Gray
Write-Host ""
}

if ($results.Count -gt 50) {
Write-Host "... und $($results.Count - 50) weitere Dateien" -ForegroundColor Yellow
}
}

function Show-Reports {
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "BERICHTE" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

if (-not (Test-Path $reportDir)) {
Write-Host "Kein Berichtsverzeichnis vorhanden." -ForegroundColor Yellow
return
}

$reports = Get-ChildItem -Path $reportDir -Filter "*.html" | Sort-Object LastWriteTime -Descending

if ($reports.Count -eq 0) {
Write-Host "Keine Berichte vorhanden." -ForegroundColor Yellow
return
}

Write-Host "Verfügbare Berichte:" -ForegroundColor Green
$i = 1
foreach ($report in $reports) {
Write-Host "$i) $($report.Name) ($([math]::Round($report.Length / 1KB, 1)) KB, $($report.LastWriteTime))" -ForegroundColor Cyan
$i++
}

$choice = Read-Host "Bericht anzeigen (Nummer)"
if ($choice -match '^\d+$' -and [int]$choice -ge 1 -and [int]$choice -le $reports.Count) {
$selectedReport = $reports[[int]$choice - 1]
try {
Start-Process $selectedReport.FullName
Write-Host "Bericht geöffnet: $($selectedReport.Name)" -ForegroundColor Green
} catch {
Write-Host "Fehler beim Öffnen des Berichts: $_" -ForegroundColor Red
}
} else {
Write-Host "Ungültige Auswahl" -ForegroundColor Red
}
}

function Export-Data {
param($Files, $Stats)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "EXPORT" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

Write-Host "1) CSV exportieren (Dateiliste)" -ForegroundColor Green
Write-Host "2) HTML-Bericht exportieren (vollständig)" -ForegroundColor Green
Write-Host "3) JSON exportieren (Rohdaten)" -ForegroundColor Green
Write-Host ""

$choice = Read-Host "Ihre Auswahl"

# Exportverzeichnis erstellen
$exportDir = Join-Path -Path $reportDir -ChildPath "Exporte"
if (-not (Test-Path $exportDir)) {
New-Item -Path $exportDir -ItemType Directory -Force | Out-Null
}

$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"

switch ($choice) {
"1" {
$csvFile = Join-Path -Path $exportDir -ChildPath "Dateiliste_$timestamp.csv"
try {
$Files | Export-Csv -Path $csvFile -NoTypeInformation -Delimiter ";" -Encoding UTF8
Write-Host "CSV exportiert: $csvFile" -ForegroundColor Green
Start-Process $csvFile
} catch {
Write-Host "Fehler beim Export: $_" -ForegroundColor Red
}
}
"2" {
$htmlFile = Join-Path -Path $exportDir -ChildPath "Bericht_$timestamp.html"
try {
Generate-HTMLReport -Files $Files -Stats $Stats -OutputPath $htmlFile
Write-Host "HTML-Bericht exportiert: $htmlFile" -ForegroundColor Green
Start-Process $htmlFile
} catch {
Write-Host "Fehler beim Export: $_" -ForegroundColor Red
}
}
"3" {
$jsonFile = Join-Path -Path $exportDir -ChildPath "Daten_$timestamp.json"
try {
$Files | ConvertTo-Json -Depth 10 | Set-Content -Path $jsonFile -Encoding UTF8
Write-Host "JSON exportiert: $jsonFile" -ForegroundColor Green
Start-Process $jsonFile
} catch {
Write-Host "Fehler beim Export: $_" -ForegroundColor Red
}
}
default {
Write-Host "Ungültige Auswahl" -ForegroundColor Red
}
}
}

# ============================================
# BERICHT-GENERIERUNG
# ============================================

function Generate-Report {
param($Statistics, $Files)

Write-Log "Generiere Bericht..." "INFO"

$reportFile = Join-Path -Path $reportDir -ChildPath "Bericht_$(Get-Date -Format 'yyyyMMdd_HHmmss').html"

# Gesamtspeicher berechnen
$totalSizeGB = [math]::Round(($Files | Measure-Object -Property GrößeGB -Sum).Sum, 2)
$avgSizeMB = [math]::Round(($Files | Measure-Object -Property GrößeMB -Average).Average, 2)

$html = @"
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mobile Datensonde - Bericht</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 20px; background: #f5f5f5; }
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
h1 { color: #2c3e50; border-bottom: 3px solid #3498db; padding-bottom: 10px; }
h2 { color: #34495e; margin-top: 30px; }
.info-box { background: #ecf0f1; padding: 15px; border-radius: 5px; margin: 10px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 20px 0; }
.stat-item { background: #3498db; color: white; padding: 15px; border-radius: 5px; text-align: center; }
.stat-item .number { font-size: 28px; font-weight: bold; }
.stat-item .label { font-size: 14px; opacity: 0.9; }
.stat-item.green { background: #2ecc71; }
.stat-item.orange { background: #f39c12; }
.stat-item.red { background: #e74c3c; }
.stat-item.purple { background: #9b59b6; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th { background: #34495e; color: white; padding: 10px; text-align: left; }
td { padding: 10px; border-bottom: 1px solid #ddd; }
tr:hover { background: #f9f9f9; }
.category-bar { height: 20px; background: #3498db; margin: 5px 0; border-radius: 3px; }
.footer { margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; color: #7f8c8d; font-size: 12px; text-align: center; }
.warning-box { background: #fcf8e3; border-left: 5px solid #f0ad4e; padding: 10px; margin: 20px 0; }
.warning-box strong { color: #8a6d3b; }
</style>
</head>
<body>
<div class="container">
<h1>📊 Mobile Datensonde - Analysebericht</h1>

<div class="warning-box">
<strong>⚠️ Hinweis zur Datensicherheit:</strong> Dieser Bericht zeigt, wie viele Informationen ein fremder USB-Stick über ein System sammeln kann.
Die Daten dienen ausschließlich der Sensibilisierung für USB-Sicherheitsrisiken.
</div>

<div class="info-box">
<strong>System:</strong> $($Statistics.System.Hostname)<br>
<strong>Benutzer:</strong> $($Statistics.System.Username)<br>
<strong>Betriebssystem:</strong> $($Statistics.System.Betriebssystem)<br>
<strong>Erfassungsdatum:</strong> $($Statistics.Erfassungsdatum)<br>
<strong>USB-Stick:</strong> $($Statistics.System.USBStick.Name) ($($Statistics.System.USBStick.Total) GB total, $($Statistics.System.USBStick.Free) GB frei)
</div>

<h2>📈 Übersicht</h2>
<div class="stat-grid">
<div class="stat-item">
<div class="number">$($Statistics.GesamtDateien)</div>
<div class="label">Dateien gesamt</div>
</div>
<div class="stat-item green">
<div class="number">$totalSizeGB GB</div>
<div class="label">Speicherverbrauch</div>
</div>
<div class="stat-item orange">
<div class="number">$avgSizeMB MB</div>
<div class="label">Durchschnittliche Dateigröße</div>
</div>
<div class="stat-item purple">
<div class="number">$(($Files | Where-Object { $_.Kategorie -eq "Bilder" }).Count)</div>
<div class="label">Bilder</div>
</div>
</div>

<h2>📁 Kategorien</h2>
<table>
<tr>
<th>Kategorie</th>
<th>Anzahl</th>
<th>Größe (GB)</th>
<th>Anteil</th>
<th>Verteilung</th>
</tr>
"@

# Kategorien sortiert nach Anzahl
$sortedCategories = $Statistics.Kategorien.PSObject.Properties | Sort-Object { $_.Value.Anzahl } -Descending
$maxCount = ($sortedCategories | Measure-Object -Property Value -Maximum).Maximum.Anzahl

foreach ($cat in $sortedCategories) {
$barWidth = if ($maxCount -gt 0) { [math]::Min(($cat.Value.Anzahl / $maxCount) * 100, 100) } else { 0 }
$html += @"
<tr>
<td><strong>$($cat.Name)</strong></td>
<td>$($cat.Value.Anzahl)</td>
<td>$($cat.Value.GrößeGB)</td>
<td>$($cat.Value.Prozent)%</td>
<td><div class="category-bar" style="width: ${barWidth}%;"></div></td>
</tr>
"@
}

$html += @"
</table>

<h2>🏆 Top 10 größte Dateien</h2>
<table>
<tr>
<th>#</th>
<th>Dateiname</th>
<th>Größe (GB)</th>
<th>Kategorie</th>
<th>Pfad</th>
</tr>
"@

$topFiles = $Files | Sort-Object -Property GrößeGB -Descending | Select-Object -First 10
$i = 1
foreach ($file in $topFiles) {
$displayPath = if ($file.Pfad.Length -gt 40) { $file.Pfad.Substring(0, 37) + "..." } else { $file.Pfad }
$html += @"
<tr>
<td>$i</td>
<td>$($file.Dateiname)</td>
<td>$($file.GrößeGB)</td>
<td>$($file.Kategorie)</td>
<td>$displayPath</td>
</tr>
"@
$i++
}

$html += @"
</table>

<h2>📅 Dateialter</h2>
<div class="stat-grid">
<div class="stat-item green">
<div class="number">$($Statistics.DateiAlter.JüngerAls1Monat)</div>
<div class="label">Jünger als 1 Monat</div>
</div>
<div class="stat-item orange">
<div class="number">$($Statistics.DateiAlter.JüngerAls6Monate)</div>
<div class="label">Jünger als 6 Monate</div>
</div>
<div class="stat-item red">
<div class="number">$($Statistics.DateiAlter.ÄlterAls1Jahr)</div>
<div class="label">Älter als 1 Jahr</div>
</div>
</div>

<h2>📊 Top 10 Datei-Erweiterungen</h2>
<table>
<tr>
<th>Erweiterung</th>
<th>Anzahl</th>
<th>Größe (GB)</th>
<th>Anteil</th>
</tr>
"@

$topExtensions = $Files | Group-Object -Property Erweiterung |
Where-Object { $_.Name -ne "" } |
Sort-Object -Property Count -Descending |
Select-Object -First 10

$totalFiles = $Files.Count
foreach ($ext in $topExtensions) {
$size = [math]::Round(($ext.Group | Measure-Object -Property GrößeGB -Sum).Sum, 2)
$percent = [math]::Round(($ext.Count / $totalFiles) * 100, 1)
$html += @"
<tr>
<td><strong>$($ext.Name)</strong></td>
<td>$($ext.Count)</td>
<td>$size</td>
<td>$percent%</td>
</tr>
"@
}

$html += @"
</table>

<div class="footer">
Erstellt mit der Mobilen Datensonde am $(Get-Date -Format "dd.MM.yyyy HH:mm:ss")<br>
<strong>Dieser Bericht dient ausschließlich zu Demonstrations- und Sensibilisierungszwecken.</strong>
</div>
</div>
</body>
</html>
"@

try {
$html | Set-Content -Path $reportFile -Encoding UTF8
Write-Log "Bericht erstellt: $reportFile" "INFO"
Write-Host "Bericht erstellt: $reportFile" -ForegroundColor Green
} catch {
Write-Log "Fehler beim Erstellen des Berichts: $_" "ERROR"
}
}

function Generate-HTMLReport {
param($Files, $Stats, $OutputPath)

# Erweiterter HTML-Bericht für den Export
$html = @"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Datenexport - Mobile Datensonde</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
.container { max-width: 1400px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; }
h1 { color: #2c3e50; }
table { border-collapse: collapse; width: 100%; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background: #34495e; color: white; }
tr:nth-child(even) { background: #f2f2f2; }
.warning { background: #fcf8e3; padding: 10px; border-left: 5px solid #f0ad4e; margin-bottom: 20px; }
</style>
</head>
<body>
<div class="container">
<h1>📊 Datenexport - Mobile Datensonde</h1>
<div class="warning">
<strong>⚠️ Hinweis:</strong> Dieser Export zeigt, welche Datei-Metadaten von einem fremden USB-Stick erfasst werden können.
</div>
<p><strong>Exportiert am:</strong> $(Get-Date -Format "dd.MM.yyyy HH:mm:ss")</p>
<p><strong>System:</strong> $($Stats.System.Hostname) ($($Stats.System.Username))</p>
<p><strong>Gesamt:</strong> $($Files.Count) Dateien</p>
<p><strong>Gesamtspeicher:</strong> $([math]::Round(($Files | Measure-Object -Property GrößeGB -Sum).Sum, 2)) GB</p>
<table>
<tr>
<th>#</th>
<th>Dateiname</th>
<th>Pfad</th>
<th>Kategorie</th>
<th>Größe (MB)</th>
<th>Größe (GB)</th>
<th>Erstellungsdatum</th>
<th>Änderungsdatum</th>
</tr>
"@

$counter = 1
foreach ($file in $Files | Select-Object -First 1000) {
$html += @"
<tr>
<td>$counter</td>
<td>$($file.Dateiname)</td>
<td>$($file.Pfad)</td>
<td>$($file.Kategorie)</td>
<td>$($file.GrößeMB)</td>
<td>$($file.GrößeGB)</td>
<td>$($file.Erstellungsdatum)</td>
<td>$($file.Änderungsdatum)</td>
</tr>
"@
$counter++
}

if ($Files.Count -gt 1000) {
$html += "<tr><td colspan='8' style='text-align:center;'><strong>... und $($Files.Count - 1000) weitere Dateien</strong></td></tr>"
}

$html += @"
</table>
<p style="margin-top:20px; color:#7f8c8d; font-size:12px;">Erstellt mit der Mobilen Datensonde - Ein Werkzeug zur Sensibilisierung für USB-Sicherheitsrisiken.</p>
</div>
</body>
</html>
"@

$html | Set-Content -Path $OutputPath -Encoding UTF8
}

# ============================================
# HAUPTLOGIK
# ============================================

function Show-Banner {
Clear-Host
Write-Host @"
==========================================


MOBILE DATENSONDE v2.0
Ein Werkzeug zur Sensibilisierung
==========================================
"@ -ForegroundColor Cyan
Write-Host "System: $env:COMPUTERNAME ($env:USERNAME)" -ForegroundColor Gray
Write-Host "USB-Stick: $scriptRoot" -ForegroundColor Gray
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "⚠️ HINWEIS ZUR SICHERHEIT" -ForegroundColor Yellow
Write-Host "Dieses Skript sammelt METADATEN (Dateinamen, Größen, Pfade)." -ForegroundColor Gray
Write-Host "Es kopiert KEINE Dateiinhalte und überträgt KEINE Daten." -ForegroundColor Gray
Write-Host "Der Zweck ist die SENSIBILISIERUNG für USB-Sicherheitsrisiken." -ForegroundColor Gray
Write-Host ""
}

# ============================================
# START
# ============================================

# Banner anzeigen
Show-Banner

# Verzeichnisse initialisieren
Initialize-Directories

# Prüfen, ob auf USB-Stick
$isUsb = Test-UsbStick

if (-not $isUsb) {
Write-Log "WARNUNG: Skript wird nicht von einem USB-Stick ausgeführt!" "WARN"
Write-Host ""
Write-Host "⚠️ Dieses Skript ist für die Ausführung von einem USB-Stick optimiert." -ForegroundColor Yellow
Write-Host "Es kann dennoch von einem lokalen Verzeichnis ausgeführt werden." -ForegroundColor Gray
$continue = Read-Host "Fortfahren? (j/n)"
if ($continue -ne "j") {
Write-Host "Skript abgebrochen." -ForegroundColor Red
exit
}
}

# Modus erkennen
if ($Mode -eq "auto") {
if (Test-Path $dbFile) {
Write-Host "📂 Datenbank gefunden. Starte Viewer..." -ForegroundColor Green
$Mode = "view"
} else {
Write-Host "📂 Keine Datenbank gefunden. Starte Sammelmodus..." -ForegroundColor Yellow
$Mode = "collect"
}
}

# Modus ausführen
switch ($Mode) {
"collect" {
Write-Host ""
Write-Host "==========================================" -ForegroundColor Yellow
Write-Host "STARTE SAMMELMODUS" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Yellow
Write-Host ""
Write-Host "Dieser Modus analysiert die Dateistruktur Ihres Systems." -ForegroundColor Gray
Write-Host "Je nach Datenmenge kann dies 5-30 Minuten dauern." -ForegroundColor Gray
Write-Host ""
Write-Host "Drücken Sie Enter, um fortzufahren, oder Ctrl+C zum Abbrechen." -ForegroundColor Cyan
Read-Host

$result = Start-Collection

if ($result -and $result.Dateien.Count -gt 0) {
Write-Host ""
Write-Host "==========================================" -ForegroundColor Green
Write-Host "SAMMLUNG ABGESCHLOSSEN!" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Green
Write-Host ""
Write-Host "✅ $($result.Dateien.Count) Dateien erfasst" -ForegroundColor Green
Write-Host "✅ Datenbank gespeichert auf USB-Stick" -ForegroundColor Green
Write-Host ""
Write-Host "📌 NÄCHSTE SCHRITTE:" -ForegroundColor Yellow
Write-Host "1. Ziehen Sie den USB-Stick ab" -ForegroundColor Gray
Write-Host "2. Stecken Sie ihn in einen anderen Rechner" -ForegroundColor Gray
Write-Host "3. Führen Sie das Skript erneut aus (Modus wird automatisch erkannt)" -ForegroundColor Gray
Write-Host ""
Write-Host "💡 So sehen Sie, wie viele Informationen ein fremder USB-Stick sammeln kann!" -ForegroundColor Cyan
} else {
Write-Host ""
Write-Host "❌ Keine Dateien erfasst. Bitte prüfen Sie die Laufwerke." -ForegroundColor Red
}
}
"view" {
Start-Viewer
}
default {
Write-Host "Unbekannter Modus: $Mode" -ForegroundColor Red
}
}

Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "Skript beendet." -ForegroundColor Gray
Read-Host "Drücken Sie Enter zum Beenden"

Anleitung zur Nutzung

1. Vorbereitung

  1. USB-Stick formatieren (empfohlen: exFAT oder NTFS)
  2. Ordner erstellen: Datensonde auf dem USB-Stick
  3. Skript speichern: Kopieren Sie den obigen Code als Datensonde.ps1 in den Ordner
  4. Batch-Datei erstellen (für einfachen Start):

batch

@echo off
powershell.exe -ExecutionPolicy Bypass -File "%~dp0Datensonde.ps1" -Mode auto
pause

2. Erste Nutzung – Datensammlung

  1. USB-Stick in Rechner A einstecken
  2. Batch-Datei ausführen
  3. Skript erkennt automatisch den Sammelmodus
  4. Warten (5-30 Minuten je nach Datenmenge)
  5. USB-Stick abziehen

3. Zweite Nutzung – Daten anzeigen

  1. USB-Stick in Rechner B einstecken
  2. Batch-Datei ausführen
  3. Skript erkennt automatisch den Viewer-Modus
  4. Menü zur Analyse nutzen

Was dieser Code demonstriert

Erkannte InformationBeispielGefahrenpotenzial
BenutzernameMax.MustermannIdentifikation der Zielperson
ComputernamePC-MAXNetzwerk-Identifikation
BetriebssystemWindows 10 ProAngriffspunkte identifizieren
DateistrukturenAlle Pfade, OrdnerhierarchienEinblick in Organisationsstruktur
DateitypenPDF, DOCX, XLSX, JPG, etc.Bewertung der Daten-Wertigkeit
DateigrößenPräzise Angaben in MB/GBIdentifikation wertvoller Dateien
DateialterErstellungs-, Änderungs- und ZugriffsdatumHinweise auf Aktivität
SpeicherverbrauchGesamtnutzung pro KategorieRückschluss auf Datenmenge
Versteckte DateienErkennung von System- und versteckten DateienAufdeckung von Sicherheitsmaßnahmen

Sicherheitshinweise

✅ Dieses Skript ist ungefährlich, weil es:

  • Keine Dateiinhalte kopiert oder überträgt
  • Keine Systemeinstellungen verändert
  • Keine Software installiert
  • Keine Netzwerkverbindungen aufbaut
  • Nur Metadaten sammelt (Namen, Größen, Pfade)

⚠️ Dieses Skript zeigt, wie viel ein fremder USB-Stick über Ihr System erfahren kann. Nutzen Sie es, um:

  • Mitarbeiter zu sensibilisieren
  • Sicherheitsrichtlinien zu überprüfen
  • Das Bewusstsein für USB-Risiken zu schärfen

Die Gefahr im Detail: Was ein Angreifer wirklich tun würde

Der Demo-Code ist bewusst harmlos. Ein echter Angreifer würde ihn wie folgt erweitern:

1. Datendiebstahl in Echtzeit

powershell

# ECHTER ANGRIFF: Daten kopieren (NICHT IM DEMO-CODE ENTHALTEN!)
# WARNUNG: Dies ist nur zur Veranschaulichung der Gefahr!

$relevantPaths = @(
    "C:\Users\$env:USERNAME\Documents",
    "C:\Users\$env:USERNAME\Desktop",
    "C:\Users\$env:USERNAME\OneDrive"
)

$relevantExtensions = @(".pdf", ".docx", ".xlsx", ".pptx", ".txt", ".jpg", ".png")

$targetFiles = Get-ChildItem -Path $relevantPaths -Recurse -File |
               Where-Object { $_.Extension -in $relevantExtensions }

foreach ($file in $targetFiles) {
    Copy-Item -Path $file.FullName -Destination "$scriptRoot\Exfiltration\" -Force
}

Zeitaufwand: 3-15 Minuten

2. BadUSB / Rubber Ducky Angriff

Ein Angreifer würde einen USB-Stick als Tastatur tarnen, der in Sekunden:

  • Ein Admin-Konto erstellt
  • Remote Desktop aktiviert
  • Eine Reverse Shell öffnet
  • Malware installiert

Schutzmaßnahmen

MaßnahmeBeschreibungEffektivität
USB-Ports sperrenDeaktivieren nicht benötigter USB-PortsHoch
Application AllowlistingNur erlaubte Programme dürfen ausgeführt werdenSehr Hoch
EDRErkennung verdächtiger AktivitätenHoch
USB-PrüfstationDedizierter Rechner zum ScannenSehr Hoch
Autoplay deaktivierenVerhindert automatische AusführungGrundlegend
BitLockerVerschlüsselung des gesamten SystemsHoch

Kommentar abschicken

Das hast du vielleicht verpasst