Skip to content

Commit

Permalink
Merge pull request #73 from bee-san/regex-fix
Browse files Browse the repository at this point in the history
Detection for credit card numbers with spaces and more regex
  • Loading branch information
bee-san authored Jun 11, 2021
2 parents 70def10 + 0f456f6 commit 544e9a9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
24 changes: 12 additions & 12 deletions pywhat/Data/regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
},
{
"Name": "Internet Protocol (IP) Address Version 6",
"Regex": "\\[?(?:(?:[0-9a-f]{1,4}:){7,7}[0-9a-f]{1,4}|([0-9a-f]{4}:){1,7}:|([0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}|([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}|([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}|([0-9a-fA]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}|[0-9a-f]{1,4}:((:[0-9a-f]{1,4}){1,6})|:((:[0-9a-f]{1,4}){1,7}|:)|fe80:(:[0-9a-f]{0,4}){0,4}%[0-9a-z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-f]{1,4}:){1,4}:(?:(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\\]?(?::[0-9]{1,5})?",
"Regex": "(?=.*[0-9])\\[?(?:(?:[0-9a-f]{1,4}:){7,7}[0-9a-f]{1,4}|([0-9a-f]{4}:){1,7}:|([0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}|([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}|([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}|([0-9a-fA]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}|[0-9a-f]{1,4}:((:[0-9a-f]{1,4}){1,6})|:((:[0-9a-f]{1,4}){1,7}|:)|fe80:(:[0-9a-f]{0,4}){0,4}%[0-9a-z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-f]{1,4}:){1,4}:(?:(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\\]?(?::[0-9]{1,5})?",
"plural_name": false,
"Description": null,
"URL": "https://www.shodan.io/host/",
Expand Down Expand Up @@ -212,7 +212,7 @@
},
{
"Name": "JSON Web Token (JWT)",
"Regex": "^([a-zA-Z0-9_=]+)\\.([a-zA-Z0-9_=]+)\\.([a-zA-Z0-9_\\-\\+\/=]*)",
"Regex": "(?i)^(?=.*[a-z])(?=.*[0-9])(?:[a-z0-9_=]+\\.){2}(?:[a-z0-9_\\-\\+\/=]*)$",
"Description": null,
"Rarity": 0.5,
"Tags": [
Expand All @@ -224,7 +224,7 @@
},
{
"Name": "American Express Card Number",
"Regex": "^3[47][0-9]{13}$",
"Regex": "^3[47][0-9]{2}\\s?(?:[0-9]{4}\\s?){2}[0-9]{3}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -235,7 +235,7 @@
},
{
"Name": "BCGlobal Card Number",
"Regex": "^(6541|6556)[0-9]{12}$",
"Regex": "^(?:6541|6556)[0-9]{12}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -257,7 +257,7 @@
},
{
"Name": "Diners Club Card Number",
"Regex": "^3(?:0[0-5]|[68][0-9])[0-9]{11}$",
"Regex": "^3(?:0[0-5]|[68][0-9])[0-9]\\s?(?:[0-9]{4}\\s?){2}[0-9]{2}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -268,7 +268,7 @@
},
{
"Name": "Discover Card Number",
"Regex": "^65[4-9][0-9]{13}$|^64[4-9][0-9]{13}$|^6011[0-9]{12}$|^(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$",
"Regex": "^(?:64[4-9][0-9]|65[0-9]{2}|6011)\\s?(?:[0-9]{4}\\s?){3}$|^622(?:1\\s?2[6-9][0-9]{2}|1\\s?[3-9][0-9]{3}|[2-8]\\s?[0-9]{4}|9\\s?[01][0-9]{3}|9\\s?2[0-5][0-9]{2})\\s?(?:[0-9]{4}\\s?){2}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -279,7 +279,7 @@
},
{
"Name": "MasterCard Number",
"Regex": "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$",
"Regex": "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)\\s?(?:[0-9]{4}\\s?){3}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -290,7 +290,7 @@
},
{
"Name": "Maestro Card Number",
"Regex": "^(5018|5020|5038|6304|6759|6761|6763)[0-9]{8,15}$",
"Regex": "^(?:5018|5020|5038|5612|5893|6304|6759|676[1-3]|0604|6390)\\s?(?:[0-9]{4}\\s?){3}\\s?(?:[0-9]{3,7})?$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -301,7 +301,7 @@
},
{
"Name": "Visa Card Number",
"Regex": "^4[0-9]{12}(?:[0-9]{3})?",
"Regex": "^4[0-9]{12}(?:[0-9]{3})?$|^4[0-9]{3}\\s(?:[0-9]{2,4}\\s?){3}(?:[0-9])?$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand Down Expand Up @@ -345,7 +345,7 @@
},
{
"Name": "Laser Card Number",
"Regex": "^(6304|6706|6709|6771)[0-9]{12,15}$",
"Regex": "^(?:6304|6706|6709|6771)[0-9]{12,15}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -355,7 +355,7 @@
},
{
"Name": "Solo Card Number",
"Regex": "^(6334|6767)[0-9]{12}|(6334|6767)[0-9]{14}|(6334|6767)[0-9]{15}$",
"Regex": "^(?:6334|6767)[0-9]{12}$|^(?:6334|6767)[0-9]{14}$|^(?:6334|6767)[0-9]{15}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand All @@ -366,7 +366,7 @@
},
{
"Name": "Switch Card Number",
"Regex": "^(4903|4905|4911|4936|6333|6759)[0-9]{12}|(4903|4905|4911|4936|6333|6759)[0-9]{14}|(4903|4905|4911|4936|6333|6759)[0-9]{15}|564182[0-9]{10}|564182[0-9]{12}|564182[0-9]{13}|633110[0-9]{10}|633110[0-9]{12}|633110[0-9]{13}$",
"Regex": "^(?:4903|4905|4911|4936|6333|6759)[0-9]{12}$|(?:4903|4905|4911|4936|6333|6759)[0-9]{14}|(?:4903|4905|4911|4936|6333|6759)[0-9]{15}|564182[0-9]{10}|564182[0-9]{12}|564182[0-9]{13}|633110[0-9]{10}|633110[0-9]{12}|633110[0-9]{13}$",
"plural_name": false,
"Description": null,
"Rarity": 0.5,
Expand Down
2 changes: 1 addition & 1 deletion pywhat/what.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main(text_input, rarity, include_tags, exclude_tags):
* what -- 52.6169586, -1.9779857
* what --rarity 0.6: [email protected]
* what --rarity 0.6: '[email protected]'
Your text must either be in quotation marks, or use the POSIX standard of "--" to mean "anything after -- is textual input".
Expand Down
44 changes: 43 additions & 1 deletion tests/test_regex_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,72 @@ def test_visa():
assert "Visa" in res[0]["Regex Pattern"]["Name"]


def test_visa_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["4607 0000 0000 0009"])
assert "Visa" in res[0]["Regex Pattern"]["Name"]


def test_master_Card():
r = regex_identifier.RegexIdentifier()
res = r.check(["5500000000000004"])
assert "MasterCard" in res[0]["Regex Pattern"]["Name"]


def test_master_card_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["5555 5555 5555 4444"])
assert "MasterCard" in res[0]["Regex Pattern"]["Name"]


