A very simple way to extract email addresses from any file, particularly a binary file such as a live MySQL database, is to use the strings command (which extracts printable characters from a file or stream) together with grep:
Example:
strings pathtoyourdatabase/* |grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'|sort -u This command extracts all printable characters from your MySQL database, then searches for the pattern corresponding to an email address. I deliberately did not use the official regular expression for an email address, which is more precise but far too long; I settled for an expression that met my needs.
For example, this command will analyse every table in a MySQL database called “mybase” and extract email addresses without needing to connect to the database, or even for it to be running:
strings /var/lib/mysql/mybase/* |grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'|sort -uI have also successfully tested this command on other databases, such as PostgreSQL:
strings /var/lib/pgsql/data/base/19981/* grep -Eio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'|sort -uChristophe Casalegno
You can follow me on: Twitter | Facebook | Linkedin | Telegram | Youtube
Leave a comment
Add a comment