secator 0.0.1__py3-none-any.whl → 0.3.5__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 secator might be problematic. Click here for more details.

Files changed (68) hide show
  1. secator/.gitignore +162 -0
  2. secator/celery.py +8 -68
  3. secator/cli.py +631 -274
  4. secator/decorators.py +42 -6
  5. secator/definitions.py +104 -33
  6. secator/exporters/csv.py +1 -2
  7. secator/exporters/gdrive.py +1 -1
  8. secator/exporters/json.py +1 -2
  9. secator/exporters/txt.py +1 -2
  10. secator/hooks/mongodb.py +12 -12
  11. secator/installer.py +335 -0
  12. secator/report.py +2 -14
  13. secator/rich.py +3 -10
  14. secator/runners/_base.py +106 -34
  15. secator/runners/_helpers.py +18 -17
  16. secator/runners/command.py +91 -55
  17. secator/runners/scan.py +3 -1
  18. secator/runners/task.py +6 -4
  19. secator/runners/workflow.py +13 -11
  20. secator/tasks/_categories.py +14 -19
  21. secator/tasks/cariddi.py +2 -1
  22. secator/tasks/dalfox.py +2 -0
  23. secator/tasks/dirsearch.py +5 -7
  24. secator/tasks/dnsx.py +1 -0
  25. secator/tasks/dnsxbrute.py +1 -0
  26. secator/tasks/feroxbuster.py +6 -7
  27. secator/tasks/ffuf.py +4 -7
  28. secator/tasks/gau.py +1 -4
  29. secator/tasks/gf.py +2 -1
  30. secator/tasks/gospider.py +1 -0
  31. secator/tasks/grype.py +47 -47
  32. secator/tasks/h8mail.py +5 -6
  33. secator/tasks/httpx.py +24 -18
  34. secator/tasks/katana.py +11 -15
  35. secator/tasks/maigret.py +3 -3
  36. secator/tasks/mapcidr.py +1 -0
  37. secator/tasks/msfconsole.py +3 -1
  38. secator/tasks/naabu.py +2 -1
  39. secator/tasks/nmap.py +14 -17
  40. secator/tasks/nuclei.py +4 -3
  41. secator/tasks/searchsploit.py +4 -2
  42. secator/tasks/subfinder.py +1 -0
  43. secator/tasks/wpscan.py +11 -13
  44. secator/utils.py +64 -82
  45. secator/utils_test.py +3 -2
  46. secator-0.3.5.dist-info/METADATA +411 -0
  47. secator-0.3.5.dist-info/RECORD +100 -0
  48. {secator-0.0.1.dist-info → secator-0.3.5.dist-info}/WHEEL +1 -2
  49. secator-0.0.1.dist-info/METADATA +0 -199
  50. secator-0.0.1.dist-info/RECORD +0 -114
  51. secator-0.0.1.dist-info/top_level.txt +0 -2
  52. tests/__init__.py +0 -0
  53. tests/integration/__init__.py +0 -0
  54. tests/integration/inputs.py +0 -42
  55. tests/integration/outputs.py +0 -392
  56. tests/integration/test_scans.py +0 -82
  57. tests/integration/test_tasks.py +0 -103
  58. tests/integration/test_workflows.py +0 -163
  59. tests/performance/__init__.py +0 -0
  60. tests/performance/loadtester.py +0 -56
  61. tests/unit/__init__.py +0 -0
  62. tests/unit/test_celery.py +0 -39
  63. tests/unit/test_scans.py +0 -0
  64. tests/unit/test_serializers.py +0 -51
  65. tests/unit/test_tasks.py +0 -348
  66. tests/unit/test_workflows.py +0 -96
  67. {secator-0.0.1.dist-info → secator-0.3.5.dist-info}/entry_points.txt +0 -0
  68. {secator-0.0.1.dist-info → secator-0.3.5.dist-info/licenses}/LICENSE +0 -0
