Skip to content

Commit

Permalink
Merge pull request #36 from bee-san/improve-regex
Browse files Browse the repository at this point in the history
Regex for LTC, BCH, XRP, XMR crypto wallets, IPv6 and more
  • Loading branch information
bee-san authored May 23, 2021
2 parents 0c3172a + ea1b79d commit 8dd40dd
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 47 deletions.
8 changes: 7 additions & 1 deletion fixtures/file
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ ScOAntcCa78
127.0.0.1
github@skerritt.blog

Access-Control-Allow-Headers: *
Access-Control-Allow-Headers: *

47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub
LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m
bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq
rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk
2001:0db8:85a3:0000:0000:8a2e:0370:7334
120 changes: 88 additions & 32 deletions pywhat/Data/regex.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Name": "Ethereum Wallet Address",
"Regex": "^0x[a-fA-F0-9]{40}$",
"Name": "Ethereum (ETH) Wallet Address",
"Regex": "(?i)^0x[a-f0-9]{40}$",
"Description": null,
"URL": "https://etherscan.io/address/",
"Rarity": 1,
Expand All @@ -12,7 +12,7 @@
},
{
"Name": "Access-Control-Allow-Header",
"Regex": "Access-Control-Allow: [a-zA-Z0-9\\-*]",
"Regex": "(?i)Access-Control-Allow: [a-z0-9\\-*]",
"Description": "Used for [#CAE4F1][link=https://en.wikipedia.org/wiki/Cross-origin_resource_sharing]Cross-Origin Resource Sharing (CORS)[/link][/#CAE4F1]",
"Rarity": 1,
"Tags": [
Expand All @@ -21,7 +21,7 @@
]
},
{
"Name": "Bitcoin Wallet",
"Name": "Bitcoin (₿) Wallet Address",
"Regex": "^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$",
"Description": null,
"URL": "https://www.blockchain.com/btc/address/",
Expand Down Expand Up @@ -68,27 +68,60 @@
]
},
{
"Name": "Uniform Resource Locator (URL)",
"Regex": "(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})",
"Name": "Bitcoin Cash (BCH) Wallet Address",
"Regex": "(?i)^bitcoincash:[a-z0-9]{42}$",
"Description": null,
"URL": "https://www.blockchain.com/bch/address/",
"Rarity": 1,
"Tags": [
"Cryptocurrency",
"Finance"
]
},
{
"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})?",
"Description": null,
"URL": "https://www.shodan.io/host/",
"Rarity": 1,
"Tags": [
"Identifiers",
"Networking"
]
},
{
"Name": "Uniform Resource Locator (URL)",
"Regex": "(?i)^(?:(?:(?:https?|ftp):)?\/\/)(?:\\S+(?::\\S*)?@?)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]?\\.?)+?(?:[a-z\u00a1-\uffff]+\\.?))(?::\\d{2,5})?(?:[\/?#]\\S*)?$",
"Description": null,
"Rarity": 0.7,
"Tags": [
"Identifiers"
]
},
{
"Name":"Latitude & Longitude Coordinates",
"Regex":"^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$",
"plural_name": true,
"Description": null,
"URL": "https://www.google.com/maps/place/",
"Rarity": 0.5,
"Tags": [
"Geo-location"
"Name": "Internet Protocol (IP) Address Version 4",
"Regex": "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?::[0-9]{1,5})?",
"Description": null,
"URL": "https://www.shodan.io/host/",
"Rarity": 0.7,
"Tags": [
"Identifiers",
"Networking"
]
},
{
"Name":"Latitude & Longitude Coordinates",
"Regex":"(?i)^(?:(?:N|W|S|E)\\s?\\d+\\s?\\u00B0?\\s?\\d+\\.?\\d*\\s?\\'?\\s?\\d*\\.?\\,?\\d*?\"?\\s?){1,2}$|^(?:\\d+\\s?\\u00B0\\s?\\d+\\s?\\'\\s?\\d+\\.?\\,?\\d{0,}?\"\\s?(?:N|W|S|E)\\s?){1,2}$|^(?:[-+]?(?:[0-8]?\\d+\\.\\d{4,}|90(?:\\.0+)?),\\s*[-+]?(?:180(?:\\.0+)?|(?:(?:1[0-7]\\d)|(?:[1-9]?\\d))(?:\\.\\d+)?))$",
"plural_name": true,
"Description": null,
"URL": "https://www.google.com/maps/place/",
"Rarity": 0.5,
"Tags": [
"Geo-location"
]
},
},
{
"Name": "Dogecoin Wallet Address",
"Name": "Dogecoin (DOGE) Wallet Address",
"Regex": "^D{1}[5-9A-HJ-NP-U]{1}[1-9A-HJ-NP-Za-km-z]{32}$",
"Description": null,
"URL": "https://dogechain.info/address/",
Expand All @@ -98,6 +131,39 @@
"Finance"
]
},
{
"Name": "Monero (XMR) Wallet Address",
"Regex": "(?i)^4(?:[0-9]|[A-B])[a-z0-9]{93}$",
"Description": null,
"URL": "https://dogechain.info/address/",
"Rarity": 0.5,
"Tags": [
"Cryptocurrency",
"Finance"
]
},
{
"Name": "Litecoin (LTC) Wallet Address",
"Regex": "(?i)^(?:L|M)[a-z0-9]{33}$",
"Description": null,
"URL": "https://live.blockcypher.com/ltc/address/",
"Rarity": 0.5,
"Tags": [
"Cryptocurrency",
"Finance"
]
},
{
"Name": "Ripple (XRP) Wallet Address",
"Regex": "(?i)^r[a-z0-9]{33}$",
"Description": null,
"URL": "https://xrpscan.com/account/",
"Rarity": 0.5,
"Tags": [
"Cryptocurrency",
"Finance"
]
},
{
"Name": "American Express Card Number",
"Regex": "^3[47][0-9]{13}$",
Expand Down Expand Up @@ -239,24 +305,14 @@
},
{
"Name": "Email Address",
"Regex": "(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)",
"Regex": "(?i)(^[a-z0-9_.+-]+@[a-z0-9-]+\\.[a-z0-9-.]+$)",
"Description": null,
"Rarity": 0.5,
"Tags": [
"Identifiers",
"Credentials"
]
},
{
"Name": "YouTube Video ID",
"Regex": "^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]{1}$",
"Description": null,
"URL": "https://www.youtube.com/watch?v=",
"Rarity": 0.4,
"Tags": [
"Media"
]
},
{
"Name": "YouTube Channel ID",
"Regex": "^UC[0-9A-Za-z_-]{21}[AQgw]{1}$",
Expand All @@ -268,13 +324,13 @@
]
},
{
"Name": "Internet Protocol (IP) Address",
"Regex": "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
"Name": "YouTube Video ID",
"Regex": "^(?=.*[A-Z])(?=.*[a-z])[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]{1}$",
"Description": null,
"Rarity": 0.4,
"URL": "https://www.youtube.com/watch?v=",
"Rarity": 0.2,
"Tags": [
"Identifiers",
"Networking"
"Media"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion pywhat/printer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from rich.console import Console, OverflowMethod
from rich.console import Console
from rich.table import Table


Expand Down
76 changes: 73 additions & 3 deletions tests/test_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_arg_parsing2():
runner = CliRunner()
result = runner.invoke(main, ["http://10.1.1.1"])
assert result.exit_code == 0
assert re.findall("URL", str(result.output))
assert re.findall("Internet Protocol", str(result.output))


def test_file_fixture_visa():
Expand Down Expand Up @@ -175,11 +175,32 @@ def test_file_fixture_youtube_id():
assert re.findall("YouTube", str(result.output))


def test_file_fixture_ip():
def test_file_fixture_ip4():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Internet Protocol", str(result.output))
assert re.findall("Address Version 4", str(result.output))


def test_file_fixture_ip4_shodan():
runner = CliRunner()
result = runner.invoke(main, ["118.103.238.230"])
assert result.exit_code == 0
assert re.findall("shodan", str(result.output))


def test_file_fixture_ip6():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Address Version 6", str(result.output))


def test_file_fixture_ip6_shodan():
runner = CliRunner()
result = runner.invoke(main, ["2001:0db8:85a3:0000:0000:8a2e:0370:7334"])
assert result.exit_code == 0
assert re.findall("shodan", str(result.output))


def test_file_fixture_ssn():
Expand All @@ -204,6 +225,55 @@ def test_file_coords():
assert re.findall("Latitude", str(result.output))


def test_file_fixture_ltc():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Litecoin", str(result.output))


def test_file_fixture_ltc2():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("live.block", str(result.output))


def test_file_fixture_bch():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Bitcoin Cash", str(result.output))


def test_file_fixture_bch2():
runner = CliRunner()
result = runner.invoke(main, ["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"])
assert result.exit_code == 0
assert re.findall("blockchain", str(result.output))


def test_file_fixture_xrp():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Ripple", str(result.output))


def test_file_fixture_xrp2():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("xrpscan", str(result.output))


def test_file_fixture_xmr():
runner = CliRunner()
result = runner.invoke(main, ["fixtures/file"])
assert result.exit_code == 0
assert re.findall("Monero", str(result.output))


def test_file_cors():
runner = CliRunner()
result = runner.invoke(main, ["Access-Control-Allow: *"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_identifier_works():
r = identifier.Identifier()
out = r.identify("DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o")
assert "Dogecoin Wallet Address" in out["Regexes"][0]["Regex Pattern"]["Name"]
assert "Dogecoin (DOGE) Wallet Address" in out["Regexes"][0]["Regex Pattern"]["Name"]


def test_identifier_spanish():
Expand Down
Loading

0 comments on commit 8dd40dd

Please sign in to comment.