|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## ⚠️ CRITICAL SECURITY AND LEGAL NOTICE |
| 6 | + |
| 7 | +**THIS PROJECT IS STRICTLY FOR SECURITY RESEARCH AND DEFENSIVE PURPOSES ONLY** |
| 8 | + |
| 9 | +- This tool is ONLY intended for legitimate security research, authorized audits, and defensive security operations |
| 10 | +- ANY use of this project for unauthorized access, data theft, or malicious purposes is STRICTLY PROHIBITED and may violate computer fraud and abuse laws |
| 11 | +- Users are SOLELY responsible for ensuring compliance with all applicable laws and regulations in their jurisdiction |
| 12 | +- The original author and contributors assume NO legal responsibility for misuse of this tool |
| 13 | +- You MUST have explicit authorization before using this tool on any system you do not own |
| 14 | +- This tool should NEVER be used for attacking, credential harvesting, or any malicious intent |
| 15 | +- All security research must be conducted ethically and within legal boundaries |
| 16 | + |
| 17 | +## Project Overview |
| 18 | + |
| 19 | +HackBrowserData is a command-line security research tool for extracting and decrypting browser data across multiple platforms (Windows, macOS, Linux). It supports data extraction from Chromium-based browsers (Chrome, Edge, Brave, etc.) and Firefox. |
| 20 | + |
| 21 | +**Legitimate Use Cases**: |
| 22 | +- Personal data backup and recovery |
| 23 | +- Authorized enterprise security audits |
| 24 | +- Digital forensics investigations (with proper authorization) |
| 25 | +- Security vulnerability research and defense improvement |
| 26 | +- Understanding browser security mechanisms for defensive purposes |
| 27 | + |
| 28 | +## Development Commands |
| 29 | + |
| 30 | +### Build the Project |
| 31 | +```bash |
| 32 | +# Build for current platform |
| 33 | +cd cmd/hack-browser-data |
| 34 | +go build |
| 35 | + |
| 36 | +# Cross-compile for Windows from macOS/Linux |
| 37 | +GOOS=windows GOARCH=amd64 go build |
| 38 | + |
| 39 | +# Cross-compile for Linux from macOS/Windows |
| 40 | +GOOS=linux GOARCH=amd64 go build |
| 41 | + |
| 42 | +# Cross-compile for macOS from Linux/Windows |
| 43 | +GOOS=darwin GOARCH=amd64 go build |
| 44 | +``` |
| 45 | + |
| 46 | +### Testing |
| 47 | +```bash |
| 48 | +# Run all tests |
| 49 | +go test -v ./... |
| 50 | + |
| 51 | +# Run tests with coverage |
| 52 | +go test -v ./... -covermode=count -coverprofile=coverage.out |
| 53 | + |
| 54 | +# Run specific package tests |
| 55 | +go test -v ./browser/chromium/... |
| 56 | +go test -v ./crypto/... |
| 57 | +``` |
| 58 | + |
| 59 | +### Code Quality |
| 60 | +```bash |
| 61 | +# Format check |
| 62 | +gofmt -d . |
| 63 | + |
| 64 | +# Run linter (requires golangci-lint) |
| 65 | +golangci-lint run |
| 66 | + |
| 67 | +# Check spelling |
| 68 | +typos |
| 69 | + |
| 70 | +# Tidy dependencies |
| 71 | +go mod tidy |
| 72 | +``` |
| 73 | + |
| 74 | +## Architecture Overview |
| 75 | + |
| 76 | +### Core Components |
| 77 | + |
| 78 | +**Browser Abstraction Layer** (`browser/`) |
| 79 | +- Interface-based design allowing easy addition of new browsers |
| 80 | +- Platform-specific implementations using build tags (`_darwin.go`, `_windows.go`, `_linux.go`) |
| 81 | +- Automatic profile discovery and multi-profile support |
| 82 | + |
| 83 | +**Data Extraction Pipeline** |
| 84 | +1. **Profile Discovery**: `profile/finder.go` locates browser profiles |
| 85 | +2. **File Management**: `filemanager/` handles secure copying of browser files |
| 86 | +3. **Decryption**: `crypto/` provides platform-specific decryption |
| 87 | + - Windows: DPAPI via Windows API |
| 88 | + - macOS: Keychain access (requires user password) |
| 89 | + - Linux: PBKDF2 key derivation |
| 90 | +4. **Data Processing**: `browserdata/` parses and structures extracted data |
| 91 | +5. **Output**: `browserdata/outputter.go` exports to CSV/JSON |
| 92 | + |
| 93 | +**Key Interfaces** |
| 94 | +- `Browser`: Main interface for browser implementations |
| 95 | +- `DataType`: Enum for different data types (passwords, cookies, etc.) |
| 96 | +- `BrowserData`: Container for all extracted browser data |
| 97 | + |
| 98 | +### Platform-Specific Considerations |
| 99 | + |
| 100 | +**macOS** |
| 101 | +- Requires user password for Keychain access to decrypt Chrome passwords |
| 102 | +- Uses Security framework for keychain operations |
| 103 | +- Profile paths: `~/Library/Application Support/[Browser]/` |
| 104 | + |
| 105 | +**Windows** |
| 106 | +- Uses DPAPI for decryption (no password required) |
| 107 | +- Accesses Local State file for encryption keys |
| 108 | +- Profile paths: `%LOCALAPPDATA%/[Browser]/User Data/` |
| 109 | + |
| 110 | +**Linux** |
| 111 | +- Uses PBKDF2 with "peanuts" as salt |
| 112 | +- Requires gnome-keyring or kwallet access |
| 113 | +- Profile paths: `~/.config/[Browser]/` |
| 114 | + |
| 115 | +### Security Mechanisms |
| 116 | + |
| 117 | +**Data Protection** |
| 118 | +- Temporary file cleanup after extraction |
| 119 | +- No persistent storage of decrypted master keys |
| 120 | +- Secure memory handling for sensitive data |
| 121 | + |
| 122 | +**File Operations** |
| 123 | +- Copy-on-read to avoid modifying original browser files |
| 124 | +- Lock file filtering to prevent conflicts |
| 125 | +- Atomic operations where possible |
| 126 | + |
| 127 | +## Adding New Browser Support |
| 128 | + |
| 129 | +1. Create browser-specific package in `browser/[name]/` |
| 130 | +2. Implement the `Browser` interface |
| 131 | +3. Add platform-specific profile paths in `browser/consts.go` |
| 132 | +4. Register in `browser/browser.go` picker functions |
| 133 | +5. Add data type mappings in `types/types.go` |
| 134 | + |
| 135 | +## Important Files and Their Roles |
| 136 | + |
| 137 | +- `cmd/hack-browser-data/main.go`: CLI entry point and flag handling |
| 138 | +- `browser/chromium/chromium.go`: Core Chromium implementation |
| 139 | +- `crypto/crypto_[platform].go`: Platform-specific decryption |
| 140 | +- `extractor/extractor.go`: Main extraction orchestration |
| 141 | +- `profile/finder.go`: Browser profile discovery logic |
| 142 | +- `browserdata/password/password.go`: Password parsing and decryption |
| 143 | + |
| 144 | +## Testing Considerations |
| 145 | + |
| 146 | +- Tests use mocked data to avoid requiring actual browser installations |
| 147 | +- Platform-specific tests are isolated with build tags |
| 148 | +- Sensitive operations (like keychain access) are mocked in tests |
| 149 | +- Use `DATA-DOG/go-sqlmock` for database operation testing |
| 150 | + |
| 151 | +## Browser Security Analysis |
| 152 | + |
| 153 | +### Chromium-Based Browsers Security |
| 154 | + |
| 155 | +**Encryption Methods**: |
| 156 | +- **Chrome v80+**: AES-256-GCM encryption for sensitive data |
| 157 | +- **Pre-v80**: AES-128-CBC with PKCS#5 padding |
| 158 | +- **Master Key Storage**: |
| 159 | + - Windows: Encrypted with DPAPI in `Local State` file |
| 160 | + - macOS: Stored in system Keychain (requires user password) |
| 161 | + - Linux: Derived using PBKDF2 with "peanuts" salt |
| 162 | + |
| 163 | +**Data Protection Layers**: |
| 164 | +1. **Password Storage**: Encrypted in SQLite database (`Login Data`) |
| 165 | +2. **Cookie Encryption**: Encrypted values in `Cookies` database |
| 166 | +3. **Credit Card Data**: Encrypted with same master key as passwords |
| 167 | +4. **Local Storage**: Stored in LevelDB format, some values encrypted |
| 168 | + |
| 169 | +### Firefox Security |
| 170 | + |
| 171 | +**Encryption Architecture**: |
| 172 | +- **Master Password**: Optional user-defined password for additional protection |
| 173 | +- **Key Database**: `key4.db` stores encrypted master keys |
| 174 | +- **NSS Library**: Network Security Services for cryptographic operations |
| 175 | +- **Profile Encryption**: Each profile has independent encryption keys |
| 176 | + |
| 177 | +**Key Derivation**: |
| 178 | +- Uses PKCS#5 PBKDF2 for key derivation |
| 179 | +- Triple-DES (3DES) for legacy compatibility |
| 180 | +- AES-256-CBC for modern encryption |
| 181 | +- ASN.1 encoding for key storage |
| 182 | + |
| 183 | +### Platform-Specific Security Mechanisms |
| 184 | + |
| 185 | +**Windows DPAPI (Data Protection API)**: |
| 186 | +- User-specific encryption tied to Windows login |
| 187 | +- No additional password required for decryption |
| 188 | +- Keys protected by Windows security subsystem |
| 189 | +- Vulnerable if attacker has user-level access |
| 190 | + |
| 191 | +**macOS Keychain Services**: |
| 192 | +- Requires user password for access |
| 193 | +- Integration with system security framework |
| 194 | +- Protected by System Integrity Protection (SIP) |
| 195 | +- Security command-line tool for programmatic access |
| 196 | + |
| 197 | +**Linux Secret Service**: |
| 198 | +- GNOME Keyring or KDE Wallet integration |
| 199 | +- D-Bus communication for key retrieval |
| 200 | +- User session-based protection |
| 201 | +- Fallback to PBKDF2 if keyring unavailable |
| 202 | + |
| 203 | +### Security Vulnerabilities and Mitigations |
| 204 | + |
| 205 | +**Known Attack Vectors**: |
| 206 | +1. **Physical Access**: Direct file system access to browser profiles |
| 207 | +2. **Memory Dumps**: Extraction of decrypted data from RAM |
| 208 | +3. **Malware**: Keyloggers and info-stealers targeting browsers |
| 209 | +4. **Process Injection**: DLL injection to extract decrypted data |
| 210 | + |
| 211 | +**Defensive Recommendations**: |
| 212 | +1. **Enable Master Password**: Firefox users should set master password |
| 213 | +2. **Use OS-Level Encryption**: FileVault (macOS), BitLocker (Windows), LUKS (Linux) |
| 214 | +3. **Regular Updates**: Keep browsers updated for latest security patches |
| 215 | +4. **Profile Isolation**: Use separate profiles for sensitive activities |
| 216 | +5. **Hardware Keys**: Use FIDO2/WebAuthn for critical accounts |
| 217 | + |
| 218 | +### Cryptographic Implementation Details |
| 219 | + |
| 220 | +**AES-GCM (Galois/Counter Mode)**: |
| 221 | +- Authenticated encryption with associated data (AEAD) |
| 222 | +- 96-bit nonce/IV for randomization |
| 223 | +- 128-bit authentication tag for integrity |
| 224 | +- Used in Chrome v80+ for enhanced security |
| 225 | + |
| 226 | +**PBKDF2 (Password-Based Key Derivation Function 2)**: |
| 227 | +- Iterations: 1003 (macOS), 1 (Linux default) |
| 228 | +- Hash function: SHA-1 (legacy) or SHA-256 |
| 229 | +- Salt: "saltysalt" (Chrome), "peanuts" (Linux) |
| 230 | +- Output: 128-bit or 256-bit keys |
| 231 | + |
| 232 | +**DPAPI Internals**: |
| 233 | +- Uses CryptProtectData/CryptUnprotectData Windows APIs |
| 234 | +- Machine-specific or user-specific encryption |
| 235 | +- Automatic key management by Windows |
| 236 | +- Integrates with Windows credential manager |
| 237 | + |
| 238 | +## Dependencies |
| 239 | + |
| 240 | +- `modernc.org/sqlite`: Pure Go SQLite for cross-platform compatibility |
| 241 | +- `github.com/godbus/dbus`: Linux keyring access |
| 242 | +- `github.com/ppacher/go-dbus-keyring`: Secret service integration |
| 243 | +- `github.com/tidwall/gjson`: JSON parsing for browser preferences |
| 244 | +- `github.com/syndtr/goleveldb`: LevelDB for IndexedDB/LocalStorage |
| 245 | + |
| 246 | +## Ethical Usage Guidelines |
| 247 | + |
| 248 | +### Responsible Disclosure |
| 249 | +- Report vulnerabilities to browser vendors through official channels |
| 250 | +- Allow reasonable time for patches before public disclosure |
| 251 | +- Never exploit vulnerabilities for personal gain |
| 252 | + |
| 253 | +### Legal Compliance |
| 254 | +- Obtain written authorization before testing third-party systems |
| 255 | +- Comply with GDPR, CCPA, and other privacy regulations |
| 256 | +- Respect intellectual property and terms of service |
| 257 | +- Maintain audit logs of all security testing activities |
| 258 | + |
| 259 | +### Best Practices for Security Researchers |
| 260 | +1. **Scope Definition**: Clearly define testing boundaries |
| 261 | +2. **Data Handling**: Securely delete any extracted sensitive data |
| 262 | +3. **Documentation**: Maintain detailed records of methodologies |
| 263 | +4. **Collaboration**: Work with security community ethically |
| 264 | +5. **Education**: Share knowledge to improve overall security |
0 commit comments