secator/installer.py ADDED
@@ -0,0 +1,335 @@
1
+
2
+ import requests
3
+ import os
4
+ import platform
5
+ import shutil
6
+ import tarfile
7
+ import zipfile
8
+ import io
9
+
10
+ from rich.table import Table
11
+
12
+ from secator.rich import console
13
+ from secator.runners import Command
14
+ from secator.definitions import BIN_FOLDER, GITHUB_TOKEN
15
+
16
+
17
+ class ToolInstaller:
18
+
19
+ @classmethod
20
+ def install(cls, tool_cls):
21
+ """Install a tool.
22
+
23
+ Args:
24
+ cls: ToolInstaller class.
25
+ tool_cls: Tool class (derived from secator.runners.Command).
26
+
27
+ Returns:
28
+ bool: True if install is successful, False otherwise.
29
+ """
30
+ console.print(f'[bold gold3]:wrench: Installing {tool_cls.__name__}')
31
+ success = False
32
+
33
+ if not tool_cls.install_github_handle and not tool_cls.install_cmd:
34
+ console.print(
35
+ f'[bold red]{tool_cls.__name__} install is not supported yet. Please install it manually.[/]')
36
+ return False
37
+
38
+ if tool_cls.install_github_handle:
39
+ success = GithubInstaller.install(tool_cls.install_github_handle)
40
+
41
+ if tool_cls.install_cmd and not success:
42
+ success = SourceInstaller.install(tool_cls.install_cmd)
43
+
44
+ if success:
45
+ console.print(
46
+ f'[bold green]:tada: {tool_cls.__name__} installed successfully[/] !')
47
+ else:
48
+ console.print(
49
+ f'[bold red]:exclamation_mark: Failed to install {tool_cls.__name__}.[/]')
50
+ return success
51
+
52
+
53
+ class SourceInstaller:
54
+ """Install a tool from source."""
55
+
56
+ @classmethod
57
+ def install(cls, install_cmd):
58
+ """Install from source.
59
+
60
+ Args:
61
+ cls: ToolInstaller class.
62
+ install_cmd (str): Install command.
63
+
64
+ Returns:
65
+ bool: True if install is successful, False otherwise.
66
+ """
67
+ ret = Command.execute(install_cmd, cls_attributes={'shell': True})
68
+ return ret.return_code == 0
69
+
70
+
71
+ class GithubInstaller:
72
+ """Install a tool from GitHub releases."""
73
+
74
+ @classmethod
75
+ def install(cls, github_handle):
76
+ """Find and install a release from a GitHub handle {user}/{repo}.
77
+
78
+ Args:
79
+ github_handle (str): A GitHub handle {user}/{repo}
80
+
81
+ Returns:
82
+ bool: True if install is successful, False otherwise.
83
+ """
84
+ _, repo = tuple(github_handle.split('/'))
85
+ latest_release = cls.get_latest_release(github_handle)
86
+ if not latest_release:
87
+ return False
88
+
89
+ # Find the right asset to download
90
+ os_identifiers, arch_identifiers = cls._get_platform_identifier()
91
+ download_url = cls._find_matching_asset(latest_release['assets'], os_identifiers, arch_identifiers)
92
+ if not download_url:
93
+ console.print('[dim red]Could not find a GitHub release matching distribution.[/]')
94
+ return False
95
+
96
+ # Download and unpack asset
97
+ console.print(f'Found release URL: {download_url}')
98
+ cls._download_and_unpack(download_url, BIN_FOLDER, repo)
99
+ return True
100
+
101
+ @classmethod
102
+ def get_latest_release(cls, github_handle):
103
+ """Get latest release from GitHub.
104
+
105
+ Args:
106
+ github_handle (str): A GitHub handle {user}/{repo}.
107
+
108
+ Returns:
109
+ dict: Latest release JSON from GitHub releases.
110
+ """
111
+ if not github_handle:
112
+ return False
113
+ owner, repo = tuple(github_handle.split('/'))
114
+ url = f"https://api.github.com/repos/{owner}/{repo}/releases/latest"
115
+ headers = {}
116
+ if GITHUB_TOKEN:
117
+ headers['Authorization'] = f'Bearer {GITHUB_TOKEN}'
118
+ try:
119
+ response = requests.get(url, headers=headers, timeout=5)
120
+ response.raise_for_status()
121
+ latest_release = response.json()
122
+ return latest_release
123
+ except requests.RequestException as e:
124
+ console.print(f'Failed to fetch latest release for {github_handle}: {str(e)}')
125
+ return None
126
+
127
+ @classmethod
128
+ def get_latest_version(cls, github_handle):
129
+ latest_release = cls.get_latest_release(github_handle)
130
+ if not latest_release:
131
+ return None
132
+ return latest_release['tag_name'].lstrip('v')
133
+
134
+ @classmethod
135
+ def _get_platform_identifier(cls):
136
+ """Generate lists of possible identifiers for the current platform."""
137
+ system = platform.system().lower()
138
+ arch = platform.machine().lower()
139
+
140
+ # Mapping common platform.system() values to those found in release names
141
+ os_mapping = {
142
+ 'linux': ['linux'],
143
+ 'windows': ['windows', 'win'],
144
+ 'darwin': ['darwin', 'macos', 'osx', 'mac']
145
+ }
146
+
147
+ # Enhanced architecture mapping to avoid conflicts
148
+ arch_mapping = {
149
+ 'x86_64': ['amd64', 'x86_64'],
150
+ 'amd64': ['amd64', 'x86_64'],
151
+ 'aarch64': ['arm64', 'aarch64'],
152
+ 'armv7l': ['armv7', 'arm'],
153
+ '386': ['386', 'x86', 'i386'],
154
+ }
155
+
156
+ os_identifiers = os_mapping.get(system, [])
157
+ arch_identifiers = arch_mapping.get(arch, [])
158
+ return os_identifiers, arch_identifiers
159
+
160
+ @classmethod
161
+ def _find_matching_asset(cls, assets, os_identifiers, arch_identifiers):
162
+ """Find a release asset matching the current platform more precisely."""
163
+ potential_matches = []
164
+
165
+ for asset in assets:
166
+ asset_name = asset['name'].lower()
167
+ if any(os_id in asset_name for os_id in os_identifiers) and \
168
+ any(arch_id in asset_name for arch_id in arch_identifiers):
169
+ potential_matches.append(asset['browser_download_url'])
170
+
171
+ # Preference ordering for file formats, if needed
172
+ preferred_formats = ['.tar.gz', '.zip']
173
+
174
+ for format in preferred_formats:
175
+ for match in potential_matches:
176
+ if match.endswith(format):
177
+ return match
178
+
179
+ if potential_matches:
180
+ return potential_matches[0]
181
+
182
+ @classmethod
183
+ def _download_and_unpack(cls, url, destination, repo_name):
184
+ """Download and unpack a release asset."""
185
+ console.print(f'Downloading and unpacking to {destination}...')
186
+ response = requests.get(url, timeout=5)
187
+ response.raise_for_status()
188
+
189
+ # Create a temporary directory to extract the archive
190
+ temp_dir = os.path.join("/tmp", repo_name)
191
+ os.makedirs(temp_dir, exist_ok=True)
192
+
193
+ if url.endswith('.zip'):
194
+ with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
195
+ zip_ref.extractall(temp_dir)
196
+ elif url.endswith('.tar.gz'):
197
+ with tarfile.open(fileobj=io.BytesIO(response.content), mode='r:gz') as tar:
198
+ tar.extractall(path=temp_dir)
199
+
200
+ # For archives, find and move the binary that matches the repo name
201
+ binary_path = cls._find_binary_in_directory(temp_dir, repo_name)
202
+ if binary_path:
203
+ os.chmod(binary_path, 0o755) # Make it executable
204
+ shutil.move(binary_path, os.path.join(destination, repo_name)) # Move the binary
205
+ else:
206
+ console.print('[bold red]Binary matching the repository name was not found in the archive.[/]')
207
+
208
+ @classmethod
209
+ def _find_binary_in_directory(cls, directory, binary_name):
210
+ """Search for the binary in the given directory that matches the repository name."""
211
+ for root, _, files in os.walk(directory):
212
+ for file in files:
213
+ # Match the file name exactly with the repository name
214
+ if file == binary_name:
215
+ return os.path.join(root, file)
216
+ return None
217
+
218
+
219
+ def which(command):
220
+ """Run which on a command.
221
+
222
+ Args:
223
+ command (str): Command to check.
224
+
225
+ Returns:
226
+ secator.Command: Command instance.
227
+ """
228
+ return Command.execute(f'which {command}', quiet=True, print_errors=False)
229
+
230
+
231
+ def get_version(version_cmd):
232
+ """Run version command and match first version number found.
233
+
234
+ Args:
235
+ version_cmd (str): Command to get the version.
236
+
237
+ Returns:
238
+ str: Version string.
239
+ """
240
+ from secator.runners import Command
241
+ import re
242
+ regex = r'[0-9]+\.[0-9]+\.?[0-9]*\.?[a-zA-Z]*'
243
+ ret = Command.execute(version_cmd, quiet=True, print_errors=False)
244
+ match = re.findall(regex, ret.output)
245
+ if not match:
246
+ return ''
247
+ return match[0]
248
+
249
+
250
+ def get_version_info(name, version_flag=None, github_handle=None, version=None):
251
+ """Get version info for a command.
252
+
253
+ Args:
254
+ name (str): Command name.
255
+ version_flag (str): Version flag.
256
+ github_handle (str): Github handle.
257
+ version (str): Existing version.
258
+
259
+ Return:
260
+ dict: Version info.
261
+ """
262
+ from packaging import version as _version
263
+ from secator.installer import GithubInstaller
264
+ info = {
265
+ 'name': name,
266
+ 'installed': False,
267
+ 'version': version,
268
+ 'latest_version': None,
269
+ 'location': None,
270
+ 'status': ''
271
+ }
272
+
273
+ # Get binary path
274
+ location = which(name).output
275
+ info['location'] = location
276
+
277
+ # Get current version
278
+ if version_flag:
279
+ version_cmd = f'{name} {version_flag}'
280
+ version = get_version(version_cmd)
281
+ info['version'] = version
282
+
283
+ # Get latest version
284
+ latest_version = GithubInstaller.get_latest_version(github_handle)
285
+ info['latest_version'] = latest_version
286
+
287
+ if location:
288
+ info['installed'] = True
289
+ if version and latest_version:
290
+ if _version.parse(version) < _version.parse(latest_version):
291
+ info['status'] = 'outdated'
292
+ else:
293
+ info['status'] = 'latest'
294
+ elif not version:
295
+ info['status'] = 'current unknown'
296
+ elif not latest_version:
297
+ info['status'] = 'latest unknown'
298
+ else:
299
+ info['status'] = 'missing'
300
+
301
+ return info
302
+
303
+
304
+ def fmt_health_table_row(version_info, category=None):
305
+ name = version_info['name']
306
+ version = version_info['version']
307
+ status = version_info['status']
308
+ installed = version_info['installed']
309
+ name_str = f'[magenta]{name:<13}[/]'
310
+
311
+ # Format version row
312
+ _version = version or ''
313
+ _version = f'[bold green]{_version:<10}[/]'
314
+ if status == 'latest':
315
+ _version += ' [bold green](latest)[/]'
316
+ elif status == 'outdated':
317
+ _version += ' [bold red](outdated)[/]'
318
+ elif status == 'missing':
319
+ _version = '[bold red]missing[/]'
320
+ elif status == 'ok':
321
+ _version = '[bold green]ok [/]'
322
+ elif status:
323
+ if not version and installed:
324
+ _version = '[bold green]ok [/]'
325
+ _version += f' [dim]({status}[/])'
326
+
327
+ row = (name_str, _version)
328
+ return row
329
+
330
+
331
+ def get_health_table():
332
+ table = Table(box=None, show_header=False)
333
+ for col in ['name', 'version']:
334
+ table.add_column(col)
335
+ return table
secator/report.py CHANGED
@@ -1,10 +1,7 @@
1
1
  import operator