def test_american_express():
r = regex_identifier.RegexIdentifier()
res = r.check(["340000000000009"])
assert "American Express" in res[0]["Regex Pattern"]["Name"]


def test_american_express_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["3714 4963 5398 431"])
assert "American Express" in res[0]["Regex Pattern"]["Name"]


def test_american_diners_club():
r = regex_identifier.RegexIdentifier()
res = r.check(["30000000000004"])
assert "Diners Club Card" in res[0]["Regex Pattern"]["Name"]


def test_american_diners_discover():
def test_american_diners_club_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["3056 9309 0259 04"])
assert "Diners Club Card" in res[0]["Regex Pattern"]["Name"]


def test_discover_card():
r = regex_identifier.RegexIdentifier()
res = r.check(["6011000000000004"])
assert "Discover" in res[0]["Regex Pattern"]["Name"]


def test_discover_card_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["6011 1111 1111 1117"])
assert "Discover" in res[0]["Regex Pattern"]["Name"]


def test_maestro_card():
r = regex_identifier.RegexIdentifier()
res = r.check(["5038146401278870"])
assert "Maestro" in res[0]["Regex Pattern"]["Name"]


def test_maestro_card_spaces():
r = regex_identifier.RegexIdentifier()
res = r.check(["6759 6498 2643 8453"])
assert "Maestro" in res[0]["Regex Pattern"]["Name"]


@pytest.mark.skip("Key:value is turned off")
def test_username():
r = regex_identifier.RegexIdentifier()
Expand Down

0 comments on commit 544e9a9

Please sign in to comment.