-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip actions] [cmdpass] 2024-08-31T12:52:24+03:00
- Loading branch information
Showing
13 changed files
with
460 additions
and
302 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Most rules are described in 'Secrets in Source Code: Reducing False Positives Using Machine Learning'.""" | ||
import contextlib | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
from typing import List, Any, Dict, Tuple, Set | ||
|
||
import numpy as np | ||
|
||
from credsweeper.common.constants import Base, Chars, CHUNK_SIZE | ||
from credsweeper.credentials import Candidate | ||
from credsweeper.ml_model.features import Feature | ||
from credsweeper.utils import Util | ||
|
||
|
||
|
||
class CharSet(Feature): | ||
"""Feature is true when all characters of the value are from a set.""" | ||
|
||
# Constant dictionary to get characters set via name | ||
CHARS: Dict[Base, str] = { # | ||
Base.base16upper: Chars.BASE16UPPER.value, # | ||
Base.base16lower: Chars.BASE16LOWER.value, # | ||
Base.base32: Chars.BASE32_CHARS.value, # | ||
Base.base36: Chars.BASE36_CHARS.value, # | ||
Base.base64std: Chars.BASE64STD_CHARS.value + '=', # | ||
Base.base64url: Chars.BASE64URL_CHARS.value + '=', # | ||
} | ||
|
||
def __init__(self, base: str) -> None: | ||
"""CharSet class initializer. | ||
Args: | ||
base: base set ID | ||
""" | ||
super().__init__() | ||
self.base: Base = getattr(Base, base) | ||
|
||
def extract(self, candidate: Candidate) -> bool: | ||
with contextlib.suppress(Exception): | ||
for i in self.CHARS[self.base]: | ||
if i not in candidate.line_data_list[0].value: | ||
break | ||
else: | ||
return True | ||
return False | ||
|
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.