2
- import os
3
- from pathlib import Path
4
2
 
5
- from secator.definitions import REPORTS_FOLDER
6
3
  from secator.output_types import OUTPUT_TYPES, OutputType
7
- from secator.utils import merge_opts, pluralize, get_file_timestamp, print_results_table
4
+ from secator.utils import merge_opts, get_file_timestamp, print_results_table
8
5
  from secator.rich import console
9
6
 
10
7
 
@@ -23,7 +20,7 @@ class Report:
23
20
  self.timestamp = get_file_timestamp()
24
21
  self.exporters = exporters
25
22
  self.workspace_name = runner.workspace_name
26
- self.create_local_folders()
23
+ self.output_folder = runner.reports_folder
27
24
 
28
25
  def as_table(self):
29
26
  print_results_table(self.results, self.title)
@@ -80,15 +77,6 @@ class Report:
80
77
  # Save data
81
78
  self.data = data
82
79
 
83
- def create_local_folders(self):
84
- output_folder = Path(REPORTS_FOLDER)
85
- if self.runner.workspace_name:
86
- output_folder = output_folder / Path(self.runner.workspace_name)
87
- output_folder = output_folder / Path(pluralize(self.runner.__class__.__name__).lower())
88
- output_folder = str(output_folder)
89
- os.makedirs(output_folder, exist_ok=True)
90
- self.output_folder = output_folder
91
-
92
80
 
