From 3a77cdfc59879682d39a01a00dfa1cbfd5a8947c Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Tue, 7 Oct 2025 22:15:12 +0100 Subject: [PATCH] Completes AXFR security scanning --- src/lib/constants/nav.ts | 13 +- src/lib/content/axfr.ts | 15 +- .../api/internal/diagnostics/axfr/+server.ts | 46 ++++-- .../diagnostics/dns/axfr-tester/+page.svelte | 149 ++++++++++++++---- .../internal/diagnostics/axfr/server.test.ts} | 9 ++ 5 files changed, 181 insertions(+), 51 deletions(-) rename tests/{api/internal-endpoints/axfr.test.ts => unit/routes/api/internal/diagnostics/axfr/server.test.ts} (97%) diff --git a/src/lib/constants/nav.ts b/src/lib/constants/nav.ts index cdca91c..d98ce97 100644 --- a/src/lib/constants/nav.ts +++ b/src/lib/constants/nav.ts @@ -1193,7 +1193,18 @@ export const SUB_NAV: Record = { label: 'AXFR Security Tester', description: 'Test if DNS zone transfers are improperly exposed - detect critical security vulnerabilities', icon: 'zone-transfer-safe', - keywords: ['axfr', 'zone', 'transfer', 'security', 'vulnerability', 'dns', 'leak', 'audit', 'test', 'nameserver'], + keywords: [ + 'axfr', + 'zone', + 'transfer', + 'security', + 'vulnerability', + 'dns', + 'leak', + 'audit', + 'test', + 'nameserver', + ], }, { href: makePath('/diagnostics/dns/query-performance'), diff --git a/src/lib/content/axfr.ts b/src/lib/content/axfr.ts index 41edccf..dfb3d68 100644 --- a/src/lib/content/axfr.ts +++ b/src/lib/content/axfr.ts @@ -38,8 +38,7 @@ However, if AXFR is misconfigured to allow transfers from any source, it becomes { risk: 'Internal IP Exposure', severity: 'Medium', - description: - 'Private IP addresses and internal network topology revealed through zone records.', + description: 'Private IP addresses and internal network topology revealed through zone records.', impact: 'Helps attackers understand internal network architecture', }, ], @@ -136,26 +135,22 @@ VALUES (1, 'ALLOW-AXFR-FROM', '192.0.2.1');`, practices: [ { practice: 'Restrict Zone Transfers', - description: - 'Only allow AXFR from authorized secondary nameservers. Never allow unrestricted transfers.', + description: 'Only allow AXFR from authorized secondary nameservers. Never allow unrestricted transfers.', priority: 'Critical', }, { practice: 'Use TSIG Authentication', - description: - 'Implement TSIG (Transaction Signature) for authenticated zone transfers between servers.', + description: 'Implement TSIG (Transaction Signature) for authenticated zone transfers between servers.', priority: 'High', }, { practice: 'Regular Security Audits', - description: - 'Periodically test your nameservers for AXFR vulnerabilities using tools like this one.', + description: 'Periodically test your nameservers for AXFR vulnerabilities using tools like this one.', priority: 'High', }, { practice: 'Minimize Public DNS Records', - description: - "Don't publish internal hostnames or private infrastructure details in public DNS zones.", + description: "Don't publish internal hostnames or private infrastructure details in public DNS zones.", priority: 'Medium', }, { diff --git a/src/routes/api/internal/diagnostics/axfr/+server.ts b/src/routes/api/internal/diagnostics/axfr/+server.ts index bf105b2..0267c34 100644 --- a/src/routes/api/internal/diagnostics/axfr/+server.ts +++ b/src/routes/api/internal/diagnostics/axfr/+server.ts @@ -1,8 +1,11 @@ import { json, error } from '@sveltejs/kit'; import type { RequestHandler } from './$types'; -import { exec } from 'node:child_process'; -import { promisify } from 'node:util'; -import { promises as dns } from 'node:dns'; +// @ts-expect-error - Node.js core modules work at runtime +import { exec } from 'child_process'; +// @ts-expect-error - Node.js core modules work at runtime +import { promisify } from 'util'; +// @ts-expect-error - Node.js core modules work at runtime +import { promises as dns } from 'dns'; const execAsync = promisify(exec); @@ -66,9 +69,7 @@ async function testAXFR(domain: string, nameserver: string, ip: string): Promise const { stdout, stderr } = await Promise.race([ execAsync(command, { maxBuffer: 1024 * 1024 * 5 }), // 5MB max - new Promise((_, reject) => - setTimeout(() => reject(new Error('AXFR query timeout')), AXFR_TIMEOUT_MS) - ), + new Promise((_, reject) => setTimeout(() => reject(new Error('AXFR query timeout')), AXFR_TIMEOUT_MS)), ]); const endTime = performance.now(); @@ -76,18 +77,17 @@ async function testAXFR(domain: string, nameserver: string, ip: string): Promise const output = stdout + stderr; - // Check for transfer success indicators - if (output.includes('Transfer failed') || output.includes('failed')) { + // Check for connection reset (SECURE - actively refusing) + if (output.includes('connection reset')) { return { nameserver, ip, vulnerable: false, - error: 'Transfer refused (secure)', responseTime, }; } - // Check for timeout + // Check for timeout/connection errors (can't determine security) if (output.includes('connection timed out') || output.includes('no servers could be reached')) { return { nameserver, @@ -98,6 +98,16 @@ async function testAXFR(domain: string, nameserver: string, ip: string): Promise }; } + // Check for transfer refused (SECURE - proper configuration) + if (output.includes('Transfer failed') || output.includes('failed') || output.includes('refused')) { + return { + nameserver, + ip, + vulnerable: false, + responseTime, + }; + } + // Parse records from output const lines = output.split('\n').filter((line: string) => { const trimmed = line.trim(); @@ -128,18 +138,28 @@ async function testAXFR(domain: string, nameserver: string, ip: string): Promise } } - // No records returned - secure + // No records returned - secure (transfer properly refused) return { nameserver, ip, vulnerable: false, - error: 'Transfer refused (secure)', responseTime, }; } catch (err: any) { const endTime = performance.now(); const responseTime = Math.round((endTime - startTime) * 100) / 100; + // Check if error output contains connection reset (SECURE) + const errorOutput = (err.stderr || err.stdout || err.message || '').toLowerCase(); + if (errorOutput.includes('connection reset')) { + return { + nameserver, + ip, + vulnerable: false, + responseTime, + }; + } + let errorMsg = 'Unknown error'; if (err.message?.includes('timeout')) { errorMsg = 'Query timeout'; @@ -224,7 +244,7 @@ export const POST: RequestHandler = async ({ request }) => { responseTime: 0, }; } - }) + }), ); // Calculate summary diff --git a/src/routes/diagnostics/dns/axfr-tester/+page.svelte b/src/routes/diagnostics/dns/axfr-tester/+page.svelte index 27e109e..f2e21cf 100644 --- a/src/routes/diagnostics/dns/axfr-tester/+page.svelte +++ b/src/routes/diagnostics/dns/axfr-tester/+page.svelte @@ -40,10 +40,15 @@ }); const examples = [ - { domain: 'zonetransfer.me', description: 'Intentionally vulnerable test domain' }, - { domain: 'google.com', description: 'Secure major site' }, - { domain: 'cloudflare.com', description: 'Secure DNS provider' }, - { domain: 'github.com', description: 'Secure tech company' }, + { domain: 'bbc.co.uk', description: '' }, + { domain: 'zonetransfer.me', description: '' }, + { domain: 'networkingtoolbox.net', description: '' }, + { domain: 'amazon.com', description: '' }, + { domain: 'wikipedia.org', description: '' }, + { domain: 'github.com', description: '' }, + { domain: 'gov.uk', description: '' }, + { domain: 'proton.me', description: '' }, + { domain: 'loveholidays.com', description: '' }, ]; async function testAXFR() { @@ -147,7 +152,13 @@ -
{ e.preventDefault(); testAXFR(); }}> + { + e.preventDefault(); + testAXFR(); + }} + >
{ selectedExampleIndex = null; }} + oninput={() => { + selectedExampleIndex = null; + }} aria-invalid={!isInputValid} />
@@ -192,8 +205,8 @@
Critical Security Vulnerability Detected!

- {results.summary.vulnerable} nameserver{results.summary.vulnerable > 1 ? 's' : ''} allowed - unrestricted zone transfer. Your entire DNS zone is exposed to anyone. + {results.summary.vulnerable} nameserver{results.summary.vulnerable > 1 ? 's' : ''} allowed unrestricted zone + transfer. Your entire DNS zone is exposed to anyone. Immediate action required!

@@ -259,10 +272,10 @@
+ {ns.responseTime}ms {getStatusText(ns)} - {ns.responseTime}ms
@@ -280,8 +293,7 @@ onclick={() => toggleRecords(ns.nameserver)} > - {expandedRecords.has(ns.nameserver) ? 'Hide' : 'Show'} exposed records - ({ns.records.length} of {ns.recordCount}) + {expandedRecords.has(ns.nameserver) ? 'Hide' : 'Show'} exposed records ({ns.records.length} of {ns.recordCount}) {#if expandedRecords.has(ns.nameserver)} @@ -315,15 +327,17 @@ {/if} -
+

{axfrContent.sections.whatIsAXFR.title}

{axfrContent.sections.whatIsAXFR.content}

@@ -354,13 +368,21 @@ {#each axfrContent.sections.interpretation.statuses as status (status.status)}
- +

{status.status}: {status.meaning}

{status.description}

- Action: {status.action} + Action: + {status.action}
{/each} @@ -464,6 +486,74 @@ } } + .alert { + display: flex; + align-items: flex-start; + gap: var(--spacing-md); + padding: var(--spacing-md); + border-radius: var(--radius-md); + border-left: 4px solid; + margin: var(--spacing-lg) 0; + + :global(.icon) { + flex-shrink: 0; + margin-top: 2px; + } + + div { + flex: 1; + min-width: 0; + } + + strong { + display: block; + font-size: var(--font-size-md); + margin-bottom: var(--spacing-xs); + } + + p { + margin: 0; + font-size: var(--font-size-sm); + line-height: 1.5; + } + + &.alert-error { + background: color-mix(in srgb, var(--color-error) 10%, var(--bg-primary)); + border-left-color: var(--color-error); + color: var(--color-error); + + :global(.icon) { + color: var(--color-error); + } + + strong { + color: var(--color-error); + } + + p { + color: var(--text-primary); + } + } + + &.alert-success { + background: color-mix(in srgb, var(--color-success) 10%, var(--bg-primary)); + border-left-color: var(--color-success); + color: var(--color-success); + + :global(.icon) { + color: var(--color-success); + } + + strong { + color: var(--color-success); + } + + p { + color: var(--text-primary); + } + } + } + .stats-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); @@ -523,24 +613,29 @@ } .nameserver-card { - background: var(--bg-secondary); + background: var(--bg-tertiary); border-radius: var(--radius-md); padding: var(--spacing-md); - border-left: 4px solid var(--border-primary); &.status-error { - border-left-color: var(--color-error); - background: color-mix(in srgb, var(--color-error) 6%, var(--bg-secondary)); + .nameserver-info :global(.icon) { + color: var(--color-error); + } + // background: color-mix(in srgb, var(--color-error) 6%, var(--bg-secondary)); } &.status-success { - border-left-color: var(--color-success); - background: color-mix(in srgb, var(--color-success) 6%, var(--bg-secondary)); + .nameserver-info :global(.icon) { + color: var(--color-success); + } + // background: color-mix(in srgb, var(--color-success) 6%, var(--bg-secondary)); } &.status-warning { - border-left-color: var(--color-warning); - background: color-mix(in srgb, var(--color-warning) 6%, var(--bg-secondary)); + .nameserver-info :global(.icon) { + color: var(--color-warning); + } + // background: color-mix(in srgb, var(--color-warning) 6%, var(--bg-secondary)); } .nameserver-header { @@ -587,12 +682,12 @@ &.status-error { background: var(--color-error); - color: white; + color: var(--bg-primary); } &.status-success { background: var(--color-success); - color: white; + color: var(--bg-primary); } &.status-warning { @@ -749,7 +844,7 @@ &.severity-high { background: var(--color-error); - color: white; + color: var(--bg-primary); } &.severity-medium { diff --git a/tests/api/internal-endpoints/axfr.test.ts b/tests/unit/routes/api/internal/diagnostics/axfr/server.test.ts similarity index 97% rename from tests/api/internal-endpoints/axfr.test.ts rename to tests/unit/routes/api/internal/diagnostics/axfr/server.test.ts index b1818e0..c074a67 100644 --- a/tests/api/internal-endpoints/axfr.test.ts +++ b/tests/unit/routes/api/internal/diagnostics/axfr/server.test.ts @@ -82,6 +82,15 @@ describe('AXFR Security Tester API', () => { expect(status).toBe(200); expect(data.summary.vulnerable).toBe(0); }); + + it('should handle connection reset as secure', async () => { + const { status, data } = await makeRequest('loveholidays.com'); + + expect(status).toBe(200); + expect(data.summary.vulnerable).toBe(0); + // Connection reset should be counted as secure, not error + expect(data.summary.secure).toBeGreaterThan(0); + }); }); describe('Vulnerable Test Domain', () => {