-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strict rules for github classic token
- Loading branch information
Showing
24 changed files
with
900 additions
and
976 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import binascii | ||
import contextlib | ||
|
||
import base62 | ||
|
||
from credsweeper.common.constants import ASCII | ||
from credsweeper.config import Config | ||
from credsweeper.credentials import LineData | ||
from credsweeper.file_handler.analysis_target import AnalysisTarget | ||
from credsweeper.filters import Filter | ||
|
||
|
||
class ValueGitHubCheck(Filter): | ||
"""GitHub Classic Token validation""" | ||
|
||
def __init__(self, config: Config = None) -> None: | ||
pass | ||
|
||
def run(self, line_data: LineData, target: AnalysisTarget) -> bool: | ||
"""Run filter checks on received token which might be structured. | ||
Args: | ||
line_data: credential candidate data | ||
target: multiline target from which line data was obtained | ||
Return: | ||
True, when need to filter candidate and False if left | ||
""" | ||
# https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/ | ||
if not line_data.value: | ||
return True | ||
with contextlib.suppress(Exception): | ||
if line_data.value.startswith("gh") and '_' == line_data.value[3]: | ||
token = line_data.value[4:-6] | ||
data = token.encode(ASCII, errors="strict") | ||
crc32sum = binascii.crc32(data) | ||
base62_crc32 = line_data.value[-6:] | ||
sign_b = base62.decodebytes(base62_crc32) | ||
crc32sign = int.from_bytes(sign_b, "big") | ||
if crc32sign == crc32sum: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
"onnxruntime", # | ||
"python-dateutil", # | ||
"pyjks", # | ||
"pybase62", # | ||
] | ||
|
||
setuptools.setup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.