// @ts-check import { defineConfig } from 'astro/config'; import mdx from '@astrojs/mdx'; import sitemap from '@astrojs/sitemap'; import Slugger from 'github-slugger'; import { headingText, rehypeHeadingMarks } from './src/lib/rehype-heading-marks.mjs'; import { rehypeSanitizeMirror } from './src/lib/rehype-sanitize-mirror.mjs'; /** * MkDocs anchor aliases for the InternalAllTheThings mirror. * * Upstream is a MkDocs site, and python-markdown's slugifier collapses every * run of `[-\s]` to one dash where github-slugger (Astro's) keeps them: the * heading "Meterpreter - Basic" is `#meterpreter-basic` upstream and * `#meterpreter---basic` here. Every deep link ever written against the * upstream page carries the MkDocs form — outside bookmarks and search hits, * and the IATT links this site rewrites out of the PayloadsAllTheThings stubs * — so without an alias they all land at the top of the page. * * The github-slugger id stays primary, because IATT's own in-page tables of * contents are written GitHub-style and resolve against it (they are in fact * broken on the live upstream site). The MkDocs form is emitted as an empty * span *inside* the heading: a sibling before it would break * `.prose > h1:first-child`, which hides the duplicated page title. * * Ids are assigned here rather than left to Astro because user rehype plugins * run before its heading-id pass, so the id has to exist to be compared * against. Astro keeps an id that is already a string, so this is the same * value it would have written. */ /** python-markdown's `toc.slugify`, separator "-". */ function mkdocsSlug(text) { return text .normalize('NFKD') .replace(/[^\x00-\x7f]/g, '') .replace(/[^\w\s-]/g, '') .trim() .toLowerCase() .replace(/[-\s]+/g, '-'); } /** python-markdown disambiguates a repeat with `_1`, `_2`; github-slugger `-1`. */ function uniqueMkdocsSlug(slug, used) { let id = slug; while (!id || used.has(id)) { const m = /^(.*)_(\d+)$/.exec(id); id = m ? `${m[1]}_${Number(m[2]) + 1}` : `${id}_1`; } used.add(id); return id; } // `headingText` (src/lib/rehype-heading-marks.mjs) mirrors // @astrojs/markdown-remark's own heading-text collection, so the two slugifiers // are fed byte-identical input. function rehypeMkdocsAnchors() { return (tree, file) => { const source = (file?.history?.[0] ?? '').replace(/\\/g, '/'); if (!source.includes('/src/content/internal/')) return; const slugger = new Slugger(); const mkdocsUsed = new Set(); const walk = (node) => { if (node.type === 'element' && /^h[1-6]$/.test(node.tagName)) { const text = headingText(node); node.properties = node.properties || {}; if (typeof node.properties.id !== 'string') { const slug = slugger.slug(text); node.properties.id = slug.endsWith('-') ? slug.slice(0, -1) : slug; } const alias = uniqueMkdocsSlug(mkdocsSlug(text), mkdocsUsed); if (alias !== node.properties.id) { node.children.unshift({ type: 'element', tagName: 'span', properties: { id: alias, className: ['anchor-alias'] }, children: [], }); } return; // headings do not nest } if (node.children) for (const child of node.children) walk(child); }; walk(tree); }; } /** * The drop cap, as the main site sets it: the opening letter of a sheet * floated three lines deep in EB Garamond. * * The letter is split out of the paragraph's first text node and wrapped * in a `` rather than left to `::first-letter`. That * keeps it real text — selectable, searchable, and read aloud as part of * the word it opens — and it is the only way to give it a different family * and weight that renders the same across engines. * * Only the first top-level paragraph of the document takes one, and only * if it is long enough to have three lines for the letter to sit in. * Short openers — an image caption, a one-line note, a lede that is really * a subtitle — are left alone, because a cap floated into a two-line * paragraph pushes the text into a column beside it. */ const CAP_MIN_CHARS = 80; function rehypeDropCap() { return (tree) => { const paragraph = tree.children.find( (n) => n.type === 'element' && n.tagName === 'p' && textLength(n) >= CAP_MIN_CHARS, ); if (!paragraph) return; // The first non-empty text node, wherever it sits — the paragraph may // legitimately open with a or an , and the cap belongs to // the first *letter* rather than to the first direct child. const lead = firstText(paragraph); if (!lead) return; const trimmed = lead.value.trimStart(); const letter = trimmed[0]; // Punctuation and quotes make poor caps: floated at 72px an opening // quote reads as a stray mark rather than as a letter. if (!letter || !/[A-Za-z0-9]/.test(letter)) return; lead.value = trimmed.slice(1); paragraph.children.unshift({ type: 'element', tagName: 'span', properties: { className: ['cap'] }, children: [{ type: 'text', value: letter }], }); }; function textLength(node) { if (node.type === 'text') return node.value.trim().length; if (!node.children) return 0; return node.children.reduce((n, c) => n + textLength(c), 0); } function firstText(node) { if (!node.children) return null; for (const child of node.children) { if (child.type === 'text' && child.value.trim()) return child; if (child.type === 'element') { const found = firstText(child); if (found) return found; } } return null; } } // Deployed to Cloudflare Workers at the domain root — no base path. // `site` feeds the sitemap and canonical URLs, so it must be the live custom // domain from wrangler.jsonc, not a platform-generated hostname. export default defineConfig({ site: 'https://cheatsheet.daemon-sec.xyz', trailingSlash: 'ignore', redirects: { "/sheets/active-directory/adfs-golden-saml": "/sheets/active-directory/adfsdump-adfspoof", "/sheets/active-directory/adidns-dnstool": "/sheets/active-directory/dnstool-bloodyad", "/sheets/active-directory/dpapi-decryption": "/sheets/active-directory/impacket-dpapi", "/sheets/active-directory/kerberos-relay-adcs-esc8": "/sheets/active-directory/krbrelayx", "/sheets/enumeration/nfs-enumeration": "/sheets/enumeration/showmount-mount", "/sheets/exploitation/dotnet-viewstate-ysoserial": "/sheets/exploitation/ysoserial-net", "/sheets/password-attacks/john-2john-extractors": "/sheets/password-attacks/john-extractors", "/sheets/password-attacks/keepass-cracking": "/sheets/password-attacks/kpcli-keepassxc-cli", "/sheets/tools/shell-helpers-rlwrap-sshpass": "/sheets/tools/rlwrap-sshpass-ntpdate-faketime" }, integrations: [mdx(), sitemap()], // Keep processed modules external. ClientRouter otherwise injects an empty // data: module as a timing barrier, which this site's strict script CSP blocks. vite: { build: { assetsInlineLimit: (assetPath) => assetPath.endsWith('.js') ? false : undefined } }, markdown: { // Heading marks first: it fixes each sheet heading's id from the untouched // text before removing the emoji, and everything after reads the result. // // `rev` is a cache key, not an option the pass reads. Astro keeps every // rendered sheet in its content store and re-renders one only when the // markdown file changes; it decides whether to throw the store away by // hashing this config, and a function hashes to nothing. So editing a // rehype pass on its own leaves 1,250 stale pages in the store, in dev and // in the build. Bump `rev` whenever one of these passes changes what it // emits and the store is rebuilt. // // The sanitiser goes last so the passes before it see the tree they // always have. It strips scripts, styles, frames, event handlers and // unsafe URLs from the HTML the mirrored collections (payloads, internal, // hacktricks) carry in from upstream; first-party sheets are left alone. // See src/lib/rehype-sanitize-mirror.mjs. It has its own `rev` for the // same cache reason. rehypePlugins: [ [rehypeHeadingMarks, { rev: 1 }], rehypeMkdocsAnchors, rehypeDropCap, [rehypeSanitizeMirror, { rev: 1 }], ], shikiConfig: { // Code blocks are dark plates in both modes (see prose.css), so there // is no light listing to flip to — but the *palette* does change them. // Rosé Pine Moon is inlined; Gruvbox's colours ride along as // --shiki-gruvbox and prose.css switches to them under // . Gruvepine keeps Rosé Pine's syntax, // which is the point of it. themes: { rosepine: 'rose-pine-moon', gruvbox: 'gruvbox-dark-hard' }, defaultColor: 'rosepine', wrap: false, // Fence languages the sheets actually use, mapped onto grammars Shiki // ships. Without these the block silently falls back to plaintext, so a // listing that should be highlighted reads as flat text. // // The capitalised three come from the generated mirrors // (payloads/, internal/) where upstream wrote ```SQL and Shiki's lookup // is case-sensitive. Those files are rewritten by the sync scripts, so // the alias is the only place the fix can live. // // The rest have no grammar of their own; each is mapped to the closest // one that reads correctly rather than left to plaintext. `smali` is // deliberately absent — nothing Shiki ships resembles it, so plaintext // is the honest result. langAlias: { SQL: 'sql', Javascript: 'javascript', C: 'c', conf: 'ini', svg: 'xml', yara: 'c', zeek: 'c', ldif: 'yaml', django: 'html', dataviewjs: 'javascript', // Web-shell listings. Each is server code embedded in markup, so // `html` reads better here than the backing language would: it // highlights the tags and the `<% %>` islands and leaves the code // inside them legible. `asp` is classic ASP (VBScript); Shiki has no // mixed grammar for that either. aspx: 'html', asp: 'html', jsp: 'html', cfm: 'html', }, }, }, });