|
4 | 4 | from pathlib import Path
|
5 | 5 |
|
6 | 6 | from analysis.PluginBase import AnalysisBasePlugin
|
7 |
| -from typing import TYPE_CHECKING |
| 7 | +from typing import Any, TYPE_CHECKING |
8 | 8 |
|
9 | 9 | if TYPE_CHECKING:
|
10 | 10 | from objects.file import FileObject
|
|
19 | 19 | 'any_history': re.compile(rb'.+_history'),
|
20 | 20 | }
|
21 | 21 |
|
| 22 | +URL_REGEXES = { |
| 23 | + 'credentials_in_url': re.compile( |
| 24 | + rb'([a-zA-Z]{3,10}://[a-zA-Z0-9]{3,20}:[^/\s:@]{3,20}@[A-Za-z0-9._/:%?&${}=-]{7,100})["\'\s\x00]?' |
| 25 | + ) |
| 26 | +} |
| 27 | + |
22 | 28 | PATH_ARTIFACT_DICT = {
|
23 | 29 | '.git/config': 'git_config',
|
24 | 30 | '.svn/entries': 'svn_entries',
|
@@ -83,25 +89,31 @@ class AnalysisPlugin(AnalysisBasePlugin):
|
83 | 89 | 'application/x-sharedlib',
|
84 | 90 | 'text/plain',
|
85 | 91 | ]
|
86 |
| - VERSION = '0.1.4' |
| 92 | + VERSION = '0.2.0' |
87 | 93 | FILE = __file__
|
88 | 94 |
|
89 | 95 | def process_object(self, file_object: FileObject) -> FileObject:
|
90 |
| - file_object.processed_analysis[self.NAME] = {} |
91 | 96 | if file_object.processed_analysis['file_type']['result']['mime'] == 'text/plain':
|
92 |
| - self._find_artifacts(file_object) |
93 |
| - file_object.processed_analysis[self.NAME]['summary'] = sorted(file_object.processed_analysis[self.NAME]) |
| 97 | + result, summary = _find_artifacts(file_object) |
94 | 98 | else:
|
95 | 99 | result, summary = _find_regex(file_object.binary, PATH_REGEX)
|
96 |
| - file_object.processed_analysis[self.NAME].update(result) |
97 |
| - file_object.processed_analysis[self.NAME]['summary'] = summary |
| 100 | + |
| 101 | + url_result, url_summary = _find_regex(file_object.binary, URL_REGEXES) |
| 102 | + result.update(url_result) |
| 103 | + summary.extend(url_summary) |
| 104 | + |
| 105 | + file_object.processed_analysis[self.NAME] = result |
| 106 | + file_object.processed_analysis[self.NAME]['summary'] = summary |
98 | 107 | return file_object
|
99 | 108 |
|
100 |
| - def _find_artifacts(self, file_object: FileObject): |
101 |
| - # FixMe: after removal of duplicate unpacking/analysis, all VFPs will only be found after analysis update |
102 |
| - for virtual_path_list in file_object.virtual_file_path.values(): |
103 |
| - for virtual_path in virtual_path_list: |
104 |
| - file_object.processed_analysis[self.NAME].update(_check_file_path(virtual_path)) |
| 109 | + |
| 110 | +def _find_artifacts(file_object: FileObject) -> tuple[dict[str, Any], list[str]]: |
| 111 | + # FixMe: after removal of duplicate unpacking/analysis, all VFPs will only be found after analysis update |
| 112 | + result = {} |
| 113 | + for virtual_path_list in file_object.virtual_file_path.values(): |
| 114 | + for virtual_path in virtual_path_list: |
| 115 | + result.update(_check_file_path(virtual_path)) |
| 116 | + return result, sorted(result) |
105 | 117 |
|
106 | 118 |
|
107 | 119 | def _check_file_path(file_path: str) -> dict[str, list[str]]:
|
|
0 commit comments