93
81
  def get_table_fields(output_type):
94
82
  """Get output fields and sort fields based on output type.
secator/rich.py CHANGED
@@ -1,20 +1,13 @@
1
1
  import operator
2
2
 
3
- import click
4
- import rich_click
5
3
  import yaml
6
4
  from rich import box
7
5
  from rich.console import Console
8
- from rich.logging import RichHandler
9
6
  from rich.table import Table
10
- from rich.traceback import install
11
7
 
12
- from secator.definitions import DEBUG, RECORD
13
-
14
- console = Console(stderr=True, record=RECORD, color_system='truecolor')
8
+ console = Console(stderr=True, color_system='truecolor')
15
9
  console_stdout = Console(record=True)
16
- handler = RichHandler(rich_tracebacks=True)
17
- install(show_locals=DEBUG > 2, suppress=[click, rich_click])
10
+ # handler = RichHandler(rich_tracebacks=True) # TODO: add logging handler
18
11
 
19
12
 
20
13
  def criticity_to_color(value):
@@ -74,7 +67,7 @@ def build_table(items, output_fields=[], exclude_fields=[], sort_by=None):
74
67
  items = sorted(items, key=operator.attrgetter(*sort_by))
75
68
 
76
69
  # Create rich table
77
- box_style = box.DOUBLE if RECORD else box.ROUNDED
70
+ box_style = box.ROUNDED
78
71
  table = Table(show_lines=True, box=box_style)
79
72
 
80
73
  # Get table schema if any, default to first item keys