#!/usr/bin/env python3 """Import the local Ligolo-ng guide and its rendered Rose Pine diagrams.""" from __future__ import annotations import re import shutil from pathlib import Path SOURCE_ROOT = Path("/home/daemon-sec/Downloads/Kimi_Agent_Rose-Pine Flowcharts") SOURCE_MARKDOWN = SOURCE_ROOT / "Ligolo-ng Cheat sheet.md" SOURCE_DIAGRAMS = SOURCE_ROOT / "diagrams" SOURCE_ARCHIVE = SOURCE_ROOT / "ligolo-dawn-diagrams.zip" REPO_ROOT = Path(__file__).resolve().parents[1] DEST_MARKDOWN = REPO_ROOT / "src/content/sheets/tunneling-pivoting/ligolo-ng.md" DEST_DIAGRAMS = REPO_ROOT / "public/diagrams/ligolo-ng" DIAGRAMS = [ ("01-three-players", "The three Ligolo-ng players", "Attacker proxy, pivot agent, and internal target"), ("02-four-bricks", "The four pieces of a working tunnel", "Session, interface, route, and tunnel flow"), ("03-which-workflow", "Choose the right Ligolo-ng workflow", "Decision tree for first pivots, multiple pivots, and reverse connections"), ("04-workflow-a", "Workflow A — first pivot", "First-pivot autoroute sequence"), ("05-double-pivot", "Workflow B — double pivot", "Two Ligolo-ng agents and two routed interfaces"), ("06-listener-direction", "Listener direction", "Connections enter the agent address and exit on the proxy side"), ("07-reverse-shell", "Reverse-shell relay", "Internal callback relayed through a Ligolo-ng listener"), ("08-troubleshooting", "Troubleshooting flow", "Route, tunnel, reachability, and scan checks"), ] FRONTMATTER = """--- title: "Ligolo-ng CLI: Routes, Listeners, and Multi-Hop Pivoting" description: "Ligolo-ng v0.9.x CLI guide covering managed routes, listeners, first pivots, multi-hop tunnels, reverse connections, scanning, and troubleshooting." category: tunneling-pivoting tags: [ligolo-ng, pivoting, tunneling, networking] tools: [Ligolo-ng, Nmap] difficulty: intermediate updated: "2026-08-25" source: "local:Kimi Agent Rose-Pine Flowcharts/Ligolo-ng Cheat sheet.md" --- """ def diagram_figure(stem: str, title: str, alt: str) -> str: public = f"/diagrams/ligolo-ng/{stem}" return f"""
{alt}
{title} PNG Mermaid source
""" def main() -> None: body = SOURCE_MARKDOWN.read_text(encoding="utf-8") if not body.startswith("---\n"): raise SystemExit(f"Expected YAML frontmatter in {SOURCE_MARKDOWN}") _, _, body = body.split("---\n", 2) blocks = list(re.finditer(r"```mermaid\n.*?\n```", body, flags=re.DOTALL)) if len(blocks) != len(DIAGRAMS): raise SystemExit(f"Expected {len(DIAGRAMS)} Mermaid blocks, found {len(blocks)}") replacements = iter(diagram_figure(*diagram) for diagram in DIAGRAMS) body = re.sub(r"```mermaid\n.*?\n```", lambda _: next(replacements), body, flags=re.DOTALL) download_note = """ > [!info] Rose Pine Dawn diagram pack > Each flowchart below opens at full resolution and includes its Mermaid source. > [Download all eight diagrams and sources as a ZIP](/diagrams/ligolo-ng/ligolo-dawn-diagrams.zip). """ body = body.replace("# Ligolo-ng CLI Cheat Sheet\n", "# Ligolo-ng CLI Cheat Sheet\n" + download_note, 1) DEST_MARKDOWN.parent.mkdir(parents=True, exist_ok=True) DEST_MARKDOWN.write_text(FRONTMATTER + body.lstrip(), encoding="utf-8") DEST_DIAGRAMS.mkdir(parents=True, exist_ok=True) for stem, _, _ in DIAGRAMS: for suffix in (".png", ".mmd"): shutil.copy2(SOURCE_DIAGRAMS / f"{stem}{suffix}", DEST_DIAGRAMS / f"{stem}{suffix}") shutil.copy2(SOURCE_ARCHIVE, DEST_DIAGRAMS / SOURCE_ARCHIVE.name) print(f"Imported {DEST_MARKDOWN.relative_to(REPO_ROOT)}") print(f"Copied {len(DIAGRAMS)} PNGs, {len(DIAGRAMS)} Mermaid sources, and the ZIP archive") if __name__ == "__main__": main()