bbot 2.6.0.6879rc0__py3-none-any.whl → 2.7.2.7254rc0__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 bbot might be problematic. Click here for more details.
- bbot/__init__.py +1 -1
- bbot/core/engine.py +1 -1
- bbot/core/flags.py +1 -0
- bbot/core/helpers/bloom.py +6 -7
- bbot/core/helpers/dns/dns.py +0 -1
- bbot/core/helpers/dns/engine.py +0 -2
- bbot/core/helpers/files.py +2 -2
- bbot/core/helpers/git.py +17 -0
- bbot/core/helpers/misc.py +1 -0
- bbot/core/helpers/ntlm.py +0 -2
- bbot/core/helpers/regex.py +1 -1
- bbot/core/modules.py +0 -54
- bbot/defaults.yml +4 -2
- bbot/modules/apkpure.py +1 -1
- bbot/modules/base.py +11 -5
- bbot/modules/dnsbimi.py +1 -4
- bbot/modules/dnsdumpster.py +35 -52
- bbot/modules/dnstlsrpt.py +0 -6
- bbot/modules/docker_pull.py +1 -1
- bbot/modules/emailformat.py +17 -1
- bbot/modules/filedownload.py +1 -1
- bbot/modules/git_clone.py +47 -22
- bbot/modules/gitdumper.py +4 -14
- bbot/modules/github_workflows.py +1 -1
- bbot/modules/gitlab_com.py +31 -0
- bbot/modules/gitlab_onprem.py +84 -0
- bbot/modules/gowitness.py +0 -6
- bbot/modules/graphql_introspection.py +5 -2
- bbot/modules/httpx.py +2 -0
- bbot/modules/iis_shortnames.py +0 -7
- bbot/modules/internal/unarchive.py +9 -3
- bbot/modules/lightfuzz/lightfuzz.py +5 -1
- bbot/modules/nuclei.py +1 -1
- bbot/modules/output/base.py +0 -5
- bbot/modules/postman_download.py +1 -1
- bbot/modules/retirejs.py +232 -0
- bbot/modules/securitytxt.py +0 -3
- bbot/modules/subdomaincenter.py +1 -16
- bbot/modules/telerik.py +6 -1
- bbot/modules/templates/gitlab.py +98 -0
- bbot/modules/trufflehog.py +1 -1
- bbot/scanner/manager.py +7 -4
- bbot/scanner/scanner.py +1 -1
- bbot/scripts/benchmark_report.py +433 -0
- bbot/test/benchmarks/__init__.py +2 -0
- bbot/test/benchmarks/test_bloom_filter_benchmarks.py +105 -0
- bbot/test/benchmarks/test_closest_match_benchmarks.py +76 -0
- bbot/test/benchmarks/test_event_validation_benchmarks.py +438 -0
- bbot/test/benchmarks/test_excavate_benchmarks.py +291 -0
- bbot/test/benchmarks/test_ipaddress_benchmarks.py +143 -0
- bbot/test/benchmarks/test_weighted_shuffle_benchmarks.py +70 -0
- bbot/test/test_step_1/test_bbot_fastapi.py +2 -2
- bbot/test/test_step_1/test_events.py +0 -1
- bbot/test/test_step_1/test_scan.py +1 -8
- bbot/test/test_step_2/module_tests/base.py +6 -1
- bbot/test/test_step_2/module_tests/test_module_dnsbimi.py +2 -1
- bbot/test/test_step_2/module_tests/test_module_dnsdumpster.py +3 -5
- bbot/test/test_step_2/module_tests/test_module_emailformat.py +1 -1
- bbot/test/test_step_2/module_tests/test_module_emails.py +2 -2
- bbot/test/test_step_2/module_tests/test_module_excavate.py +35 -6
- bbot/test/test_step_2/module_tests/test_module_gitlab_com.py +66 -0
- bbot/test/test_step_2/module_tests/{test_module_gitlab.py → test_module_gitlab_onprem.py} +4 -69
- bbot/test/test_step_2/module_tests/test_module_lightfuzz.py +2 -2
- bbot/test/test_step_2/module_tests/test_module_retirejs.py +159 -0
- bbot/test/test_step_2/module_tests/test_module_telerik.py +1 -1
- {bbot-2.6.0.6879rc0.dist-info → bbot-2.7.2.7254rc0.dist-info}/METADATA +7 -4
- {bbot-2.6.0.6879rc0.dist-info → bbot-2.7.2.7254rc0.dist-info}/RECORD +70 -60
- {bbot-2.6.0.6879rc0.dist-info → bbot-2.7.2.7254rc0.dist-info}/WHEEL +1 -1
- bbot/modules/censys.py +0 -98
- bbot/modules/gitlab.py +0 -141
- bbot/modules/zoomeye.py +0 -77
- bbot/test/test_step_2/module_tests/test_module_censys.py +0 -83
- bbot/test/test_step_2/module_tests/test_module_zoomeye.py +0 -35
- {bbot-2.6.0.6879rc0.dist-info → bbot-2.7.2.7254rc0.dist-info}/entry_points.txt +0 -0
- {bbot-2.6.0.6879rc0.dist-info → bbot-2.7.2.7254rc0.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from bbot.modules.base import BaseModule
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GitLabBaseModule(BaseModule):
|
|
5
|
+
"""Common functionality for interacting with GitLab instances.
|
|
6
|
+
|
|
7
|
+
This template is intended to be inherited by two concrete modules:
|
|
8
|
+
1. ``gitlab_com`` – Handles public SaaS instances (gitlab.com / gitlab.org).
|
|
9
|
+
2. ``gitlab_onprem`` – Handles self-hosted, on-premises GitLab servers.
|
|
10
|
+
|
|
11
|
+
Both child modules share identical behaviour when talking to the GitLab
|
|
12
|
+
REST API; they only differ in which events they are willing to accept.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# domains owned by GitLab
|
|
16
|
+
saas_domains = ["gitlab.com", "gitlab.org"]
|
|
17
|
+
|
|
18
|
+
async def setup(self):
|
|
19
|
+
if self.options.get("api_key") is not None:
|
|
20
|
+
await self.require_api_key()
|
|
21
|
+
return True
|
|
22
|
+
|
|
23
|
+
async def handle_social(self, event):
|
|
24
|
+
"""Enumerate projects belonging to a user or group profile."""
|
|
25
|
+
username = event.data.get("profile_name", "")
|
|
26
|
+
if not username:
|
|
27
|
+
return
|
|
28
|
+
base_url = self.get_base_url(event)
|
|
29
|
+
urls = [
|
|
30
|
+
# User-owned projects
|
|
31
|
+
self.helpers.urljoin(base_url, f"api/v4/users/{username}/projects?simple=true"),
|
|
32
|
+
# Group-owned projects
|
|
33
|
+
self.helpers.urljoin(base_url, f"api/v4/groups/{username}/projects?simple=true"),
|
|
34
|
+
]
|
|
35
|
+
for url in urls:
|
|
36
|
+
await self.handle_projects_url(url, event)
|
|
37
|
+
|
|
38
|
+
async def handle_projects_url(self, projects_url, event):
|
|
39
|
+
for project in await self.gitlab_json_request(projects_url):
|
|
40
|
+
project_url = project.get("web_url", "")
|
|
41
|
+
if project_url:
|
|
42
|
+
code_event = self.make_event({"url": project_url}, "CODE_REPOSITORY", tags="git", parent=event)
|
|
43
|
+
await self.emit_event(
|
|
44
|
+
code_event,
|
|
45
|
+
context=f"{{module}} enumerated projects and found {{event.type}} at {project_url}",
|
|
46
|
+
)
|
|
47
|
+
namespace = project.get("namespace", {})
|
|
48
|
+
if namespace:
|
|
49
|
+
await self.handle_namespace(namespace, event)
|
|
50
|
+
|
|
51
|
+
async def handle_groups_url(self, groups_url, event):
|
|
52
|
+
for group in await self.gitlab_json_request(groups_url):
|
|
53
|
+
await self.handle_namespace(group, event)
|
|
54
|
+
|
|
55
|
+
async def gitlab_json_request(self, url):
|
|
56
|
+
"""Helper that performs an HTTP request and safely returns JSON list."""
|
|
57
|
+
response = await self.api_request(url)
|
|
58
|
+
if response is not None:
|
|
59
|
+
try:
|
|
60
|
+
json_data = response.json()
|
|
61
|
+
except Exception:
|
|
62
|
+
return []
|
|
63
|
+
if json_data and isinstance(json_data, list):
|
|
64
|
+
return json_data
|
|
65
|
+
return []
|
|
66
|
+
|
|
67
|
+
async def handle_namespace(self, namespace, event):
|
|
68
|
+
namespace_name = namespace.get("path", "")
|
|
69
|
+
namespace_url = namespace.get("web_url", "")
|
|
70
|
+
namespace_path = namespace.get("full_path", "")
|
|
71
|
+
|
|
72
|
+
if not (namespace_name and namespace_url and namespace_path):
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
namespace_url = self.helpers.parse_url(namespace_url)._replace(path=f"/{namespace_path}").geturl()
|
|
76
|
+
|
|
77
|
+
social_event = self.make_event(
|
|
78
|
+
{
|
|
79
|
+
"platform": "gitlab",
|
|
80
|
+
"profile_name": namespace_path,
|
|
81
|
+
"url": namespace_url,
|
|
82
|
+
},
|
|
83
|
+
"SOCIAL",
|
|
84
|
+
parent=event,
|
|
85
|
+
)
|
|
86
|
+
await self.emit_event(
|
|
87
|
+
social_event,
|
|
88
|
+
context=f'{{module}} found GitLab namespace ({{event.type}}) "{namespace_name}" at {namespace_url}',
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# ------------------------------------------------------------------
|
|
92
|
+
# Utility helpers
|
|
93
|
+
# ------------------------------------------------------------------
|
|
94
|
+
def get_base_url(self, event):
|
|
95
|
+
base_url = event.data.get("url", "")
|
|
96
|
+
if not base_url:
|
|
97
|
+
base_url = f"https://{event.host}"
|
|
98
|
+
return self.helpers.urlparse(base_url)._replace(path="/").geturl()
|
bbot/modules/trufflehog.py
CHANGED
bbot/scanner/manager.py
CHANGED
|
@@ -94,10 +94,6 @@ class ScanIngress(BaseInterceptModule):
|
|
|
94
94
|
# special handling of URL extensions
|
|
95
95
|
url_extension = getattr(event, "url_extension", None)
|
|
96
96
|
if url_extension is not None:
|
|
97
|
-
if url_extension in self.scan.url_extension_httpx_only:
|
|
98
|
-
event.add_tag("httpx-only")
|
|
99
|
-
event._omit = True
|
|
100
|
-
|
|
101
97
|
# blacklist by extension
|
|
102
98
|
if url_extension in self.scan.url_extension_blacklist:
|
|
103
99
|
self.debug(
|
|
@@ -209,6 +205,13 @@ class ScanEgress(BaseInterceptModule):
|
|
|
209
205
|
)
|
|
210
206
|
event.internal = True
|
|
211
207
|
|
|
208
|
+
# mark special URLs (e.g. Javascript) as internal so they don't get output except when they're critical to the graph
|
|
209
|
+
if event.type.startswith("URL"):
|
|
210
|
+
extension = getattr(event, "url_extension", "")
|
|
211
|
+
if extension in self.scan.url_extension_special:
|
|
212
|
+
event.internal = True
|
|
213
|
+
self.debug(f"Making {event} internal because it is a special URL (extension {extension})")
|
|
214
|
+
|
|
212
215
|
if event.type in self.scan.omitted_event_types:
|
|
213
216
|
self.debug(f"Omitting {event} because its type is omitted in the config")
|
|
214
217
|
event._omit = True
|
bbot/scanner/scanner.py
CHANGED
|
@@ -230,8 +230,8 @@ class Scanner:
|
|
|
230
230
|
)
|
|
231
231
|
|
|
232
232
|
# url file extensions
|
|
233
|
+
self.url_extension_special = {e.lower() for e in self.config.get("url_extension_special", [])}
|
|
233
234
|
self.url_extension_blacklist = {e.lower() for e in self.config.get("url_extension_blacklist", [])}
|
|
234
|
-
self.url_extension_httpx_only = {e.lower() for e in self.config.get("url_extension_httpx_only", [])}
|
|
235
235
|
|
|
236
236
|
# url querystring behavior
|
|
237
237
|
self.url_querystring_remove = self.config.get("url_querystring_remove", True)
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Branch-based benchmark comparison tool for BBOT performance tests.
|
|
4
|
+
|
|
5
|
+
This script takes two git branches, runs benchmarks on each, and generates
|
|
6
|
+
a comparison report showing performance differences between them.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import argparse
|
|
11
|
+
import subprocess
|
|
12
|
+
import tempfile
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Dict, List, Any, Tuple
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run_command(cmd: List[str], cwd: Path = None, capture_output: bool = True) -> subprocess.CompletedProcess:
|
|
18
|
+
"""Run a shell command and return the result."""
|
|
19
|
+
try:
|
|
20
|
+
result = subprocess.run(cmd, cwd=cwd, capture_output=capture_output, text=True, check=True)
|
|
21
|
+
return result
|
|
22
|
+
except subprocess.CalledProcessError as e:
|
|
23
|
+
print(f"Command failed: {' '.join(cmd)}")
|
|
24
|
+
print(f"Exit code: {e.returncode}")
|
|
25
|
+
print(f"Error output: {e.stderr}")
|
|
26
|
+
raise
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_current_branch() -> str:
|
|
30
|
+
"""Get the current git branch name."""
|
|
31
|
+
result = run_command(["git", "branch", "--show-current"])
|
|
32
|
+
return result.stdout.strip()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def checkout_branch(branch: str, repo_path: Path = None):
|
|
36
|
+
"""Checkout a git branch."""
|
|
37
|
+
print(f"Checking out branch: {branch}")
|
|
38
|
+
run_command(["git", "checkout", branch], cwd=repo_path)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run_benchmarks(output_file: Path, repo_path: Path = None) -> bool:
|
|
42
|
+
"""Run benchmarks and save results to JSON file."""
|
|
43
|
+
print(f"Running benchmarks, saving to {output_file}")
|
|
44
|
+
|
|
45
|
+
# Check if benchmarks directory exists
|
|
46
|
+
benchmarks_dir = repo_path / "bbot/test/benchmarks" if repo_path else Path("bbot/test/benchmarks")
|
|
47
|
+
if not benchmarks_dir.exists():
|
|
48
|
+
print(f"Benchmarks directory not found: {benchmarks_dir}")
|
|
49
|
+
print("This branch likely doesn't have benchmark tests yet.")
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
cmd = [
|
|
54
|
+
"poetry",
|
|
55
|
+
"run",
|
|
56
|
+
"python",
|
|
57
|
+
"-m",
|
|
58
|
+
"pytest",
|
|
59
|
+
"bbot/test/benchmarks/",
|
|
60
|
+
"--benchmark-only",
|
|
61
|
+
f"--benchmark-json={output_file}",
|
|
62
|
+
"-q",
|
|
63
|
+
]
|
|
64
|
+
run_command(cmd, cwd=repo_path, capture_output=False)
|
|
65
|
+
return True
|
|
66
|
+
except subprocess.CalledProcessError:
|
|
67
|
+
print("Benchmarks failed for current state")
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def load_benchmark_data(filepath: Path) -> Dict[str, Any]:
|
|
72
|
+
"""Load benchmark data from JSON file."""
|
|
73
|
+
try:
|
|
74
|
+
with open(filepath, "r") as f:
|
|
75
|
+
return json.load(f)
|
|
76
|
+
except FileNotFoundError:
|
|
77
|
+
print(f"Warning: Benchmark file not found: {filepath}")
|
|
78
|
+
return {}
|
|
79
|
+
except json.JSONDecodeError:
|
|
80
|
+
print(f"Warning: Could not parse JSON from {filepath}")
|
|
81
|
+
return {}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def format_time(seconds: float) -> str:
|
|
85
|
+
"""Format time in human-readable format."""
|
|
86
|
+
if seconds < 0.000001: # Less than 1 microsecond
|
|
87
|
+
return f"{seconds * 1000000000:.0f}ns" # Show as nanoseconds with no decimal
|
|
88
|
+
elif seconds < 0.001: # Less than 1 millisecond
|
|
89
|
+
return f"{seconds * 1000000:.2f}µs" # Show as microseconds with 2 decimal places
|
|
90
|
+
elif seconds < 1: # Less than 1 second
|
|
91
|
+
return f"{seconds * 1000:.2f}ms" # Show as milliseconds with 2 decimal places
|
|
92
|
+
else:
|
|
93
|
+
return f"{seconds:.3f}s" # Show as seconds with 3 decimal places
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def format_ops(ops: float) -> str:
|
|
97
|
+
"""Format operations per second."""
|
|
98
|
+
if ops > 1000:
|
|
99
|
+
return f"{ops / 1000:.1f}K ops/sec"
|
|
100
|
+
else:
|
|
101
|
+
return f"{ops:.1f} ops/sec"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def calculate_change_percentage(old_value: float, new_value: float) -> Tuple[float, str]:
|
|
105
|
+
"""Calculate percentage change and return emoji indicator."""
|
|
106
|
+
if old_value == 0:
|
|
107
|
+
return 0, "🆕"
|
|
108
|
+
|
|
109
|
+
change = ((new_value - old_value) / old_value) * 100
|
|
110
|
+
|
|
111
|
+
if change > 10:
|
|
112
|
+
return change, "⚠️" # Regression (slower)
|
|
113
|
+
elif change < -10:
|
|
114
|
+
return change, "🚀" # Improvement (faster)
|
|
115
|
+
else:
|
|
116
|
+
return change, "✅" # No significant change
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def generate_benchmark_table(benchmarks: List[Dict[str, Any]], title: str = "Results") -> str:
|
|
120
|
+
"""Generate markdown table for benchmark results."""
|
|
121
|
+
if not benchmarks:
|
|
122
|
+
return f"### {title}\nNo benchmark data available.\n"
|
|
123
|
+
|
|
124
|
+
table = f"""### {title}
|
|
125
|
+
|
|
126
|
+
| Test Name | Mean Time | Ops/sec | Min | Max |
|
|
127
|
+
|-----------|-----------|---------|-----|-----|
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
for bench in benchmarks:
|
|
131
|
+
stats = bench.get("stats", {})
|
|
132
|
+
name = bench.get("name", "Unknown")
|
|
133
|
+
# Generic test name cleanup - just remove 'test_' prefix and format nicely
|
|
134
|
+
test_name = name.replace("test_", "").replace("_", " ").title()
|
|
135
|
+
|
|
136
|
+
mean = format_time(stats.get("mean", 0))
|
|
137
|
+
ops = format_ops(stats.get("ops", 0))
|
|
138
|
+
min_time = format_time(stats.get("min", 0))
|
|
139
|
+
max_time = format_time(stats.get("max", 0))
|
|
140
|
+
|
|
141
|
+
table += f"| {test_name} | {mean} | {ops} | {min_time} | {max_time} |\n"
|
|
142
|
+
|
|
143
|
+
return table + "\n"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def generate_comparison_table(current_data: Dict, base_data: Dict, current_branch: str, base_branch: str) -> str:
|
|
147
|
+
"""Generate comparison table between current and base benchmark results."""
|
|
148
|
+
if not current_data or not base_data:
|
|
149
|
+
return ""
|
|
150
|
+
|
|
151
|
+
current_benchmarks = current_data.get("benchmarks", [])
|
|
152
|
+
base_benchmarks = base_data.get("benchmarks", [])
|
|
153
|
+
|
|
154
|
+
# Create lookup for base benchmarks
|
|
155
|
+
base_lookup = {bench["name"]: bench for bench in base_benchmarks}
|
|
156
|
+
|
|
157
|
+
if not current_benchmarks:
|
|
158
|
+
return ""
|
|
159
|
+
|
|
160
|
+
# Count changes for summary
|
|
161
|
+
improvements = 0
|
|
162
|
+
regressions = 0
|
|
163
|
+
no_change = 0
|
|
164
|
+
|
|
165
|
+
table = f"""## 📊 Performance Benchmark Report
|
|
166
|
+
|
|
167
|
+
> Comparing **`{base_branch}`** (baseline) vs **`{current_branch}`** (current)
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary>📈 <strong>Detailed Results</strong> (All Benchmarks)</summary>
|
|
171
|
+
|
|
172
|
+
> 📋 **Complete results for all benchmarks** - includes both significant and insignificant changes
|
|
173
|
+
|
|
174
|
+
| 🧪 Test Name | 📏 Base | 📏 Current | 📈 Change | 🎯 Status |
|
|
175
|
+
|--------------|---------|------------|-----------|-----------|"""
|
|
176
|
+
|
|
177
|
+
significant_changes = []
|
|
178
|
+
performance_summary = []
|
|
179
|
+
|
|
180
|
+
for current_bench in current_benchmarks:
|
|
181
|
+
name = current_bench.get("name", "Unknown")
|
|
182
|
+
# Generic test name cleanup - just remove 'test_' prefix and format nicely
|
|
183
|
+
test_name = name.replace("test_", "").replace("_", " ").title()
|
|
184
|
+
|
|
185
|
+
current_stats = current_bench.get("stats", {})
|
|
186
|
+
current_mean = current_stats.get("mean", 0)
|
|
187
|
+
# For multi-item benchmarks, calculate correct ops/sec
|
|
188
|
+
if "excavate" in name:
|
|
189
|
+
current_ops = 100 / current_mean # 100 segments per test
|
|
190
|
+
elif "event_validation" in name and "small" in name:
|
|
191
|
+
current_ops = 100 / current_mean # 100 targets per test
|
|
192
|
+
elif "event_validation" in name and "large" in name:
|
|
193
|
+
current_ops = 1000 / current_mean # 1000 targets per test
|
|
194
|
+
elif "make_event" in name and "small" in name:
|
|
195
|
+
current_ops = 100 / current_mean # 100 items per test
|
|
196
|
+
elif "make_event" in name and "large" in name:
|
|
197
|
+
current_ops = 1000 / current_mean # 1000 items per test
|
|
198
|
+
elif "ip" in name:
|
|
199
|
+
current_ops = 1000 / current_mean # 1000 IPs per test
|
|
200
|
+
elif "bloom_filter" in name:
|
|
201
|
+
if "dns_mutation" in name:
|
|
202
|
+
current_ops = 2500 / current_mean # 2500 operations per test
|
|
203
|
+
else:
|
|
204
|
+
current_ops = 13000 / current_mean # 13000 operations per test
|
|
205
|
+
else:
|
|
206
|
+
current_ops = 1 / current_mean # Default: single operation
|
|
207
|
+
|
|
208
|
+
base_bench = base_lookup.get(name)
|
|
209
|
+
if base_bench:
|
|
210
|
+
base_stats = base_bench.get("stats", {})
|
|
211
|
+
base_mean = base_stats.get("mean", 0)
|
|
212
|
+
# For multi-item benchmarks, calculate correct ops/sec
|
|
213
|
+
if "excavate" in name:
|
|
214
|
+
base_ops = 100 / base_mean # 100 segments per test
|
|
215
|
+
elif "event_validation" in name and "small" in name:
|
|
216
|
+
base_ops = 100 / base_mean # 100 targets per test
|
|
217
|
+
elif "event_validation" in name and "large" in name:
|
|
218
|
+
base_ops = 1000 / base_mean # 1000 targets per test
|
|
219
|
+
elif "make_event" in name and "small" in name:
|
|
220
|
+
base_ops = 100 / base_mean # 100 items per test
|
|
221
|
+
elif "make_event" in name and "large" in name:
|
|
222
|
+
base_ops = 1000 / base_mean # 1000 items per test
|
|
223
|
+
elif "ip" in name:
|
|
224
|
+
base_ops = 1000 / base_mean # 1000 IPs per test
|
|
225
|
+
elif "bloom_filter" in name:
|
|
226
|
+
if "dns_mutation" in name:
|
|
227
|
+
base_ops = 2500 / base_mean # 2500 operations per test
|
|
228
|
+
else:
|
|
229
|
+
base_ops = 13000 / base_mean # 13000 operations per test
|
|
230
|
+
else:
|
|
231
|
+
base_ops = 1 / base_mean # Default: single operation
|
|
232
|
+
|
|
233
|
+
change_percent, emoji = calculate_change_percentage(base_mean, current_mean)
|
|
234
|
+
|
|
235
|
+
# Create visual change indicator
|
|
236
|
+
if abs(change_percent) > 20:
|
|
237
|
+
change_bar = "🔴🔴🔴" if change_percent > 0 else "🟢🟢🟢"
|
|
238
|
+
elif abs(change_percent) > 10:
|
|
239
|
+
change_bar = "🟡🟡" if change_percent > 0 else "🟢🟢"
|
|
240
|
+
else:
|
|
241
|
+
change_bar = "⚪"
|
|
242
|
+
|
|
243
|
+
table += f"\n| **{test_name}** | `{format_time(base_mean)}` | `{format_time(current_mean)}` | **{change_percent:+.1f}%** {change_bar} | {emoji} |"
|
|
244
|
+
|
|
245
|
+
# Track significant changes
|
|
246
|
+
if abs(change_percent) > 10:
|
|
247
|
+
direction = "🐌 slower" if change_percent > 0 else "🚀 faster"
|
|
248
|
+
significant_changes.append(f"- **{test_name}**: {abs(change_percent):.1f}% {direction}")
|
|
249
|
+
if change_percent > 0:
|
|
250
|
+
regressions += 1
|
|
251
|
+
else:
|
|
252
|
+
improvements += 1
|
|
253
|
+
else:
|
|
254
|
+
no_change += 1
|
|
255
|
+
|
|
256
|
+
# Add to performance summary
|
|
257
|
+
ops_change = ((current_ops - base_ops) / base_ops) * 100 if base_ops > 0 else 0
|
|
258
|
+
performance_summary.append(
|
|
259
|
+
{
|
|
260
|
+
"name": test_name,
|
|
261
|
+
"time_change": change_percent,
|
|
262
|
+
"ops_change": ops_change,
|
|
263
|
+
"current_ops": current_ops,
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
else:
|
|
267
|
+
table += f"\n| **{test_name}** | `-` | `{format_time(current_mean)}` | **New** 🆕 | 🆕 |"
|
|
268
|
+
significant_changes.append(
|
|
269
|
+
f"- **{test_name}**: New test 🆕 ({format_time(current_mean)}, {format_ops(current_ops)})"
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
table += "\n\n</details>\n\n"
|
|
273
|
+
|
|
274
|
+
# Add performance summary
|
|
275
|
+
table += "## 🎯 Performance Summary\n\n"
|
|
276
|
+
|
|
277
|
+
if improvements > 0 or regressions > 0:
|
|
278
|
+
table += "```diff\n"
|
|
279
|
+
if improvements > 0:
|
|
280
|
+
table += f"+ {improvements} improvement{'s' if improvements != 1 else ''} 🚀\n"
|
|
281
|
+
if regressions > 0:
|
|
282
|
+
table += f"! {regressions} regression{'s' if regressions != 1 else ''} ⚠️\n"
|
|
283
|
+
if no_change > 0:
|
|
284
|
+
table += f" {no_change} unchanged ✅\n"
|
|
285
|
+
table += "```\n\n"
|
|
286
|
+
else:
|
|
287
|
+
table += "✅ **No significant performance changes detected** (all changes <10%)\n\n"
|
|
288
|
+
|
|
289
|
+
# Add significant changes section
|
|
290
|
+
if significant_changes:
|
|
291
|
+
table += "### 🔍 Significant Changes (>10%)\n\n"
|
|
292
|
+
for change in significant_changes:
|
|
293
|
+
table += f"{change}\n"
|
|
294
|
+
table += "\n"
|
|
295
|
+
|
|
296
|
+
return table
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def generate_report(current_data: Dict, base_data: Dict, current_branch: str, base_branch: str) -> str:
|
|
300
|
+
"""Generate complete benchmark comparison report."""
|
|
301
|
+
|
|
302
|
+
if not current_data:
|
|
303
|
+
report = """## 🚀 Performance Benchmark Report
|
|
304
|
+
|
|
305
|
+
> ⚠️ **No current benchmark data available**
|
|
306
|
+
>
|
|
307
|
+
> This might be because:
|
|
308
|
+
> - Benchmarks failed to run
|
|
309
|
+
> - No benchmark tests found
|
|
310
|
+
> - Dependencies missing
|
|
311
|
+
|
|
312
|
+
"""
|
|
313
|
+
return report
|
|
314
|
+
|
|
315
|
+
if not base_data:
|
|
316
|
+
report = f"""## 🚀 Performance Benchmark Report
|
|
317
|
+
|
|
318
|
+
> ℹ️ **No baseline benchmark data available**
|
|
319
|
+
>
|
|
320
|
+
> Showing current results for **{current_branch}** only.
|
|
321
|
+
|
|
322
|
+
"""
|
|
323
|
+
current_benchmarks = current_data.get("benchmarks", [])
|
|
324
|
+
if current_benchmarks:
|
|
325
|
+
report += f"""<details>
|
|
326
|
+
<summary>📊 Current Results ({current_branch}) - Click to expand</summary>
|
|
327
|
+
|
|
328
|
+
{generate_benchmark_table(current_benchmarks, "Results")}
|
|
329
|
+
</details>"""
|
|
330
|
+
else:
|
|
331
|
+
# Add comparison
|
|
332
|
+
comparison = generate_comparison_table(current_data, base_data, current_branch, base_branch)
|
|
333
|
+
if comparison:
|
|
334
|
+
report = comparison
|
|
335
|
+
else:
|
|
336
|
+
# Fallback if no comparison data
|
|
337
|
+
report = f"""## 🚀 Performance Benchmark Report
|
|
338
|
+
|
|
339
|
+
> ℹ️ **No baseline benchmark data available**
|
|
340
|
+
>
|
|
341
|
+
> Showing current results for **{current_branch}** only.
|
|
342
|
+
|
|
343
|
+
"""
|
|
344
|
+
|
|
345
|
+
# Get Python version info
|
|
346
|
+
machine_info = current_data.get("machine_info", {})
|
|
347
|
+
python_version = machine_info.get("python_version", "Unknown")
|
|
348
|
+
|
|
349
|
+
report += f"\n\n---\n\n🐍 Python Version {python_version}"
|
|
350
|
+
|
|
351
|
+
return report
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def main():
|
|
355
|
+
parser = argparse.ArgumentParser(description="Compare benchmark performance between git branches")
|
|
356
|
+
parser.add_argument("--base", required=True, help="Base branch name (e.g., 'main', 'dev')")
|
|
357
|
+
parser.add_argument("--current", required=True, help="Current branch name (e.g., 'feature-branch', 'HEAD')")
|
|
358
|
+
parser.add_argument("--output", type=Path, help="Output markdown file (default: stdout)")
|
|
359
|
+
parser.add_argument("--keep-results", action="store_true", help="Keep intermediate JSON files")
|
|
360
|
+
|
|
361
|
+
args = parser.parse_args()
|
|
362
|
+
|
|
363
|
+
# Get current working directory
|
|
364
|
+
repo_path = Path.cwd()
|
|
365
|
+
|
|
366
|
+
# Save original branch to restore later
|
|
367
|
+
try:
|
|
368
|
+
original_branch = get_current_branch()
|
|
369
|
+
print(f"Current branch: {original_branch}")
|
|
370
|
+
except subprocess.CalledProcessError:
|
|
371
|
+
print("Warning: Could not determine current branch")
|
|
372
|
+
original_branch = None
|
|
373
|
+
|
|
374
|
+
# Create temporary files for benchmark results
|
|
375
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
376
|
+
temp_path = Path(temp_dir)
|
|
377
|
+
base_results_file = temp_path / "base_results.json"
|
|
378
|
+
current_results_file = temp_path / "current_results.json"
|
|
379
|
+
|
|
380
|
+
base_data = {}
|
|
381
|
+
current_data = {}
|
|
382
|
+
|
|
383
|
+
base_data = {}
|
|
384
|
+
current_data = {}
|
|
385
|
+
|
|
386
|
+
try:
|
|
387
|
+
# Run benchmarks on base branch
|
|
388
|
+
print(f"\n=== Running benchmarks on base branch: {args.base} ===")
|
|
389
|
+
checkout_branch(args.base, repo_path)
|
|
390
|
+
if run_benchmarks(base_results_file, repo_path):
|
|
391
|
+
base_data = load_benchmark_data(base_results_file)
|
|
392
|
+
|
|
393
|
+
# Run benchmarks on current branch
|
|
394
|
+
print(f"\n=== Running benchmarks on current branch: {args.current} ===")
|
|
395
|
+
checkout_branch(args.current, repo_path)
|
|
396
|
+
if run_benchmarks(current_results_file, repo_path):
|
|
397
|
+
current_data = load_benchmark_data(current_results_file)
|
|
398
|
+
|
|
399
|
+
# Generate report
|
|
400
|
+
print("\n=== Generating comparison report ===")
|
|
401
|
+
report = generate_report(current_data, base_data, args.current, args.base)
|
|
402
|
+
|
|
403
|
+
# Output report
|
|
404
|
+
if args.output:
|
|
405
|
+
with open(args.output, "w") as f:
|
|
406
|
+
f.write(report)
|
|
407
|
+
print(f"Report written to {args.output}")
|
|
408
|
+
else:
|
|
409
|
+
print("\n" + "=" * 80)
|
|
410
|
+
print(report)
|
|
411
|
+
|
|
412
|
+
# Keep results if requested
|
|
413
|
+
if args.keep_results:
|
|
414
|
+
if base_data:
|
|
415
|
+
with open("base_benchmark_results.json", "w") as f:
|
|
416
|
+
json.dump(base_data, f, indent=2)
|
|
417
|
+
if current_data:
|
|
418
|
+
with open("current_benchmark_results.json", "w") as f:
|
|
419
|
+
json.dump(current_data, f, indent=2)
|
|
420
|
+
print("Benchmark result files saved.")
|
|
421
|
+
|
|
422
|
+
finally:
|
|
423
|
+
# Restore original branch
|
|
424
|
+
if original_branch:
|
|
425
|
+
print(f"\nRestoring original branch: {original_branch}")
|
|
426
|
+
try:
|
|
427
|
+
checkout_branch(original_branch, repo_path)
|
|
428
|
+
except subprocess.CalledProcessError:
|
|
429
|
+
print(f"Warning: Could not restore original branch {original_branch}")
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
if __name__ == "__main__":
|
|
433
|
+
main()
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import string
|
|
3
|
+
import random
|
|
4
|
+
from bbot.scanner import Scanner
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestBloomFilterBenchmarks:
|
|
8
|
+
"""
|
|
9
|
+
Benchmark tests for Bloom Filter operations.
|
|
10
|
+
|
|
11
|
+
These tests measure the performance of bloom filter operations which are
|
|
12
|
+
critical for DNS brute-forcing efficiency in BBOT.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def setup_method(self):
|
|
16
|
+
"""Setup common test data"""
|
|
17
|
+
self.scan = Scanner()
|
|
18
|
+
|
|
19
|
+
# Generate test data of different sizes
|
|
20
|
+
self.items_small = self._generate_random_strings(1000) # 1K items
|
|
21
|
+
self.items_medium = self._generate_random_strings(10000) # 10K items
|
|
22
|
+
|
|
23
|
+
def _generate_random_strings(self, n, length=10):
|
|
24
|
+
"""Generate a list of n random strings."""
|
|
25
|
+
# Slightly longer strings for testing performance difference
|
|
26
|
+
length = length + 2 # Make strings 2 chars longer
|
|
27
|
+
return ["".join(random.choices(string.ascii_letters + string.digits, k=length)) for _ in range(n)]
|
|
28
|
+
|
|
29
|
+
@pytest.mark.benchmark(group="bloom_filter_operations")
|
|
30
|
+
def test_bloom_filter_dns_mutation_tracking_performance(self, benchmark):
|
|
31
|
+
"""Benchmark comprehensive bloom filter operations (add, check, mixed) for DNS brute-forcing"""
|
|
32
|
+
|
|
33
|
+
def comprehensive_bloom_operations():
|
|
34
|
+
bloom_filter = self.scan.helpers.bloom_filter(size=8000000) # 8M bits
|
|
35
|
+
|
|
36
|
+
# Phase 1: Add operations (simulating storing tried DNS mutations)
|
|
37
|
+
for item in self.items_small:
|
|
38
|
+
bloom_filter.add(item)
|
|
39
|
+
|
|
40
|
+
# Phase 2: Check operations (simulating lookup of existing mutations)
|
|
41
|
+
found_count = 0
|
|
42
|
+
for item in self.items_small:
|
|
43
|
+
if item in bloom_filter:
|
|
44
|
+
found_count += 1
|
|
45
|
+
|
|
46
|
+
# Phase 3: Mixed operations (realistic DNS brute-force simulation)
|
|
47
|
+
# Add new items while checking existing ones
|
|
48
|
+
for i, item in enumerate(self.items_medium[:500]): # Smaller subset for mixed ops
|
|
49
|
+
bloom_filter.add(item)
|
|
50
|
+
# Every few additions, check some existing items
|
|
51
|
+
if i % 10 == 0:
|
|
52
|
+
for check_item in self.items_small[i : i + 5]:
|
|
53
|
+
if check_item in bloom_filter:
|
|
54
|
+
found_count += 1
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
"items_added": len(self.items_small) + 500,
|
|
58
|
+
"items_checked": found_count,
|
|
59
|
+
"bloom_size": bloom_filter.size,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
result = benchmark(comprehensive_bloom_operations)
|
|
63
|
+
assert result["items_added"] > 1000
|
|
64
|
+
assert result["items_checked"] > 0
|
|
65
|
+
|
|
66
|
+
@pytest.mark.benchmark(group="bloom_filter_scalability")
|
|
67
|
+
def test_bloom_filter_large_scale_dns_brute_force(self, benchmark):
|
|
68
|
+
"""Benchmark bloom filter performance with large-scale DNS brute-force simulation"""
|
|
69
|
+
|
|
70
|
+
def large_scale_simulation():
|
|
71
|
+
bloom_filter = self.scan.helpers.bloom_filter(size=8000000) # 8M bits
|
|
72
|
+
|
|
73
|
+
# Simulate a large DNS brute-force session
|
|
74
|
+
mutations_tried = 0
|
|
75
|
+
duplicate_attempts = 0
|
|
76
|
+
|
|
77
|
+
# Add all medium dataset (simulating 10K DNS mutations)
|
|
78
|
+
for item in self.items_medium:
|
|
79
|
+
bloom_filter.add(item)
|
|
80
|
+
mutations_tried += 1
|
|
81
|
+
|
|
82
|
+
# Simulate checking for duplicates during brute-force
|
|
83
|
+
for item in self.items_medium[:2000]: # Check subset for duplicates
|
|
84
|
+
if item in bloom_filter:
|
|
85
|
+
duplicate_attempts += 1
|
|
86
|
+
|
|
87
|
+
# Simulate adding more mutations with duplicate checking
|
|
88
|
+
for item in self.items_small:
|
|
89
|
+
if item not in bloom_filter: # Only add if not already tried
|
|
90
|
+
bloom_filter.add(item)
|
|
91
|
+
mutations_tried += 1
|
|
92
|
+
else:
|
|
93
|
+
duplicate_attempts += 1
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
"total_mutations_tried": mutations_tried,
|
|
97
|
+
"duplicates_avoided": duplicate_attempts,
|
|
98
|
+
"efficiency_ratio": mutations_tried / (mutations_tried + duplicate_attempts)
|
|
99
|
+
if duplicate_attempts > 0
|
|
100
|
+
else 1.0,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
result = benchmark(large_scale_simulation)
|
|
104
|
+
assert result["total_mutations_tried"] > 10000
|
|
105
|
+
assert result["efficiency_ratio"] > 0
|