常用的正则、搜索

转自:https://www.unix-ninja.com/p/A_cheat-sheet_for_password_crackers

提取E-mail

1
grep -E -o "\b[a-zA-Z0-9.#?$*_-]+@[a-zA-Z0-9.#?$*_-]+.[a-zA-Z0-9.-]+\b" *.txt > e-mails.txt

提取http url

1
grep http | grep -shoP 'http.*?[" >]' *.txt > http-urls.txt

For extracting HTTPS, FTP and other URL format use

1
grep -E '(((https|ftp|gopher)|mailto)[.:][^ >"	]*|www.[-a-z0-9.]+)[^ .,;	>">):]' *.txt > urls.txt

提取浮点数

1
grep -E -o "^[-+]?[0-9]*.?[0-9]+([eE][-+]?[0-9]+)?$" *.txt > floats.txt

提取信用卡号码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Visa 
# grep -E -o "4[0-9]{3}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}" *.txt > visa.txt

MasterCard
# grep -E -o "5[0-9]{3}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}" *.txt > mastercard.txt

American Express
# grep -E -o "\b3[47][0-9]{13}\b" *.txt > american-express.txt

Diners Club
# grep -E -o "\b3(?:0[0-5]|[68][0-9])[0-9]{11}\b" *.txt > diners.txt

Discover
# grep -E -o "6011[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}" *.txt > discover.txt

JCB
# grep -E -o "\b(?:2131|1800|35d{3})d{11}\b" *.txt > jcb.txt

AMEX
# grep -E -o "3[47][0-9]{2}[ -]?[0-9]{6}[ -]?[0-9]{5}" *.txt > amex.txt

各种hash的提取

md5 hash

1
egrep -oE '(^|[^a-fA-F0-9])[a-fA-F0-9]{32}([^a-fA-F0-9]|$)' *.txt | egrep -o '[a-fA-F0-9]{32}' > md5-hashes.txt


1
sed -rn 's/.*[^a-fA-F0-9]([a-fA-F0-9]{32})[^a-fA-F0-9].*/1/p' *.txt > md5-hashes

上述代码用来查找SHA1, SHA256等其他未加salt的hash, 对于其他长度hash,只需要更改{32}中的长度

Extract valid MySQL-Old hashes

1
grep -e "[0-7][0-9a-f]{7}[0-7][0-9a-f]{7}" *.txt > mysql-old-hashes.txt

Extract blowfish hashes

1
grep -e "$2a\$8\$(.){75}" *.txt > blowfish-hashes.txt

Extract Joomla hashes

1
egrep -o "([0-9a-zA-Z]{32}):(w{16,32})" *.txt > joomla.txt

Extract VBulletin hashes

1
egrep -o "([0-9a-zA-Z]{32}):(S{3,32})" *.txt > vbulletin.txt

Extraxt phpBB3-MD5

1
egrep -o '$H$S{31}' *.txt > phpBB3-md5.txt

Extract Wordpress-MD5

1
egrep -o '$P$S{31}' *.txt > wordpress-md5.txt

Extract Drupal 7

1
egrep -o '$S$S{52}' *.txt > drupal-7.txt

Extract old Unix-md5

1
egrep -o '$1$w{8}S{22}' *.txt > md5-unix-old.txt

Extract md5-apr1

1
egrep -o '$apr1$w{8}S{22}' *.txt > md5-apr1.txt

Extract sha512crypt, SHA512(Unix)

1
egrep -o '$6$w{8}S{86}' *.txt > sha512crypt.txt