port-missing.py (6297B)
1 #!/usr/bin/env python3 2 """Mechanically port vault markdown -> site content for the 13 missing 'port' sheets. 3 Strips Obsidian syntax, drops any existing frontmatter, prepends normalized frontmatter. 4 Deterministic, content preserved (no LLM rewrite).""" 5 import json, os, re 6 7 REPO = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) 8 VAULT = os.environ.get("VAULT_CHEATS", os.path.expanduser("~/git/NetrunnerVault/02Cybersecurity/Cheatsheets")) 9 SHEETS = os.path.join(REPO, "src", "content", "sheets") 10 UPDATED = "2026-08-09" 11 12 # (category, slug, title, rel, tools, tags, difficulty, description) 13 ITEMS = [ 14 ("exploitation","sqlmap","SQLMap","Exploitation/sqlmap.md",["SQLMap"],["exploitation","sql-injection","web"],"intermediate","SQLMap automated SQL injection: target flags, techniques, enumeration, dumping and tamper scripts."), 15 ("exploitation","shell-stabilization","Shell Stabilization & TTY Upgrades","Exploitation/Jailbreak - TTY Upgrade.md",["python","socat","stty"],["exploitation","shells","post-exploitation"],"intermediate","Upgrade dumb shells to full TTYs and escape restricted shells (rbash, jails) with many techniques."), 16 ("exploitation","metasploit","Metasploit Framework","Tools/meterpreter.md",["Metasploit","msfconsole","Meterpreter"],["exploitation","framework","post-exploitation"],"intermediate","msfconsole and Meterpreter workflow: search, exploits, payloads, sessions, post modules, pivoting."), 17 ("privilege-escalation","windows-privesc","Windows Privilege Escalation","PrivEsc/PrivEsc - Windows.md",["winPEAS","PowerUp","JuicyPotato"],["privilege-escalation","windows","post-exploitation"],"advanced","Windows privesc master guide: token/privilege abuse, services, registry, AlwaysInstallElevated, potatoes."), 18 ("tunneling-pivoting","tunneling-tools","Tunneling Tools","Misc/Tunneling.md",["Chisel","socat","plink","SSH"],["pivoting","tunneling","port-forwarding"],"advanced","Chisel, socat, plink and SSH tunneling patterns for port forwarding and pivoting through hosts."), 19 ("tunneling-pivoting","ssh-tunneling","SSH Tunneling & Port Forwarding","Misc/SSH Portfwding with metasploit .md",["SSH","Metasploit"],["pivoting","ssh","port-forwarding"],"intermediate","SSH local/remote/dynamic forwarding and Metasploit route/portfwd pivoting, worked end to end."), 20 ("cryptography","gpg","GPG","Cryptography/GPG - Cheatsheet markdown.md",["GPG","GnuPG"],["cryptography","encryption","pgp"],"intermediate","GnuPG keys, encryption/decryption, signing/verification, keyservers, trust and revocation."), 21 ("dfir","forensics","Digital Forensics","DFIR/Forensics Cheatsheet.md",["Autopsy","Sleuth Kit","plaso"],["dfir","forensics","incident-response"],"intermediate","Cross-platform DFIR reference: acquisition, triage, artifacts, timelines and analysis commands."), 22 ("tools","windows-cmd-powershell","Windows CMD & PowerShell","Tools/CMD-Powershell Cheat Sheet.md",["cmd","PowerShell"],["windows","post-exploitation","commands"],"intermediate","Windows pentest command reference: recon, users/groups, networking, downloads and PowerShell one-liners."), 23 ("tools","fscan","fscan","Tools/fscan.md",["fscan"],["scanning","enumeration","internal"],"intermediate","fscan all-in-one intranet scanner: host/port discovery, service brute-forcing and vuln checks."), 24 ("tools","eyewitness","EyeWitness","Tools/EyeWitness-Cheatsheet.md",["EyeWitness"],["recon","screenshots","web"],"beginner","EyeWitness bulk web/RDP/VNC screenshotting and reporting for rapid visual recon."), 25 ("tools","snaffler","Snaffler","ActiveDirectory/Snaffler.md",["Snaffler"],["credentials","shares","enumeration"],"intermediate","Snaffler share-crawling for credentials, keys and sensitive files across SMB with tuning rules."), 26 ("tools","sharpsploit","SharpSploit","ActiveDirectory/SharpSploit.md",["SharpSploit"],["post-exploitation","dotnet","offensive"],"advanced","SharpSploit .NET post-exploitation library: execution, credentials, enumeration and evasion APIs."), 27 ] 28 29 def strip_frontmatter(txt): 30 if txt.startswith("---"): 31 end = txt.find("\n---", 3) 32 if end != -1: 33 nl = txt.find("\n", end + 1) 34 return txt[nl+1:] if nl != -1 else "" 35 return txt 36 37 def clean_obsidian(body): 38 # ![[embed]] -> drop line-inline: keep alt-less removal 39 body = re.sub(r"!\[\[[^\]]*\]\]", "", body) 40 # [[link|alias]] -> alias ; [[link]] -> link (last path segment) 41 def wl(m): 42 inner = m.group(1) 43 if "|" in inner: 44 return inner.split("|",1)[1] 45 return inner.split("/")[-1].split("#")[0] or inner 46 body = re.sub(r"\[\[([^\]]+)\]\]", wl, body) 47 # %%comments%% 48 body = re.sub(r"%%.*?%%", "", body, flags=re.S) 49 # obsidian callout markers -> blockquote note 50 body = re.sub(r"^>\s*\[!(\w+)\]\s*", r"> **Note —** ", body, flags=re.M) 51 return body 52 53 def yaml_list(xs): 54 return "[" + ", ".join(xs) + "]" 55 56 def fm(cat, slug, title, tools, tags, diff, desc, rel): 57 d = desc.replace('"', "'") 58 t = title.replace('"', "'") 59 return (f"---\ntitle: \"{t}\"\ndescription: \"{d}\"\ncategory: {cat}\n" 60 f"tags: {yaml_list(tags)}\ntools: {yaml_list(tools)}\n" 61 f"difficulty: {diff}\nupdated: \"{UPDATED}\"\n" 62 f"source: \"vault:{rel}\"\n---\n") 63 64 def demote_h1(body, title): 65 # ensure a single top H1 matching title; site hides first h1 66 lines = body.split("\n") 67 # find first non-empty 68 i = 0 69 while i < len(lines) and not lines[i].strip(): 70 i += 1 71 if i < len(lines) and lines[i].startswith("# "): 72 return "\n".join(lines[i:]) # already has H1 73 return f"# {title}\n\n" + "\n".join(lines[i:]) 74 75 def main(): 76 for cat, slug, title, rel, tools, tags, diff, desc in ITEMS: 77 src = os.path.join(VAULT, rel) 78 raw = open(src, encoding="utf-8", errors="replace").read() 79 body = clean_obsidian(strip_frontmatter(raw)).strip() 80 body = demote_h1(body, title) 81 out = fm(cat, slug, title, tools, tags, diff, desc, rel) + "\n" + body + "\n" 82 dst = os.path.join(SHEETS, cat, slug + ".md") 83 os.makedirs(os.path.dirname(dst), exist_ok=True) 84 open(dst, "w", encoding="utf-8").write(out) 85 print(f"wrote {cat}/{slug}.md ({len(body)} chars)") 86 87 if __name__ == "__main__": 88 main()