astranyx-engine 4.0.0a1__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.
Files changed (83) hide show
  1. astranyx/__init__.py +8 -0
  2. astranyx/analysis/__init__.py +0 -0
  3. astranyx/analysis/evidence_gate.py +187 -0
  4. astranyx/analysis/pipeline.py +50 -0
  5. astranyx/analysis/taint.py +46 -0
  6. astranyx/analysis/validation.py +56 -0
  7. astranyx/cli.py +267 -0
  8. astranyx/commands/__init__.py +0 -0
  9. astranyx/commands/report.py +25 -0
  10. astranyx/core/__init__.py +0 -0
  11. astranyx/core/html.py +207 -0
  12. astranyx/core/preview.py +27 -0
  13. astranyx/core/report.py +39 -0
  14. astranyx/core/sarif.py +54 -0
  15. astranyx/core/templates/app.js +45 -0
  16. astranyx/core/templates/dashboard.html +96 -0
  17. astranyx/core/templates/style.css +220 -0
  18. astranyx/graph/callgraph.py +66 -0
  19. astranyx/graph/dfg.py +41 -0
  20. astranyx/graph/trust.py +43 -0
  21. astranyx/intelligence/__init__.py +0 -0
  22. astranyx/intelligence/classify.py +47 -0
  23. astranyx/intelligence/cwe.py +73 -0
  24. astranyx/intelligence/engine.py +37 -0
  25. astranyx/intelligence/models.py +29 -0
  26. astranyx/intelligence/recommendations.py +78 -0
  27. astranyx/intelligence/risk.py +32 -0
  28. astranyx/intelligence/safe_patterns.py +61 -0
  29. astranyx/intelligence/scoring.py +53 -0
  30. astranyx/intelligence/surface.py +26 -0
  31. astranyx/investigation/__init__.py +1 -0
  32. astranyx/investigation/manager.py +89 -0
  33. astranyx/investigation/orchestrator.py +256 -0
  34. astranyx/investigation/run.py +128 -0
  35. astranyx/models/ir.py +62 -0
  36. astranyx/modules/__init__.py +0 -0
  37. astranyx/modules/js.py +465 -0
  38. astranyx/output/__init__.py +0 -0
  39. astranyx/output/html_writer.py +309 -0
  40. astranyx/output/markdown_writer.py +18 -0
  41. astranyx/parsers/base.py +35 -0
  42. astranyx/plugins/__init__.py +0 -0
  43. astranyx/plugins/analyze.py +136 -0
  44. astranyx/plugins/dashboard.py +54 -0
  45. astranyx/plugins/evidence.py +79 -0
  46. astranyx/plugins/extract.py +41 -0
  47. astranyx/plugins/focus.py +101 -0
  48. astranyx/plugins/investigate.py +81 -0
  49. astranyx/plugins/ipa.py +134 -0
  50. astranyx/plugins/playbook.py +49 -0
  51. astranyx/plugins/report.py +116 -0
  52. astranyx/plugins/review.py +124 -0
  53. astranyx/plugins/threat.py +147 -0
  54. astranyx/services/__init__.py +0 -0
  55. astranyx/services/checklist.py +35 -0
  56. astranyx/services/data.py +20 -0
  57. astranyx/services/playbook.py +22 -0
  58. astranyx/services/status.py +32 -0
  59. astranyx/telemetry.py +55 -0
  60. astranyx/tracing.py +28 -0
  61. astranyx/wordpress/__init__.py +0 -0
  62. astranyx/wordpress/analyzer.py +90 -0
  63. astranyx/wordpress/report.py +76 -0
  64. astranyx/wordpress/rules/__init__.py +0 -0
  65. astranyx/wordpress/rules/ajax.py +14 -0
  66. astranyx/wordpress/rules/dangerous.py +11 -0
  67. astranyx/wordpress/rules/deserialization.py +9 -0
  68. astranyx/wordpress/rules/include.py +9 -0
  69. astranyx/wordpress/rules/react.py +21 -0
  70. astranyx/wordpress/rules/registry.py +32 -0
  71. astranyx/wordpress/rules/rest.py +14 -0
  72. astranyx/wordpress/rules/sql.py +16 -0
  73. astranyx/wordpress/rules/ssrf.py +11 -0
  74. astranyx/wordpress/rules/upload.py +11 -0
  75. astranyx/wordpress/scanner.py +200 -0
  76. astranyx/wordpress/sql.py +23 -0
  77. astranyx/wordpress/taint.py +73 -0
  78. astranyx_engine-4.0.0a1.dist-info/METADATA +389 -0
  79. astranyx_engine-4.0.0a1.dist-info/RECORD +83 -0
  80. astranyx_engine-4.0.0a1.dist-info/WHEEL +5 -0
  81. astranyx_engine-4.0.0a1.dist-info/entry_points.txt +2 -0
  82. astranyx_engine-4.0.0a1.dist-info/licenses/LICENSE +0 -0
  83. astranyx_engine-4.0.0a1.dist-info/top_level.txt +1 -0
