feat: enhance run name generation to include target information
This commit is contained in:
@@ -459,7 +459,7 @@ def main() -> None:
|
|||||||
asyncio.run(warm_up_llm())
|
asyncio.run(warm_up_llm())
|
||||||
|
|
||||||
if not args.run_name:
|
if not args.run_name:
|
||||||
args.run_name = generate_run_name()
|
args.run_name = generate_run_name(args.targets_info)
|
||||||
|
|
||||||
for target_info in args.targets_info:
|
for target_info in args.targets_info:
|
||||||
if target_info["type"] == "repository":
|
if target_info["type"] == "repository":
|
||||||
|
|||||||
@@ -122,23 +122,63 @@ def build_llm_stats_text(tracer: Any) -> Text:
|
|||||||
|
|
||||||
|
|
||||||
# Name generation utilities
|
# Name generation utilities
|
||||||
def generate_run_name() -> str:
|
|
||||||
# fmt: off
|
|
||||||
adjectives = [
|
def _slugify_for_run_name(text: str, max_length: int = 32) -> str:
|
||||||
"stealthy", "sneaky", "crafty", "elite", "phantom", "shadow", "silent",
|
text = text.lower().strip()
|
||||||
"rogue", "covert", "ninja", "ghost", "cyber", "digital", "binary",
|
text = re.sub(r"[^a-z0-9]+", "-", text)
|
||||||
"encrypted", "obfuscated", "masked", "cloaked", "invisible", "anonymous"
|
text = text.strip("-")
|
||||||
]
|
if len(text) > max_length:
|
||||||
nouns = [
|
text = text[:max_length].rstrip("-")
|
||||||
"exploit", "payload", "backdoor", "rootkit", "keylogger", "botnet", "trojan",
|
return text or "pentest"
|
||||||
"worm", "virus", "packet", "buffer", "shell", "daemon", "spider", "crawler",
|
|
||||||
"scanner", "sniffer", "honeypot", "firewall", "breach"
|
|
||||||
]
|
def _derive_target_label_for_run_name(targets_info: list[dict[str, Any]] | None) -> str: # noqa: PLR0911
|
||||||
# fmt: on
|
if not targets_info:
|
||||||
adj = secrets.choice(adjectives)
|
return "pentest"
|
||||||
noun = secrets.choice(nouns)
|
|
||||||
number = secrets.randbelow(900) + 100
|
first = targets_info[0]
|
||||||
return f"{adj}-{noun}-{number}"
|
target_type = first.get("type")
|
||||||
|
details = first.get("details", {}) or {}
|
||||||
|
original = first.get("original", "") or ""
|
||||||
|
|
||||||
|
if target_type == "web_application":
|
||||||
|
url = details.get("target_url", original)
|
||||||
|
try:
|
||||||
|
parsed = urlparse(url)
|
||||||
|
return str(parsed.netloc or parsed.path or url)
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
return str(url)
|
||||||
|
|
||||||
|
if target_type == "repository":
|
||||||
|
repo = details.get("target_repo", original)
|
||||||
|
parsed = urlparse(repo)
|
||||||
|
path = parsed.path or repo
|
||||||
|
name = path.rstrip("/").split("/")[-1] or path
|
||||||
|
if name.endswith(".git"):
|
||||||
|
name = name[:-4]
|
||||||
|
return str(name)
|
||||||
|
|
||||||
|
if target_type == "local_code":
|
||||||
|
path_str = details.get("target_path", original)
|
||||||
|
try:
|
||||||
|
return str(Path(path_str).name or path_str)
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
return str(path_str)
|
||||||
|
|
||||||
|
if target_type == "ip_address":
|
||||||
|
return str(details.get("target_ip", original) or original)
|
||||||
|
|
||||||
|
return str(original or "pentest")
|
||||||
|
|
||||||
|
|
||||||
|
def generate_run_name(targets_info: list[dict[str, Any]] | None = None) -> str:
|
||||||
|
base_label = _derive_target_label_for_run_name(targets_info)
|
||||||
|
slug = _slugify_for_run_name(base_label)
|
||||||
|
|
||||||
|
random_suffix = secrets.token_hex(2)
|
||||||
|
|
||||||
|
return f"{slug}_{random_suffix}"
|
||||||
|
|
||||||
|
|
||||||
# Target processing utilities
|
# Target processing utilities
|
||||||
|
|||||||
Reference in New Issue
Block a user