Skip to content

Commit a565289

Browse files
committed
2 parents 80e4516 + 2e47f97 commit a565289

39 files changed

+938
-244
lines changed

.travis.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ python:
1313
- '3.8'
1414
- 'pypy3'
1515

16-
script: python -m unittest tests/tests.py
16+
script:
17+
- python -m unittest tests/tests.py
18+
- make -C docs html
19+
- touch docs/_build/html/.nojekyll
1720

1821
deploy:
1922
- provider: releases
@@ -27,6 +30,14 @@ deploy:
2730
skip_cleanup: true
2831
api_key:
2932
secure: IcX91IbJikIWp5p9AgJWKVpVIhpBZdpstQmz7hES9BnGdh1o/cLcIHcJGhpJXqSQ+kEspxw5DHMhKYFcKShWmj1TyG4TI1eCNycJ/F8f2d4TRBvucZxNfiPZF7GmxZrWEze6iFJ4p3KPBzwQ2zfggxYwbyEL5d73vfLcVc3nQDpoanRvF94EDobMuAeKk5P01OGRU2IK4pMi1ESOolUZr2XKiNaTgNqol5np/XI6Gte+Mlx8bo+AcVKCC+mSSVotrTsPsRErma9sVF9OYf8OH0jySwAt2tqvWRAC66R+inJMbH1qJdJ1EsO2hyF3N7pe9oIGJZkRqxd7Z20MTDg8zYCydbNQB/bsLZeA1fLmt5uQ3+AmIGnia27v7h5tGd5oeceMUbmXtYbX5midfvDXnpZcpqUE/8aUiN/Lq0Lr6qGGiSjvlynEYBWfMY5W4yLhpsKryTn/oaeBMAoMg2IY4BFkSZ+Evtu1RQe5EloYzwT/QjJ2LVO6Rb0ORZpmXUZcuFJOLoISFDqjaI5OpamDuxwKzvR6OGwq+sFYTR42rLN4YZ9NVbUb5AqkKdwqvo8qRiEtivkokbcNwRtMSgEnvD1TSLArYHQdY9gvLNP8CTyW6qO+0Wt1/DianqjYhsk3fBBHijfRbBBRqfyYNmipLm0cPZ1VW4OeBRF+A1OumRc=
33+
- provider: pages
34+
skip_cleanup: true
35+
local_dir: docs/_build/html/
36+
on:
37+
repo: ShellCode33/CredSLayer
38+
tags: true
39+
github_token:
40+
secure: IcX91IbJikIWp5p9AgJWKVpVIhpBZdpstQmz7hES9BnGdh1o/cLcIHcJGhpJXqSQ+kEspxw5DHMhKYFcKShWmj1TyG4TI1eCNycJ/F8f2d4TRBvucZxNfiPZF7GmxZrWEze6iFJ4p3KPBzwQ2zfggxYwbyEL5d73vfLcVc3nQDpoanRvF94EDobMuAeKk5P01OGRU2IK4pMi1ESOolUZr2XKiNaTgNqol5np/XI6Gte+Mlx8bo+AcVKCC+mSSVotrTsPsRErma9sVF9OYf8OH0jySwAt2tqvWRAC66R+inJMbH1qJdJ1EsO2hyF3N7pe9oIGJZkRqxd7Z20MTDg8zYCydbNQB/bsLZeA1fLmt5uQ3+AmIGnia27v7h5tGd5oeceMUbmXtYbX5midfvDXnpZcpqUE/8aUiN/Lq0Lr6qGGiSjvlynEYBWfMY5W4yLhpsKryTn/oaeBMAoMg2IY4BFkSZ+Evtu1RQe5EloYzwT/QjJ2LVO6Rb0ORZpmXUZcuFJOLoISFDqjaI5OpamDuxwKzvR6OGwq+sFYTR42rLN4YZ9NVbUb5AqkKdwqvo8qRiEtivkokbcNwRtMSgEnvD1TSLArYHQdY9gvLNP8CTyW6qO+0Wt1/DianqjYhsk3fBBHijfRbBBRqfyYNmipLm0cPZ1VW4OeBRF+A1OumRc=
3041
- provider: pypi
3142
distributions: sdist bdist_wheel
3243
skip_existing: true

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ This tool is really helpful if you're doing IT security or if you want to scan y
1414

1515
# Features
1616

17+
CredSLayer doesn't waste your time with invalid credentials, it makes sure credentials are valid.
18+
Yet if it's not able to tell whether they're valid or not, what has been found will be printed out anyway.
19+
1720
Right now, CredSLayer supports the following protocols:
1821
* FTP
1922
* SMTP / IMAP / POP3

credslayer/core/extract.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from credslayer.core.utils import CreditCard
77

