credsweeper 1.11.5__py3-none-any.whl → 1.11.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of credsweeper might be problematic. Click here for more details.
- credsweeper/__init__.py +21 -15
- credsweeper/__main__.py +141 -35
- credsweeper/app.py +11 -11
- credsweeper/config/__init__.py +0 -1
- credsweeper/config/config.py +1 -1
- credsweeper/credentials/__init__.py +0 -5
- credsweeper/credentials/augment_candidates.py +1 -1
- credsweeper/credentials/candidate.py +1 -1
- credsweeper/credentials/credential_manager.py +1 -1
- credsweeper/credentials/line_data.py +2 -2
- credsweeper/deep_scanner/__init__.py +0 -1
- credsweeper/deep_scanner/abstract_scanner.py +3 -3
- credsweeper/deep_scanner/byte_scanner.py +1 -1
- credsweeper/deep_scanner/bzip2_scanner.py +2 -2
- credsweeper/deep_scanner/deb_scanner.py +1 -1
- credsweeper/deep_scanner/deep_scanner.py +3 -3
- credsweeper/deep_scanner/docx_scanner.py +1 -1
- credsweeper/deep_scanner/eml_scanner.py +1 -1
- credsweeper/deep_scanner/encoder_scanner.py +1 -1
- credsweeper/deep_scanner/gzip_scanner.py +2 -2
- credsweeper/deep_scanner/html_scanner.py +1 -1
- credsweeper/deep_scanner/jclass_scanner.py +1 -1
- credsweeper/deep_scanner/jks_scanner.py +1 -1
- credsweeper/deep_scanner/lang_scanner.py +1 -1
- credsweeper/deep_scanner/lzma_scanner.py +2 -2
- credsweeper/deep_scanner/mxfile_scanner.py +1 -1
- credsweeper/deep_scanner/pdf_scanner.py +1 -1
- credsweeper/deep_scanner/pkcs_scanner.py +2 -2
- credsweeper/deep_scanner/pptx_scanner.py +1 -1
- credsweeper/deep_scanner/rpm_scanner.py +1 -1
- credsweeper/deep_scanner/tar_scanner.py +2 -2
- credsweeper/deep_scanner/tmx_scanner.py +2 -2
- credsweeper/deep_scanner/xlsx_scanner.py +2 -2
- credsweeper/deep_scanner/xml_scanner.py +1 -1
- credsweeper/deep_scanner/zip_scanner.py +2 -2
- credsweeper/file_handler/__init__.py +0 -15
- credsweeper/file_handler/abstract_provider.py +3 -4
- credsweeper/file_handler/byte_content_provider.py +1 -1
- credsweeper/file_handler/content_provider.py +1 -1
- credsweeper/file_handler/data_content_provider.py +1 -1
- credsweeper/file_handler/diff_content_provider.py +133 -3
- credsweeper/file_handler/file_path_extractor.py +2 -2
- credsweeper/file_handler/files_provider.py +4 -4
- credsweeper/file_handler/patches_provider.py +7 -8
- credsweeper/file_handler/text_content_provider.py +1 -1
- credsweeper/filters/__init__.py +1 -2
- credsweeper/filters/filter.py +2 -2
- credsweeper/filters/group/__init__.py +0 -2
- credsweeper/filters/group/general_keyword.py +2 -2
- credsweeper/filters/group/general_pattern.py +2 -2
- credsweeper/filters/group/group.py +16 -5
- credsweeper/filters/group/password_keyword.py +2 -2
- credsweeper/filters/group/token_pattern.py +2 -2
- credsweeper/filters/group/url_credentials_group.py +2 -2
- credsweeper/filters/group/weird_base36_token.py +2 -2
- credsweeper/filters/group/weird_base64_token.py +2 -2
- credsweeper/filters/line_git_binary_check.py +3 -3
- credsweeper/filters/line_specific_key_check.py +4 -4
- credsweeper/filters/line_uue_part_check.py +3 -3
- credsweeper/filters/value_allowlist_check.py +4 -4
- credsweeper/filters/value_array_dictionary_check.py +3 -3
- credsweeper/filters/value_atlassian_token_check.py +4 -4
- credsweeper/filters/value_azure_token_check.py +4 -4
- credsweeper/filters/value_base32_data_check.py +4 -4
- credsweeper/filters/value_base64_data_check.py +4 -4
- credsweeper/filters/value_base64_encoded_pem_check.py +4 -4
- credsweeper/filters/value_base64_key_check.py +4 -4
- credsweeper/filters/value_base64_part_check.py +4 -4
- credsweeper/filters/value_basic_auth_check.py +36 -0
- credsweeper/filters/value_blocklist_check.py +3 -3
- credsweeper/filters/value_camel_case_check.py +4 -4
- credsweeper/filters/value_couple_keyword_check.py +3 -3
- credsweeper/filters/value_dictionary_keyword_check.py +3 -3
- credsweeper/filters/value_dictionary_value_length_check.py +3 -3
- credsweeper/filters/value_discord_bot_check.py +4 -4
- credsweeper/filters/value_entropy_base_check.py +4 -4
- credsweeper/filters/value_file_path_check.py +5 -4
- credsweeper/filters/value_github_check.py +3 -3
- credsweeper/filters/value_grafana_check.py +4 -4
- credsweeper/filters/value_grafana_service_check.py +3 -3
- credsweeper/filters/value_hex_number_check.py +3 -3
- credsweeper/filters/value_jfrog_token_check.py +4 -4
- credsweeper/filters/value_json_web_key_check.py +4 -4
- credsweeper/filters/value_json_web_token_check.py +4 -4
- credsweeper/filters/value_last_word_check.py +3 -3
- credsweeper/filters/value_method_check.py +3 -3
- credsweeper/filters/value_not_allowed_pattern_check.py +4 -4
- credsweeper/filters/value_not_part_encoded_check.py +3 -3
- credsweeper/filters/value_number_check.py +3 -3
- credsweeper/filters/value_pattern_check.py +3 -3
- credsweeper/filters/value_similarity_check.py +3 -3
- credsweeper/filters/value_split_keyword_check.py +3 -3
- credsweeper/filters/value_string_type_check.py +3 -3
- credsweeper/filters/value_token_base_check.py +3 -3
- credsweeper/filters/value_token_check.py +3 -3
- credsweeper/logger/__init__.py +0 -1
- credsweeper/logger/logger.py +1 -1
- credsweeper/ml_model/__init__.py +0 -1
- credsweeper/ml_model/features/entropy_evaluation.py +1 -1
- credsweeper/ml_model/features/feature.py +1 -1
- credsweeper/ml_model/features/file_extension.py +1 -1
- credsweeper/ml_model/features/has_html_tag.py +2 -2
- credsweeper/ml_model/features/is_secret_numeric.py +1 -1
- credsweeper/ml_model/features/length_of_attribute.py +1 -1
- credsweeper/ml_model/features/morpheme_dense.py +1 -1
- credsweeper/ml_model/features/rule_name.py +1 -1
- credsweeper/ml_model/features/search_in_attribute.py +1 -1
- credsweeper/ml_model/features/word_in.py +1 -1
- credsweeper/ml_model/features/word_in_path.py +1 -1
- credsweeper/ml_model/features/word_in_postamble.py +1 -1
- credsweeper/ml_model/features/word_in_preamble.py +1 -1
- credsweeper/ml_model/features/word_in_transition.py +1 -1
- credsweeper/ml_model/features/word_in_value.py +1 -1
- credsweeper/ml_model/features/word_in_variable.py +1 -1
- credsweeper/ml_model/ml_validator.py +3 -2
- credsweeper/rules/__init__.py +0 -1
- credsweeper/rules/config.yaml +66 -19
- credsweeper/rules/rule.py +4 -3
- credsweeper/scanner/__init__.py +0 -1
- credsweeper/scanner/scan_type/__init__.py +0 -5
- credsweeper/scanner/scan_type/multi_pattern.py +4 -4
- credsweeper/scanner/scan_type/pem_key_pattern.py +4 -4
- credsweeper/scanner/scan_type/scan_type.py +4 -4
- credsweeper/scanner/scan_type/single_pattern.py +4 -4
- credsweeper/scanner/scanner.py +8 -5
- credsweeper/utils/__init__.py +0 -1
- credsweeper/utils/pem_key_detector.py +3 -3
- credsweeper/utils/util.py +1 -132
- {credsweeper-1.11.5.dist-info → credsweeper-1.11.6.dist-info}/METADATA +1 -1
- credsweeper-1.11.6.dist-info/RECORD +160 -0
- credsweeper-1.11.5.dist-info/RECORD +0 -159
- {credsweeper-1.11.5.dist-info → credsweeper-1.11.6.dist-info}/WHEEL +0 -0
- {credsweeper-1.11.5.dist-info → credsweeper-1.11.6.dist-info}/entry_points.txt +0 -0
- {credsweeper-1.11.5.dist-info → credsweeper-1.11.6.dist-info}/licenses/LICENSE +0 -0
|
@@ -9,8 +9,9 @@ from onnxruntime import InferenceSession
|
|
|
9
9
|
|
|
10
10
|
import credsweeper.ml_model.features as features
|
|
11
11
|
from credsweeper.common.constants import ThresholdPreset, ML_HUNK
|
|
12
|
-
from credsweeper.credentials import Candidate
|
|
13
|
-
from credsweeper.
|
|
12
|
+
from credsweeper.credentials.candidate import Candidate
|
|
13
|
+
from credsweeper.credentials.candidate_key import CandidateKey
|
|
14
|
+
from credsweeper.utils.util import Util
|
|
14
15
|
|
|
15
16
|
logger = logging.getLogger(__name__)
|
|
16
17
|
|
credsweeper/rules/__init__.py
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from credsweeper.rules.rule import Rule
|
credsweeper/rules/config.yaml
CHANGED
|
@@ -209,6 +209,20 @@
|
|
|
209
209
|
- code
|
|
210
210
|
- doc
|
|
211
211
|
|
|
212
|
+
- name: Akamai Credentials
|
|
213
|
+
severity: high
|
|
214
|
+
confidence: strong
|
|
215
|
+
type: pattern
|
|
216
|
+
values:
|
|
217
|
+
- (?P<value>akab-[0-9a-z]{16}-[0-9a-z]{16})(?!\.[0-9a-z-]{1,80}\.akamaiapis\.net)
|
|
218
|
+
filter_type: GeneralPattern
|
|
219
|
+
required_substrings:
|
|
220
|
+
- akab-
|
|
221
|
+
min_line_len: 38
|
|
222
|
+
target:
|
|
223
|
+
- code
|
|
224
|
+
- doc
|
|
225
|
+
|
|
212
226
|
- name: AWS Client ID
|
|
213
227
|
severity: high
|
|
214
228
|
confidence: moderate
|
|
@@ -1276,6 +1290,23 @@
|
|
|
1276
1290
|
- code
|
|
1277
1291
|
- doc
|
|
1278
1292
|
|
|
1293
|
+
- name: Docker Access Token
|
|
1294
|
+
severity: high
|
|
1295
|
+
confidence: strong
|
|
1296
|
+
type: pattern
|
|
1297
|
+
values:
|
|
1298
|
+
- (?P<value>dckr_[op]at_[0-9A-Za-z_-]{27,32})
|
|
1299
|
+
min_line_len: 36
|
|
1300
|
+
filter_type:
|
|
1301
|
+
- ValuePatternCheck
|
|
1302
|
+
- ValueEntropyBase64Check
|
|
1303
|
+
required_substrings:
|
|
1304
|
+
- dckr_pat_
|
|
1305
|
+
- dckr_oat_
|
|
1306
|
+
target:
|
|
1307
|
+
- code
|
|
1308
|
+
- doc
|
|
1309
|
+
|
|
1279
1310
|
- name: Docker Swarm Token
|
|
1280
1311
|
severity: high
|
|
1281
1312
|
confidence: strong
|
|
@@ -1434,45 +1465,61 @@
|
|
|
1434
1465
|
- code
|
|
1435
1466
|
- doc
|
|
1436
1467
|
|
|
1437
|
-
- name:
|
|
1468
|
+
- name: Basic Authorization
|
|
1469
|
+
severity: medium
|
|
1470
|
+
confidence: strong
|
|
1471
|
+
type: pattern
|
|
1472
|
+
values:
|
|
1473
|
+
- (?P<variable>(?i:basic))(?P<separator>\s+)(?P<value>[=0-9A-Za-z_/+-]{8,8000})(?![0-9A-Za-z_/+-])
|
|
1474
|
+
min_line_len: 18
|
|
1475
|
+
filter_type:
|
|
1476
|
+
- ValueBasicAuthCheck
|
|
1477
|
+
required_substrings:
|
|
1478
|
+
- basic
|
|
1479
|
+
target:
|
|
1480
|
+
- code
|
|
1481
|
+
- doc
|
|
1482
|
+
|
|
1483
|
+
- name: Bearer Authorization
|
|
1438
1484
|
severity: medium
|
|
1439
1485
|
confidence: moderate
|
|
1440
|
-
type:
|
|
1486
|
+
type: pattern
|
|
1441
1487
|
values:
|
|
1442
|
-
-
|
|
1488
|
+
- (?P<variable>(?i:bearer|ntlm))(?P<separator>\s+)(?P<value>[.0-9A-Za-z_/+-]{32,8000}=*)(?![0-9A-Za-z_/+-])
|
|
1489
|
+
min_line_len: 37
|
|
1443
1490
|
filter_type: GeneralKeyword
|
|
1444
|
-
use_ml: true
|
|
1445
|
-
min_line_len: 11
|
|
1446
1491
|
required_substrings:
|
|
1447
|
-
-
|
|
1492
|
+
- bearer
|
|
1493
|
+
- ntlm
|
|
1448
1494
|
target:
|
|
1449
1495
|
- code
|
|
1496
|
+
- doc
|
|
1450
1497
|
|
|
1451
|
-
- name:
|
|
1452
|
-
severity:
|
|
1498
|
+
- name: API
|
|
1499
|
+
severity: low
|
|
1453
1500
|
confidence: moderate
|
|
1454
1501
|
type: keyword
|
|
1455
1502
|
values:
|
|
1456
|
-
-
|
|
1503
|
+
- api(?!tal)
|
|
1457
1504
|
filter_type: GeneralKeyword
|
|
1458
1505
|
use_ml: true
|
|
1459
|
-
min_line_len:
|
|
1506
|
+
min_line_len: 11
|
|
1460
1507
|
required_substrings:
|
|
1461
|
-
-
|
|
1508
|
+
- api
|
|
1462
1509
|
target:
|
|
1463
1510
|
- code
|
|
1464
1511
|
|
|
1465
|
-
- name:
|
|
1512
|
+
- name: Auth
|
|
1466
1513
|
severity: medium
|
|
1467
1514
|
confidence: moderate
|
|
1468
1515
|
type: keyword
|
|
1469
1516
|
values:
|
|
1470
|
-
-
|
|
1517
|
+
- auth(?!ors?(?!i[tz]))
|
|
1471
1518
|
filter_type: GeneralKeyword
|
|
1472
1519
|
use_ml: true
|
|
1473
1520
|
min_line_len: 12
|
|
1474
1521
|
required_substrings:
|
|
1475
|
-
-
|
|
1522
|
+
- auth
|
|
1476
1523
|
target:
|
|
1477
1524
|
- code
|
|
1478
1525
|
|
|
@@ -1491,7 +1538,7 @@
|
|
|
1491
1538
|
- code
|
|
1492
1539
|
|
|
1493
1540
|
- name: Key
|
|
1494
|
-
severity:
|
|
1541
|
+
severity: high
|
|
1495
1542
|
confidence: moderate
|
|
1496
1543
|
type: keyword
|
|
1497
1544
|
values:
|
|
@@ -1505,7 +1552,7 @@
|
|
|
1505
1552
|
- code
|
|
1506
1553
|
|
|
1507
1554
|
- name: Nonce
|
|
1508
|
-
severity:
|
|
1555
|
+
severity: low
|
|
1509
1556
|
confidence: moderate
|
|
1510
1557
|
type: keyword
|
|
1511
1558
|
values:
|
|
@@ -1519,7 +1566,7 @@
|
|
|
1519
1566
|
- code
|
|
1520
1567
|
|
|
1521
1568
|
- name: Password
|
|
1522
|
-
severity:
|
|
1569
|
+
severity: high
|
|
1523
1570
|
confidence: moderate
|
|
1524
1571
|
type: keyword
|
|
1525
1572
|
values:
|
|
@@ -1534,7 +1581,7 @@
|
|
|
1534
1581
|
- code
|
|
1535
1582
|
|
|
1536
1583
|
- name: Salt
|
|
1537
|
-
severity:
|
|
1584
|
+
severity: low
|
|
1538
1585
|
confidence: moderate
|
|
1539
1586
|
type: keyword
|
|
1540
1587
|
values:
|
|
@@ -1562,7 +1609,7 @@
|
|
|
1562
1609
|
- code
|
|
1563
1610
|
|
|
1564
1611
|
- name: Token
|
|
1565
|
-
severity:
|
|
1612
|
+
severity: high
|
|
1566
1613
|
confidence: moderate
|
|
1567
1614
|
type: keyword
|
|
1568
1615
|
values:
|
credsweeper/rules/rule.py
CHANGED
|
@@ -7,9 +7,10 @@ from typing import Dict, List, Optional, Union, Set
|
|
|
7
7
|
from credsweeper import filters
|
|
8
8
|
from credsweeper.common.constants import RuleType, Severity, MAX_LINE_LENGTH, Confidence
|
|
9
9
|
from credsweeper.common.keyword_pattern import KeywordPattern
|
|
10
|
-
from credsweeper.config import Config
|
|
11
|
-
from credsweeper.filters import
|
|
12
|
-
from credsweeper.filters.
|
|
10
|
+
from credsweeper.config.config import Config
|
|
11
|
+
from credsweeper.filters import group
|
|
12
|
+
from credsweeper.filters.filter import Filter
|
|
13
|
+
from credsweeper.filters.group.group import Group
|
|
13
14
|
|
|
14
15
|
logger = logging.getLogger(__name__)
|
|
15
16
|
|
credsweeper/scanner/__init__.py
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from credsweeper.scanner.scanner import Scanner
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
from credsweeper.scanner.scan_type.scan_type import ScanType # isort:skip
|
|
2
|
-
|
|
3
|
-
from credsweeper.scanner.scan_type.multi_pattern import MultiPattern
|
|
4
|
-
from credsweeper.scanner.scan_type.pem_key_pattern import PemKeyPattern
|
|
5
|
-
from credsweeper.scanner.scan_type.single_pattern import SinglePattern
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from typing import List
|
|
2
2
|
|
|
3
3
|
from credsweeper.common.constants import RuleType
|
|
4
|
-
from credsweeper.config import Config
|
|
5
|
-
from credsweeper.credentials import Candidate
|
|
4
|
+
from credsweeper.config.config import Config
|
|
5
|
+
from credsweeper.credentials.candidate import Candidate
|
|
6
6
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
7
|
-
from credsweeper.rules import Rule
|
|
8
|
-
from credsweeper.scanner.scan_type import ScanType
|
|
7
|
+
from credsweeper.rules.rule import Rule
|
|
8
|
+
from credsweeper.scanner.scan_type.scan_type import ScanType
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class MultiPattern(ScanType):
|
|
@@ -2,11 +2,11 @@ import logging
|
|
|
2
2
|
from typing import List
|
|
3
3
|
|
|
4
4
|
from credsweeper.common.constants import RuleType
|
|
5
|
-
from credsweeper.config import Config
|
|
6
|
-
from credsweeper.credentials import Candidate
|
|
5
|
+
from credsweeper.config.config import Config
|
|
6
|
+
from credsweeper.credentials.candidate import Candidate
|
|
7
7
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
8
|
-
from credsweeper.rules import Rule
|
|
9
|
-
from credsweeper.scanner.scan_type import ScanType
|
|
8
|
+
from credsweeper.rules.rule import Rule
|
|
9
|
+
from credsweeper.scanner.scan_type.scan_type import ScanType
|
|
10
10
|
from credsweeper.utils.pem_key_detector import PemKeyDetector
|
|
11
11
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
@@ -4,11 +4,11 @@ from abc import ABC, abstractmethod
|
|
|
4
4
|
from typing import List
|
|
5
5
|
|
|
6
6
|
from credsweeper.common.constants import RuleType, MIN_DATA_LEN
|
|
7
|
-
from credsweeper.config import Config
|
|
8
|
-
from credsweeper.credentials import Candidate, LineData
|
|
7
|
+
from credsweeper.config.config import Config
|
|
8
|
+
from credsweeper.credentials.candidate import Candidate, LineData
|
|
9
9
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
10
|
-
from credsweeper.filters import Filter
|
|
11
|
-
from credsweeper.rules import Rule
|
|
10
|
+
from credsweeper.filters.filter import Filter
|
|
11
|
+
from credsweeper.rules.rule import Rule
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
14
14
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from typing import List
|
|
2
2
|
|
|
3
|
-
from credsweeper.config import Config
|
|
4
|
-
from credsweeper.credentials import Candidate
|
|
3
|
+
from credsweeper.config.config import Config
|
|
4
|
+
from credsweeper.credentials.candidate import Candidate
|
|
5
5
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
6
|
-
from credsweeper.rules import Rule
|
|
7
|
-
from credsweeper.scanner.scan_type import ScanType
|
|
6
|
+
from credsweeper.rules.rule import Rule
|
|
7
|
+
from credsweeper.scanner.scan_type.scan_type import ScanType
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class SinglePattern(ScanType):
|
credsweeper/scanner/scanner.py
CHANGED
|
@@ -6,13 +6,16 @@ from typing import List, Type, Tuple, Union, Dict, Generator, Set
|
|
|
6
6
|
from credsweeper.app import APP_PATH
|
|
7
7
|
from credsweeper.common.constants import RuleType, MIN_VARIABLE_LENGTH, MIN_SEPARATOR_LENGTH, MIN_VALUE_LENGTH, \
|
|
8
8
|
MAX_LINE_LENGTH, PEM_BEGIN_PATTERN
|
|
9
|
-
from credsweeper.config import Config
|
|
10
|
-
from credsweeper.credentials import Candidate
|
|
9
|
+
from credsweeper.config.config import Config
|
|
10
|
+
from credsweeper.credentials.candidate import Candidate
|
|
11
11
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
12
12
|
from credsweeper.file_handler.content_provider import ContentProvider
|
|
13
|
-
from credsweeper.rules import Rule
|
|
14
|
-
from credsweeper.scanner.scan_type import
|
|
15
|
-
from credsweeper.
|
|
13
|
+
from credsweeper.rules.rule import Rule
|
|
14
|
+
from credsweeper.scanner.scan_type.multi_pattern import MultiPattern
|
|
15
|
+
from credsweeper.scanner.scan_type.pem_key_pattern import PemKeyPattern
|
|
16
|
+
from credsweeper.scanner.scan_type.scan_type import ScanType
|
|
17
|
+
from credsweeper.scanner.scan_type.single_pattern import SinglePattern
|
|
18
|
+
from credsweeper.utils.util import Util
|
|
16
19
|
|
|
17
20
|
logger = logging.getLogger(__name__)
|
|
18
21
|
|
credsweeper/utils/__init__.py
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from credsweeper.utils.util import DiffRowData, Util, DiffDict
|
|
@@ -5,10 +5,10 @@ import string
|
|
|
5
5
|
from typing import List
|
|
6
6
|
|
|
7
7
|
from credsweeper.common.constants import PEM_BEGIN_PATTERN, PEM_END_PATTERN, Chars
|
|
8
|
-
from credsweeper.config import Config
|
|
9
|
-
from credsweeper.credentials import LineData
|
|
8
|
+
from credsweeper.config.config import Config
|
|
9
|
+
from credsweeper.credentials.line_data import LineData
|
|
10
10
|
from credsweeper.file_handler.analysis_target import AnalysisTarget
|
|
11
|
-
from credsweeper.utils import Util
|
|
11
|
+
from credsweeper.utils.util import Util
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
14
14
|
|
credsweeper/utils/util.py
CHANGED
|
@@ -9,12 +9,10 @@ import random
|
|
|
9
9
|
import re
|
|
10
10
|
import string
|
|
11
11
|
import tarfile
|
|
12
|
-
from dataclasses import dataclass
|
|
13
12
|
from pathlib import Path
|
|
14
13
|
from typing import Any, Dict, List, Tuple, Optional, Union
|
|
15
14
|
|
|
16
15
|
import numpy as np
|
|
17
|
-
import whatthepatch
|
|
18
16
|
import yaml
|
|
19
17
|
from cryptography.hazmat.primitives import hashes
|
|
20
18
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
@@ -29,31 +27,12 @@ from cryptography.hazmat.primitives.asymmetric.x448 import X448PublicKey, X448Pr
|
|
|
29
27
|
from cryptography.hazmat.primitives.serialization import load_der_private_key
|
|
30
28
|
from cryptography.hazmat.primitives.serialization.pkcs12 import load_key_and_certificates
|
|
31
29
|
from lxml import etree
|
|
32
|
-
from typing_extensions import TypedDict
|
|
33
30
|
|
|
34
|
-
from credsweeper.common.constants import
|
|
31
|
+
from credsweeper.common.constants import AVAILABLE_ENCODINGS, \
|
|
35
32
|
DEFAULT_ENCODING, LATIN_1, CHUNK_SIZE, MAX_LINE_LENGTH, CHUNK_STEP_SIZE, ASCII
|
|
36
33
|
|
|
37
34
|
logger = logging.getLogger(__name__)
|
|
38
35
|
|
|
39
|
-
DiffDict = TypedDict(
|
|
40
|
-
"DiffDict",
|
|
41
|
-
{
|
|
42
|
-
"old": Optional[int], #
|
|
43
|
-
"new": Optional[int], #
|
|
44
|
-
"line": Union[str, bytes], # bytes are possibly since whatthepatch v1.0.4
|
|
45
|
-
"hunk": Any # not used
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@dataclass(frozen=True)
|
|
50
|
-
class DiffRowData:
|
|
51
|
-
"""Class for keeping data of diff row."""
|
|
52
|
-
|
|
53
|
-
line_type: DiffRowType
|
|
54
|
-
line_numb: int
|
|
55
|
-
line: str
|
|
56
|
-
|
|
57
36
|
|
|
58
37
|
class Util:
|
|
59
38
|
"""Class that contains different useful methods."""
|
|
@@ -277,116 +256,6 @@ class Util:
|
|
|
277
256
|
lines = []
|
|
278
257
|
return lines
|
|
279
258
|
|
|
280
|
-
@staticmethod
|
|
281
|
-
def patch2files_diff(raw_patch: List[str], change_type: DiffRowType) -> Dict[str, List[DiffDict]]:
|
|
282
|
-
"""Generate files changes from patch for added or deleted filepaths.
|
|
283
|
-
|
|
284
|
-
Args:
|
|
285
|
-
raw_patch: git patch file content
|
|
286
|
-
change_type: change type to select, DiffRowType.ADDED or DiffRowType.DELETED
|
|
287
|
-
|
|
288
|
-
Return:
|
|
289
|
-
return dict with ``{file paths: list of file row changes}``, where
|
|
290
|
-
elements of list of file row changes represented as::
|
|
291
|
-
|
|
292
|
-
{
|
|
293
|
-
"old": line number before diff,
|
|
294
|
-
"new": line number after diff,
|
|
295
|
-
"line": line text,
|
|
296
|
-
"hunk": diff hunk number
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
"""
|
|
300
|
-
if not raw_patch:
|
|
301
|
-
return {}
|
|
302
|
-
|
|
303
|
-
added_files, deleted_files = {}, {}
|
|
304
|
-
try:
|
|
305
|
-
for patch in whatthepatch.parse_patch(raw_patch):
|
|
306
|
-
if patch.changes is None:
|
|
307
|
-
logger.warning(f"Patch '{str(patch.header)}' cannot be scanned")
|
|
308
|
-
continue
|
|
309
|
-
changes = []
|
|
310
|
-
for change in patch.changes:
|
|
311
|
-
change_dict = change._asdict()
|
|
312
|
-
changes.append(change_dict)
|
|
313
|
-
|
|
314
|
-
added_files[patch.header.new_path] = changes
|
|
315
|
-
deleted_files[patch.header.old_path] = changes
|
|
316
|
-
if change_type == DiffRowType.ADDED:
|
|
317
|
-
return added_files
|
|
318
|
-
elif change_type == DiffRowType.DELETED:
|
|
319
|
-
return deleted_files
|
|
320
|
-
else:
|
|
321
|
-
logger.error(f"Change type should be one of: '{DiffRowType.ADDED}', '{DiffRowType.DELETED}';"
|
|
322
|
-
f" but received {change_type}")
|
|
323
|
-
except Exception as exc:
|
|
324
|
-
logger.exception(exc)
|
|
325
|
-
return {}
|
|
326
|
-
|
|
327
|
-
@staticmethod
|
|
328
|
-
def preprocess_diff_rows(
|
|
329
|
-
added_line_number: Optional[int], #
|
|
330
|
-
deleted_line_number: Optional[int], #
|
|
331
|
-
line: str) -> List[DiffRowData]:
|
|
332
|
-
"""Auxiliary function to extend diff changes.
|
|
333
|
-
|
|
334
|
-
Args:
|
|
335
|
-
added_line_number: number of added line or None
|
|
336
|
-
deleted_line_number: number of deleted line or None
|
|
337
|
-
line: the text line
|
|
338
|
-
|
|
339
|
-
Return:
|
|
340
|
-
diff rows data with as list of row change type, line number, row content
|
|
341
|
-
|
|
342
|
-
"""
|
|
343
|
-
rows_data: List[DiffRowData] = []
|
|
344
|
-
if isinstance(added_line_number, int):
|
|
345
|
-
# indicates line was inserted
|
|
346
|
-
rows_data.append(DiffRowData(DiffRowType.ADDED, added_line_number, line))
|
|
347
|
-
if isinstance(deleted_line_number, int):
|
|
348
|
-
# indicates line was removed
|
|
349
|
-
rows_data.append(DiffRowData(DiffRowType.DELETED, deleted_line_number, line))
|
|
350
|
-
return rows_data
|
|
351
|
-
|
|
352
|
-
@staticmethod
|
|
353
|
-
def wrong_change(change: DiffDict) -> bool:
|
|
354
|
-
"""Returns True if the change is wrong"""
|
|
355
|
-
for i in ["line", "new", "old"]:
|
|
356
|
-
if i not in change:
|
|
357
|
-
logger.error(f"Skipping wrong change {change}")
|
|
358
|
-
return True
|
|
359
|
-
return False
|
|
360
|
-
|
|
361
|
-
@staticmethod
|
|
362
|
-
def preprocess_file_diff(changes: List[DiffDict]) -> List[DiffRowData]:
|
|
363
|
-
"""Generate changed file rows from diff data with changed lines (e.g. marked + or - in diff).
|
|
364
|
-
|
|
365
|
-
Args:
|
|
366
|
-
changes: git diff by file rows data
|
|
367
|
-
|
|
368
|
-
Return:
|
|
369
|
-
diff rows data with as list of row change type, line number, row content
|
|
370
|
-
|
|
371
|
-
"""
|
|
372
|
-
if not changes:
|
|
373
|
-
return []
|
|
374
|
-
|
|
375
|
-
rows_data = []
|
|
376
|
-
# process diff to restore lines and their positions
|
|
377
|
-
for change in changes:
|
|
378
|
-
if Util.wrong_change(change):
|
|
379
|
-
continue
|
|
380
|
-
line = change["line"]
|
|
381
|
-
if isinstance(line, str):
|
|
382
|
-
rows_data.extend(Util.preprocess_diff_rows(change.get("new"), change.get("old"), line))
|
|
383
|
-
elif isinstance(line, (bytes, bytearray)):
|
|
384
|
-
logger.warning("The feature is available with the deep scan option")
|
|
385
|
-
else:
|
|
386
|
-
logger.error(f"Unknown type of line {type(line)}")
|
|
387
|
-
|
|
388
|
-
return rows_data
|
|
389
|
-
|
|
390
259
|
@staticmethod
|
|
391
260
|
def is_zip(data: Union[bytes, bytearray]) -> bool:
|
|
392
261
|
"""According https://en.wikipedia.org/wiki/List_of_file_signatures"""
|