HaveIBeenPwned/EmailAddressExtractor
Acerca de
A project to rapidly extract all email addresses from any files in a given path
Productividad y automatizaciónCrecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +1
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
OriginalThe Have I Been Pwned Email Address Extractor
A project to rapidly extract all email addresses from any files in a given path.
Background
This project is intended to be a brand new open source version of a basic codebase I've used for the better part of a decade to extract email addresses from data breaches before loading them into HIBP. Most breaches are in a .sql or .csv format either in a single file or multiple files within a folder and extraction follows a simple process:
- Extract all addresses via regex
- Convert them to lowercase
- Order them alphabetically
- Save them to an output file
- Create a report of how many unique addresses were in each file
Practical Considerations
Email address validation via regex is hard, but it also doesn't need to be perfect for this use case. Inevitably, discussion has led to compliance with the RFC versus the practical uses of certain characters when considering parsing rules. Let me explain:
- There is an argument that where the RFC allows a character such as a double quote, it should be considered a valid character and permitted in addresses
- However, a character such as a double quote is more likely to be present as the result of a parsing error rather than legitimate use
Anecdotally, point 1 is rarely ever true in comparison to point 2. The impact of falsely rejecting a legitimate spec-compliant address is that it doesn't end up in HIBP (i.e. low impact). The impact of allowing addresses that don't actually exist is that junk records are introduced into HIBP (also low impact). Especially when considering the likelihood of an address with obscure characters being practically used (for example, accepted into a registration form and not rejected), on balance it is preferable to reject characters that are likely the result of parsing errors. Let me rephrase and and reiterate for impact: the likelihood of an email address containing obscure character patterns and being valid and actively used is so rare that it should be discarded.
Email Address Rules
The portable email rules package defines which candidates the extractor accepts and how it finds them in breach data and pastes.
Its fixtures are not a signup or search policy: never scan a customer-entered address to look up a different mailbox.
Copy the entire spec directory to give another project or agent the rules, exact JSON test cases, offline test TLD list, and license.
Contributions
I've reached out and asked for support and will get things kicked off via one or two key people then seek broader input. I'm particularly interested in optimising the service across larger data sets and non text-based files, especially with the uptick of documents being dumped by ransomware crews. I'll start creating issues for the bits that need building.
Test Data
Using Red Gate's SQL Data Generator, a sample (archived) file containing 10M records of typical breach data is available. This file results in exactly 10M email addresses being extracted with the current version of this app.
Running the Address Extractor
Building and running from source requires the .NET 11 SDK.
Excel workbooks (.xlsx, macro-enabled .xlsm, binary .xlsb, and legacy binary .xls) are supported.
The extractor reads text cells (including rich text) and cached text formula results across worksheets.
For .xlsx and .xlsm, this includes shared strings and inline text; .xls and .xlsb are read row by row using ExcelDataReader, including legacy .xls character encodings.
It does not execute macros, calculate formulas, or accept passwords for encrypted workbooks.
PowerPoint presentations (.pptx and PowerPoint 97-2003 binary .ppt) and templates (.potx) are supported, including slide text and speaker notes.
The .pptx and .potx reader joins formatting runs within each paragraph, including text in tables, while keeping paragraph and line breaks separate.
The .ppt reader scans stored text records, which can also include master slides, hyperlinks, and text retained from earlier revisions.
Images and embedded documents are not parsed, and password-protected presentations are not supported.
Outlook messages (.msg) are supported without --processAllExtensions.
The extractor reads sender and recipient fields, subject and transport headers, plain text, HTML, and compressed RTF bodies, including embedded Outlook messages.
Unicode and declared Windows code pages are decoded, as are HTML character references and encoded transport headers.
Binary attachment contents are excluded; encrypted message contents are not decrypted.
Compound-file streams are read directly without loading attachments into memory; RTF body conversion buffers the body.
MSG files bypass the raw @ quick scan because encoded addresses may not contain a literal @ in the file.
Standalone email messages (.eml) and mbox mailboxes (.mbox) are supported without --processAllExtensions.
Both readers extract addresses from decoded headers and text MIME parts (including text attachments and nested messages).
For mbox mailboxes, the extractor also reads the envelope sender for each message.
Base64, quoted-printable, declared character sets, and HTML character references are decoded before extraction.
Binary attachment contents are excluded from MIME extraction.
MIME content remains file-backed and decoded text is read line by line, rather than loading the whole mailbox into memory.
Both formats bypass the raw @ quick scan because encoded addresses may not contain a literal @ in the file.
Malformed message sections (including unescaped From lines in message bodies) are scanned as plain text with a notice, then MIME decoding resumes at the next parseable message.
Leading fragments and files without valid mbox messages are also scanned as plain text.
Plain-text recovery finds visible addresses but cannot guarantee recovery of MIME-encoded addresses in the damaged section.
Unrecognized character sets produce a notice and fall back to UTF-8 while still decoding the MIME transfer encoding.
File-access errors surface through the existing file-error reporting.
The initial file summary lists known and processed, known and ignored, then unknown and ignored file types.
Each section starts after a blank line and includes its own file count and total size.
Known ignored and unknown types are ordered by accumulated size descending, then file count descending.
Known ignored types retain their individual reasons.
With --processAllExtensions, all files are processed and the section headings reflect this.
The summary has no timestamps; processing results retain their timestamps.
Syntax: AddressExtractor.exe -?
Syntax: AddressExtractor.exe -v
Syntax: AddressExtractor.exe <input [[... input]]> [-o output] [-r report]
Main Options
| Option | Description |
|---|---|
-?, -h, --help |
Prints the command line syntax and options |
-v, --version |
Prints the application version number |
| input | One or more input filenames or directories |
-o, --output output |
Path and filename of the output file. Defaults to 'addresses_output.txt' |
-r, --report report |
Reports are saved as <output>.report.txt |
--recursive |
Enable recursive mode for directories, which will search child directories |
--processAllExtensions |
Process all files regardless of their extension type |
-y, --yes |
Automatically confirm prompts to CONTINUE without asking |
-q, --quiet |
Run with less verbosity, progress messages aren't shown |
Performance / Debugging
| Option | Description |
|---|---|
--debug |
Enable debug mode for fine-tuned performance checking |
--threads num |
Uses multiple threads with channels for reading from files. Defaults to 4 |
--skip-exceptions |
Automatically prompts on CONTINUE when an exception occurs |
Explorar proyectos relacionados
Cargando…