astranyx/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("astranyx-engine")
5
+ except PackageNotFoundError:
6
+ __version__ = "unknown"
7
+
8
+ __all__ = ["__version__"]
File without changes
@@ -0,0 +1,187 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from urllib.parse import urlparse
5
+
6
+ from astranyx.analysis.pipeline import AnalysisStage
7
+
8
+
9
+ @dataclass(slots=True)
10
+ class FindingEvidence:
11
+ category: str
12
+ sensitive_value: str = ""
13
+ injected_header: bool = False
14
+ final_url: str = ""
15
+ trusted_hosts: tuple[str, ...] = field(default_factory=tuple)
16
+ attacker_origin_readable: bool = False
17
+ authenticated_sensitive_data: bool = False
18
+ stack_trace: bool = False
19
+ data_exposure: bool = False
20
+ authorization_impact: bool = False
21
+ availability_impact: bool = False
22
+ protected_data: bool = False
23
+
24
+
25
+ @dataclass(slots=True)
26
+ class EvidenceDecision:
27
+ reportable: bool
28
+ reason: str
29
+
30
+
31
+ class EvidenceGate:
32
+ """Rejects findings that lack observable security impact."""
33
+
34
+ def evaluate(self, evidence: FindingEvidence) -> EvidenceDecision:
35
+ category = evidence.category.lower().replace("-", "_").replace(" ", "_")
36
+
37
+ if category in {"pii", "pii_disclosure"}:
38
+ if evidence.sensitive_value.strip():
39
+ return EvidenceDecision(
40
+ True,
41
+ "Non-empty sensitive value observed",
42
+ )
43
+ return EvidenceDecision(
44
+ False,
45
+ "No sensitive value was disclosed",
46
+ )
47
+
48
+ if category in {"crlf", "header_injection"}:
49
+ if evidence.injected_header:
50
+ return EvidenceDecision(
51
+ True,
52
+ "A separate response header was injected",
53
+ )
54
+ return EvidenceDecision(
55
+ False,
56
+ "Input was escaped or reflected only as text",
57
+ )
58
+
59
+ if category == "open_redirect":
60
+ host = urlparse(evidence.final_url).hostname
61
+
62
+ if host and not self._trusted(host, evidence.trusted_hosts):
63
+ return EvidenceDecision(
64
+ True,
65
+ "Redirect left the trusted domain",
66
+ )
67
+
68
+ return EvidenceDecision(
69
+ False,
70
+ "Redirect remained on a trusted domain",
71
+ )
72
+
73
+ if category == "cors":
74
+ if (
75
+ evidence.attacker_origin_readable
76
+ and evidence.authenticated_sensitive_data
77
+ ):
78
+ return EvidenceDecision(
79
+ True,
80
+ "Attacker origin read authenticated sensitive data",
81
+ )
82
+
83
+ return EvidenceDecision(
84
+ False,
85
+ "No cross-origin authenticated data exposure demonstrated",
86
+ )
87
+
88
+ if category in {"http_500", "server_error"}:
89
+ impact = any(
90
+ (
91
+ evidence.stack_trace,
92
+ evidence.data_exposure,
93
+ evidence.authorization_impact,
94
+ evidence.availability_impact,
95
+ )
96
+ )
97
+
98
+ if impact:
99
+ return EvidenceDecision(
100
+ True,
101
+ "Server error had security impact",
102
+ )
103
+
104
+ return EvidenceDecision(
105
+ False,
106
+ "Generic server error without impact",
107
+ )
108
+
109
+ if category == "graphql":
110
+ if evidence.protected_data:
111
+ return EvidenceDecision(
112
+ True,
113
+ "Unauthorized protected data returned",
114
+ )
115
+
116
+ return EvidenceDecision(
117
+ False,
118
+ "Query execution returned no protected data",
119
+ )
120
+
121
+ if category in {"health", "health_endpoint"}:
122
+ if evidence.data_exposure or evidence.sensitive_value.strip():
123
+ return EvidenceDecision(
124
+ True,
125
+ "Health endpoint exposed sensitive data",
126
+ )
127
+
128
+ return EvidenceDecision(
129
+ False,
130
+ "Health endpoint exposed status only",
131
+ )
132
+
133
+ return EvidenceDecision(
134
+ False,
135
+ "Manual validation required",
136
+ )
137
+
138
+ @staticmethod
139
+ def _trusted(
140
+ host: str,
141
+ trusted_hosts: tuple[str, ...],
142
+ ) -> bool:
143
+ host = host.lower().rstrip(".")
144
+
145
+ return any(
146
+ host == trusted.lower().rstrip(".")
147
+ or host.endswith("." + trusted.lower().rstrip("."))
148
+ for trusted in trusted_hosts
149
+ )
150
+
151
+
152
+ class EvidenceGateStage(AnalysisStage):
153
+ """Applies evidence decisions within an AnalysisPipeline."""
154
+
155
+ name = "evidence_gate"
156
+
157
+ def __init__(
158
+ self,
159
+ gate: EvidenceGate | None = None,
160
+ input_key: str = "finding_evidence",
161
+ output_key: str = "evidence_decisions",
162
+ ):
163
+ self.gate = gate or EvidenceGate()
164
+ self.input_key = input_key
165
+ self.output_key = output_key
166
+
167
+ def run(self, context: dict) -> None:
168
+ records = context.get(self.input_key, [])
169
+ decisions: list[EvidenceDecision] = []
170
+
171
+ for record in records:
172
+ if isinstance(record, FindingEvidence):
173
+ evidence = record
174
+ elif isinstance(record, dict):
175
+ evidence = FindingEvidence(**record)
176
+ else:
177
+ raise TypeError(
178
+ "EvidenceGateStage records must be "
179
+ "FindingEvidence instances or dictionaries"
180
+ )
181
+
182
+ decisions.append(self.gate.evaluate(evidence))
183
+
184
+ context[self.output_key] = decisions
185
+ context["reportable_findings"] = sum(
186
+ decision.reportable for decision in decisions
187
+ )
@@ -0,0 +1,50 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Any
5
+
6
+
7
+ @dataclass(slots=True)
8
+ class AnalysisResult:
9
+ findings: list[Any] = field(default_factory=list)
10
+ metadata: dict[str, Any] = field(default_factory=dict)
11
+
12
+
13
+ class AnalysisStage:
14
+ """Base class for all Astranyx analysis stages."""
15
+
16
+ name = "stage"
17
+
18
+ def run(self, context: dict) -> None:
19
+ raise NotImplementedError
20
+
21
+
22
+ class AnalysisPipeline:
23
+ """Executes registered analysis stages in order."""
24
+
25
+ def __init__(self):
26
+ self.stages: list[AnalysisStage] = []
27
+
28
+ def register(self, stage: AnalysisStage) -> None:
29
+ self.stages.append(stage)
30
+
31
+ def execute(self, context: dict) -> dict:
32
+ for stage in self.stages:
33
+ stage.run(context)
34
+
35
+ return context
36
+
37
+
38
+ def build_default_pipeline() -> AnalysisPipeline:
39
+ """
40
+ Builds the default Astranyx analysis pipeline.
41
+
42
+ The local import avoids a circular import because EvidenceGateStage
43
+ inherits from AnalysisStage.
44
+ """
45
+ from astranyx.analysis.evidence_gate import EvidenceGateStage
46
+
47
+ pipeline = AnalysisPipeline()
48
+ pipeline.register(EvidenceGateStage())
49
+
50
+ return pipeline
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+
5
+ from astranyx.analysis.validation import ValidationEvidence
6
+ from astranyx.graph.dfg import DataFlowGraph
7
+ from astranyx.graph.trust import TrustEngine, TrustLevel
8
+
9
+
10
+ @dataclass(slots=True)
11
+ class TaintEvidence:
12
+ source: str
13
+ sink: str
14
+ trust: TrustLevel
15
+ validators: list[ValidationEvidence] = field(default_factory=list)
16
+
17
+
18
+ class TaintEngine:
19
+ def __init__(self):
20
+ self.trust = TrustEngine()
21
+
22
+ def analyze(
23
+ self,
24
+ graph: DataFlowGraph,
25
+ validations: list[ValidationEvidence],
26
+ ) -> list[TaintEvidence]:
27
+
28
+ findings: list[TaintEvidence] = []
29
+
30
+ for source in graph.nodes:
31
+ trust = self.trust.classify(source)
32
+
33
+ if trust != TrustLevel.UNTRUSTED:
34
+ continue
35
+
36
+ for sink in graph.successors(source):
37
+ findings.append(
38
+ TaintEvidence(
39
+ source=source,
40
+ sink=sink,
41
+ trust=trust,
42
+ validators=[v for v in validations if v.location == sink],
43
+ )
44
+ )
45
+
46
+ return findings
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Iterable
4
+ from dataclasses import dataclass
5
+ from typing import ClassVar
6
+
7
+
8
+ @dataclass(slots=True)
9
+ class ValidationEvidence:
10
+ validator: str
11
+ category: str
12
+ confidence: float
13
+ location: str | None = None
14
+
15
+
16
+ class ValidationEngine:
17
+ """
18
+ Detects observable validation routines.
19
+
20
+ It records evidence rather than deciding whether code is safe.
21
+ """
22
+
23
+ DEFAULT_VALIDATORS: ClassVar[dict[str, str]] = {
24
+ "validate": "Validation",
25
+ "sanitize": "Sanitization",
26
+ "escape": "Output Encoding",
27
+ "allowlist": "Allowlist",
28
+ "whitelist": "Allowlist",
29
+ "normalize": "Normalization",
30
+ "verify": "Verification",
31
+ "authorize": "Authorization",
32
+ "authenticate": "Authentication",
33
+ "check_permission": "Authorization",
34
+ }
35
+
36
+ def __init__(self, validators=None):
37
+ self.validators = validators or self.DEFAULT_VALIDATORS
38
+
39
+ def analyze(self, calls: Iterable[str]) -> list[ValidationEvidence]:
40
+ findings: list[ValidationEvidence] = []
41
+
42
+ for call in calls:
43
+ lowered = call.lower()
44
+
45
+ for keyword, category in self.validators.items():
46
+ if keyword in lowered:
47
+ findings.append(
48
+ ValidationEvidence(
49
+ validator=call,
50
+ category=category,
51
+ confidence=0.95,
52
+ location=call,
53
+ )
54
+ )
55
+
56
+ return findings
astranyx/cli.py ADDED
@@ -0,0 +1,267 @@
1
+ import argparse
2
+
3
+ from astranyx import __version__
4
+ from astranyx.commands import report as report_command
5
+ from astranyx.investigation import orchestrator
6
+ from astranyx.investigation import run as investigation_command
7
+ from astranyx.modules import js
8
+ from astranyx.tracing import configure_tracing
9
+ from astranyx.wordpress import scanner
10
+
11
+
12
+ def run_js(args):
13
+ """Run JavaScript analysis."""
14
+ js.analyze(
15
+ path=args.path,
16
+ output=args.output,
17
+ investigation=args.investigation,
18
+ recursive=args.recursive,
19
+ )
20
+
21
+
22
+ def run_report(args):
23
+ """Generate reports from an Astranyx JSON report."""
24
+ report_command.run(args.report_json)
25
+
26
+
27
+ def run_wordpress(args):
28
+ """Run the WordPress plugin scanner."""
29
+ scanner.run(args.path)
30
+
31
+
32
+ def run_investigation(args):
33
+ """Create a workspace and optionally run an investigation pipeline."""
34
+ positional_target = getattr(args, "path", None)
35
+ option_target = getattr(args, "target", None)
36
+
37
+ if (
38
+ positional_target
39
+ and option_target
40
+ and str(positional_target) != str(option_target)
41
+ ):
42
+ raise SystemExit(
43
+ "[!] Supply the target either positionally or with --target, not both"
44
+ )
45
+
46
+ target = positional_target or option_target
47
+ args.target = target
48
+
49
+ if target is None:
50
+ return investigation_command.run(args)
51
+
52
+ try:
53
+ return orchestrator.run(
54
+ target,
55
+ analyst=args.analyst,
56
+ profile=args.profile,
57
+ recursive=args.recursive,
58
+ trace_enabled=args.trace_enabled,
59
+ workspace_root=args.workspace_root,
60
+ )
61
+ except (FileNotFoundError, NotADirectoryError, ValueError) as exc:
62
+ raise SystemExit(f"[!] {exc}") from exc
63
+
64
+
65
+ def main():
66
+ """Astranyx command-line entry point."""
67
+ tracer = configure_tracing()
68
+
69
+ parser = argparse.ArgumentParser(
70
+ prog="astranyx",
71
+ description=("Astranyx Threat Intelligence Automation Framework"),
72
+ )
73
+
74
+ parser.add_argument(
75
+ "--version",
76
+ action="version",
77
+ version=f"%(prog)s {__version__}",
78
+ )
79
+
80
+ subparsers = parser.add_subparsers(dest="command")
81
+
82
+ # JavaScript commands
83
+ js_parser = subparsers.add_parser(
84
+ "js",
85
+ help="JavaScript analysis",
86
+ )
87
+
88
+ js_subparsers = js_parser.add_subparsers(
89
+ dest="js_command",
90
+ )
91
+
92
+ analyze_parser = js_subparsers.add_parser(
93
+ "analyze",
94
+ help="Analyze JavaScript bundles",
95
+ )
96
+
97
+ analyze_parser.add_argument(
98
+ "path",
99
+ help="Directory containing JavaScript files",
100
+ )
101
+
102
+ analyze_parser.add_argument(
103
+ "-o",
104
+ "--output",
105
+ help="Optional path for the JSON report",
106
+ )
107
+
108
+ analyze_parser.add_argument(
109
+ "--investigation",
110
+ help=(
111
+ "Path to an Astranyx investigation workspace, "
112
+ "for example investigations/INV-20260721-171856"
113
+ ),
114
+ )
115
+
116
+ analyze_parser.add_argument(
117
+ "--recursive",
118
+ action="store_true",
119
+ help="Discover JavaScript files in nested directories",
120
+ )
121
+
122
+ analyze_parser.set_defaults(func=run_js)
123
+
124
+ # Report command
125
+ report_parser = subparsers.add_parser(
126
+ "report",
127
+ help="Generate HTML and Markdown reports",
128
+ )
129
+
130
+ report_parser.add_argument(
131
+ "report_json",
132
+ help="Path to an Astranyx JSON report",
133
+ )
134
+
135
+ report_parser.set_defaults(func=run_report)
136
+
137
+ # WordPress command
138
+ wordpress_parser = subparsers.add_parser(
139
+ "wordpress",
140
+ help="Audit a WordPress plugin",
141
+ )
142
+
143
+ wordpress_parser.add_argument(
144
+ "path",
145
+ help="Path to the WordPress plugin directory",
146
+ )
147
+
148
+ wordpress_parser.set_defaults(func=run_wordpress)
149
+
150
+ # Investigation command
151
+ investigation_parser = subparsers.add_parser(
152
+ "investigate",
153
+ help="Create or run an investigation",
154
+ description=(
155
+ "Create an investigation workspace and, when a local target is "
156
+ "supplied, run the selected analysis profile"
157
+ ),
158
+ )
159
+
160
+ investigation_parser.add_argument(
161
+ "path",
162
+ nargs="?",
163
+ help="Optional local, authorized target to analyze",
164
+ )
165
+
166
+ investigation_parser.add_argument(
167
+ "--analyst",
168
+ default="Jonathan Mendiola",
169
+ help="Name of the analyst creating the investigation",
170
+ )
171
+
172
+ investigation_parser.add_argument(
173
+ "--target",
174
+ help="Compatibility alias for the positional target path",
175
+ )
176
+
177
+ investigation_parser.add_argument(
178
+ "--profile",
179
+ choices=orchestrator.SUPPORTED_PROFILES,
180
+ default="auto",
181
+ help="Analysis profile (default: auto)",
182
+ )
183
+
184
+ investigation_parser.add_argument(
185
+ "--recursive",
186
+ action=argparse.BooleanOptionalAction,
187
+ default=True,
188
+ help="Discover supported source files recursively (default: enabled)",
189
+ )
190
+
191
+ investigation_parser.add_argument(
192
+ "--workspace-root",
193
+ default="investigations",
194
+ help="Parent directory for investigation workspaces",
195
+ )
196
+
197
+ investigation_parser.set_defaults(
198
+ func=run_investigation,
199
+ )
200
+
201
+ args = parser.parse_args()
202
+ args.trace_enabled = tracer is not None
203
+
204
+ if not hasattr(args, "func"):
205
+ parser.print_help()
206
+ return
207
+
208
+ # Run normally when tracing credentials are unavailable.
209
+ if tracer is None:
210
+ args.func(args)
211
+ return
212
+
213
+ span_name = f"astranyx.cli.{args.command}"
214
+
215
+ with tracer.start_as_current_span(span_name) as span:
216
+ span.set_attribute(
217
+ "astranyx.command",
218
+ args.command,
219
+ )
220
+
221
+ if getattr(args, "js_command", None):
222
+ span.set_attribute(
223
+ "astranyx.subcommand",
224
+ args.js_command,
225
+ )
226
+
227
+ if getattr(args, "path", None):
228
+ span.set_attribute(
229
+ "astranyx.input.path",
230
+ str(args.path),
231
+ )
232
+
233
+ if getattr(args, "investigation", None):
234
+ span.set_attribute(
235
+ "astranyx.investigation.path",
236
+ str(args.investigation),
237
+ )
238
+
239
+ if getattr(args, "recursive", False):
240
+ span.set_attribute(
241
+ "astranyx.javascript.recursive",
242
+ True,
243
+ )
244
+
245
+ if getattr(args, "target", None):
246
+ span.set_attribute(
247
+ "astranyx.target",
248
+ str(args.target),
249
+ )
250
+
251
+ if getattr(args, "analyst", None):
252
+ span.set_attribute(
253
+ "astranyx.analyst",
254
+ str(args.analyst),
255
+ )
256
+
257
+ if getattr(args, "profile", None):
258
+ span.set_attribute(
259
+ "astranyx.investigation.profile",
260
+ str(args.profile),
261
+ )
262
+
263
+ args.func(args)
264
+
265
+
266
+ if __name__ == "__main__":
267
+ main()
File without changes
@@ -0,0 +1,25 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+ from astranyx.output.html_writer import write_html_report
5
+ from astranyx.output.markdown_writer import write_markdown_summary
6
+
7
+
8
+ def run(report_json: str) -> None:
9
+ path = Path(report_json)
10
+
11
+ if not path.exists():
12
+ raise SystemExit(f"[!] Report JSON not found: {path}")
13
+
14
+ with path.open("r", encoding="utf-8") as f:
15
+ report = json.load(f)
16
+
17
+ output_dir = path.parent
18
+ html_path = output_dir / "report.html"
19
+ md_path = output_dir / "summary.md"
20
+
21
+ write_html_report(report, html_path)
22
+ write_markdown_summary(report, md_path)
23
+
24
+ print(f"[+] HTML report written to {html_path}")
25
+ print(f"[+] Markdown summary written to {md_path}")
File without changes