From 9b65a5555640a7f1cc01e4a86625888a4864684d Mon Sep 17 00:00:00 2001 From: amadejpapez Date: Thu, 10 Jun 2021 14:42:03 +0200 Subject: [PATCH 1/2] Detection for credit cards with spaces and more regex --- pywhat/Data/regex.json | 24 +++++++++---------- pywhat/what.py | 2 +- tests/test_regex_identifier.py | 44 +++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/pywhat/Data/regex.json b/pywhat/Data/regex.json index 3d1b1fb..567d835 100644 --- a/pywhat/Data/regex.json +++ b/pywhat/Data/regex.json @@ -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]{2})\\[?(?:(?:[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/", @@ -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": [ @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/pywhat/what.py b/pywhat/what.py index 7e99fc1..da67fbd 100644 --- a/pywhat/what.py +++ b/pywhat/what.py @@ -80,7 +80,7 @@ def main(text_input, rarity, include_tags, exclude_tags): * what -- 52.6169586, -1.9779857 - * what --rarity 0.6: myEmail@host.org + * what --rarity 0.6: 'myEmail@host.org' Your text must either be in quotation marks, or use the POSIX standard of "--" to mean "anything after -- is textual input". diff --git a/tests/test_regex_identifier.py b/tests/test_regex_identifier.py index 284a5ad..bdb1fab 100644 --- a/tests/test_regex_identifier.py +++ b/tests/test_regex_identifier.py @@ -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() From 0f456f697c4d3485b8516460c39e8bf117c93e1d Mon Sep 17 00:00:00 2001 From: amadejpapez Date: Thu, 10 Jun 2021 16:33:47 +0200 Subject: [PATCH 2/2] Updated IPv6 regex --- pywhat/Data/regex.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywhat/Data/regex.json b/pywhat/Data/regex.json index 567d835..179254c 100644 --- a/pywhat/Data/regex.json +++ b/pywhat/Data/regex.json @@ -108,7 +108,7 @@ }, { "Name": "Internet Protocol (IP) Address Version 6", - "Regex": "(?=.*[0-9]{2})\\[?(?:(?:[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/",