1

so quite simply I'm looking to incorporate the bcrpyt regex into an egrep command to see whether a bcrypt hash is present on each line.

I currently do this with MD5 hashes, quite easily:

egrep -wa "[a-f0-9]{32}" DB.txt >> DB_md5.txt
egrep -v -a "[a-f0-9]{32}" DB.txt >> DB_nomd5.txt

I've researched and found: Regular expression to find bcrypt hash?

Along with the solution being: \$2[ayb]\$.{56}

I'm struggling to include it in my egrep command. For example:

egrep -wa "\$2[ayb]\$.{56}" DB.txt >> DB_bcrypt.txt

The above command is not working. Any help is greatly appreciated.

Note: The position of the bcrypt hash is not important, it can be in any position on the line, hence why I've removed the ^ and $ from the regex solution found in the link below.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • Please do not edit solution announcements into the question. Accept (i.e. click the "tick" next to it) one of the existing answer, if there are any. You can also create your own answer, and even accept it, if your solution is not yet covered by an existing answer. Compare https://stackoverflow.com/help/self-answer – Yunnosch Jul 09 '22 at 12:06

1 Answers1

1

You may use

grep -Ea '\$2[ayb]\$.{56}' DB.txt >> DB_bcrypt.txt

See the online demo.

NOTES

  • -E - POSIX ERE syntax on, now { and } in the {56} range quantifier do not need escaping (your regex was parsed with the POSIX BRE engine, and you need \{56\} there to match a pattern 56 times)
  • Single quotes around the regex make sure \$ is parsed as a \$ regex escape, else "\$" just dentotes a $ special char, that is, the end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563