88
# This regex has been made in order to prevent false positives, theoretically it can miss a few addresses.
9-
email_regex = re.compile(r'(?:\t| |^|<|,|:)([^+\x00-\x20@<>/\\{}`^\'*:;=()%\[\],_\-"]'
10-
r'[^\x00-\x20@<>/\\{}`^\'*:;=()%\[\],"]{2,63}@(?:[a-z0-9]{2,63}\.)+[a-z]{2,6})')
9+
_email_regex = re.compile(r'(?:\t| |^|<|,|:)([^+\x00-\x20@<>/\\{}`^\'*:;=()%\[\],_\-"]'
10+
r'[^\x00-\x20@<>/\\{}`^\'*:;=()%\[\],"]{2,63}@(?:[a-z0-9]{2,63}\.)+[a-z]{2,6})')
1111

1212
# Tries to match things that look like a credit card.
1313
# Things like 11111111-11111111 will also match, that's why there's a second step to validate that data.
14-
first_step_credit_card_regex = re.compile(r"(?:\s|^)(?:\d[ -]*?){13,16}(?:\s|$)")
14+
_first_step_credit_card_regex = re.compile(r"(?:\s|^)(?:\d[ -]*?){13,16}(?:\s|$)")
1515

1616
# https://gist.github.com/michaelkeevildown/9096cd3aac9029c4e6e05588448a8841
17-
second_step_credit_card_regex = re.compile(
17+
_second_step_credit_card_regex = re.compile(
1818
r"^(?P<AmericanExpress>3[47][0-9]{13})"
1919
r"|(?P<BCGlobal>(?:6541|6556)[0-9]{12})"
2020
r"|(?P<CarteBlanche>389[0-9]{11})"
@@ -41,11 +41,22 @@
4141
credit_cards_already_found = set()
4242

4343

44-
def extract_emails(packet_strings: List[str]) -> Set:
44+
def extract_emails(packet_strings: List[str]) -> Set[str]:
45+
"""
46+
Parameters
47+
----------
48+
packet_strings
49+
The list of strings to extract emails from.
50+
51+
Returns
52+
-------
53+
Set[str]
54+
A set of emails found.
55+
"""
4556
emails = set()
4657

4758
for string in packet_strings:
48-
emails_found = email_regex.findall(string)
59+
emails_found = _email_regex.findall(string)
4960

5061
for email_found in emails_found:
5162
if email_found not in emails_already_found:
@@ -56,17 +67,28 @@ def extract_emails(packet_strings: List[str]) -> Set:
5667

5768

5869
def extract_credit_cards(packet_strings: List[str]) -> Set[CreditCard]:
70+
"""
71+
Parameters
72+
----------
73+
packet_strings
74+
The list of strings to extract credit cards from.
75+
76+
Returns
77+
-------
78+
Set[CreditCard]
79+
A set of `CreditCard` tuple.
80+
"""
5981
credit_cards = set()
6082

6183
def clean_credit_card(card):
6284
return card.replace(" ", "").replace("-", "")
6385

6486
for string in packet_strings:
65-
credit_cards_found = first_step_credit_card_regex.findall(string)
87+
credit_cards_found = _first_step_credit_card_regex.findall(string)
6688

6789
for credit_card_found in credit_cards_found:
6890
credit_card_found = credit_card_found.strip() # Remove potential whitespaces
69-
credit_card_match = second_step_credit_card_regex.match(clean_credit_card(credit_card_found))
91+
credit_card_match = _second_step_credit_card_regex.match(clean_credit_card(credit_card_found))
7092

7193
if credit_card_match and credit_card_found not in credit_cards_already_found:
7294
credit_cards.add(CreditCard(credit_card_match.lastgroup, credit_card_found))

credslayer/core/logger.py

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def _log(content):
2424

2525

2626
def debug(*args):
27+
"""
28+
This should be used to display information to the developers, not the users.
29+
"""
30+
2731
if not DEBUG_MODE:
2832
return
2933

@@ -37,6 +41,10 @@ def debug(*args):
3741

3842

3943
def info(*args):
44+
"""
45+
This should be used to display - not necessarily - useful information to the users.
46+
"""
47+
4048
if len(args) == 2:
4149
session = args[0]
4250
msg = args[1]
@@ -47,8 +55,14 @@ def info(*args):
4755

4856

4957
def error(msg: str):
58+
"""
59+
This should be used when anything goes wrong (not necessarily fatal).
60+
"""
5061
_log("{}[ERROR]{} {}".format(Color.RED, Color.RESET, msg))
5162

5263

5364
def found(session: Session, msg: str):
65+
"""
66+
This should be used when something valuable has been found.
67+
"""
5468
_log("{}[{} {}] {}{}{}[FOUND]{} {}".format(Color.BRIGHT_BLUE, session.protocol, str(session), Color.RESET, Color.WHITE, Color.BACKGROUND_RED, Color.RESET, msg))

0 commit comments

Comments
 (0)