DNS AXFR security testing, started

This commit is contained in:
Alicia Sykes committed 2025-10-07 22:05:03 +01:00
1 parent 5cc8e29058
commit eaf8bd883d
6 files changed
+1909

No files matched your search

+1
View File
@@ -254,6 +254,7 @@ export const iconMap: Record<string, string> = {
signature: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M144 192C144 165.5 165.5 144 192 144C218.5 144 240 165.5 240 192L240 199.9C240 225.6 238 251.3 233.9 276.7L123.5 314.5C87.9 326.7 64 360.1 64 397.7L64 474C64 512.6 95.3 544 134 544C158.6 544 181.4 531.1 194 510L209.9 483.6C239.5 434.2 261 380.3 273.5 324.1L275.3 316L275.9 313.1L352.7 286.8L329.4 351.9C326.8 359.3 327.9 367.4 332.4 373.8C336.3 379.3 342.3 382.9 348.9 383.8C354 375 360.5 367.1 368 360.4L368 336C368 296.6 385.8 261.4 413.8 237.9C412.7 235.4 411.1 233.1 409.1 231.1C402.6 224.5 393 222.3 384.2 225.2L284.7 259.3C286.9 239.6 288 219.7 288 199.8L288 191.9C288 138.9 245 95.9 192 95.9C139 95.9 96 139 96 192L96 232C96 245.3 106.7 256 120 256C133.3 256 144 245.3 144 232L144 192zM289.5 432C282.7 448.3 275.2 464.3 266.9 480L336 480L336 432L289.5 432zM139.1 359.9L222.4 331.4C210.7 376.2 192.6 419.1 168.8 458.9L152.9 485.3C148.9 491.9 141.8 496 134.1 496C122 496 112.1 486.2 112.1 474L112.1 397.7C112.1 380.6 123 365.4 139.2 359.9zM528 336.1L528 384L464 384L464 336.1C464 318.4 478.3 304.1 496 304.1C513.7 304.1 528 318.4 528 336.1zM384 432L384 528C384 554.5 405.5 576 432 576L560 576C586.5 576 608 554.5 608 528L608 432C608 411.1 594.6 393.3 576 386.7L576 336.1C576 291.9 540.2 256.1 496 256.1C451.8 256.1 416 291.9 416 336.1L416 386.7C397.4 393.3 384 411.1 384 432z"/></svg>`,
blacklist: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M120 576C133.3 576 144 565.3 144 552L144 544C144 487.2 181.1 438.9 232.4 422.2L302.6 496.4C307.1 501.2 313.4 503.9 320 503.9C326.6 503.9 332.9 501.2 337.4 496.4L407.6 422.2C458.9 438.9 496 487.2 496 544L496 552C496 565.3 506.7 576 520 576L120 576zM240 197.7C263.2 203.4 290.9 208 320 208C349.1 208 376.8 203.4 400 197.7L400 208C400 252.2 364.2 288 320 288C275.8 288 240 252.2 240 208L240 197.7zM384 512C384 529.7 398.3 544 416 544C433.7 544 448 529.7 448 512C448 494.3 433.7 480 416 480C398.3 480 384 494.3 384 512z"/><path d="M161.7 75.2L311.6 34.3C317.1 32.8 322.9 32.8 328.4 34.3L478.3 75.2C488.8 78.1 496 87.6 496 98.4C496 106.9 491.6 114.7 484.3 119L464 131.2L464 155.8C464 167.2 458 177.6 448 182.5L448 208C448 278.7 390.7 336 320 336C249.3 336 192 278.7 192 208L192 182.5C182 177.5 176 167.1 176 155.8L176 131.2L155.7 119C148.4 114.7 144 106.8 144 98.4C144 87.5 151.3 78 161.7 75.2zM320 208C290.9 208 263.2 203.4 240 197.7L240 208C240 252.2 275.8 288 320 288C364.2 288 400 252.2 400 208L400 197.7C376.8 203.4 349.1 208 320 208zM257.4 378.9L320 445.1L382.6 378.9C388.4 372.8 396.9 370.2 405.1 371.9C484.5 388.9 544.1 459.5 544.1 544L544.1 552C544.1 565.3 533.4 576 520.1 576C506.8 576 496.1 565.3 496.1 552L496.1 544C496.1 487.2 459 438.9 407.7 422.2L337.5 496.4C333 501.2 326.7 503.9 320.1 503.9C313.5 503.9 307.2 501.2 302.7 496.4L232.5 422.2C181.1 438.9 144 487.2 144 544L144 552C144 565.3 133.3 576 120 576C106.7 576 96 565.3 96 552L96 544C96 459.5 155.6 388.9 235 371.9C243.2 370.1 251.7 372.8 257.5 378.9zM448 512C448 529.7 433.7 544 416 544C398.3 544 384 529.7 384 512C384 494.3 398.3 480 416 480C433.7 480 448 494.3 448 512zM325.7 93.7C322.6 90.6 317.5 90.6 314.4 93.7L285.7 122.3C282.6 125.4 282.6 130.5 285.7 133.6L314.4 162.3C317.5 165.4 322.6 165.4 325.7 162.3L354.4 133.6C357.5 130.5 357.5 125.4 354.4 122.3L325.7 93.7z"/></svg>`,
'info-circle': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320zM256 312C256 298.7 266.7 288 280 288L328 288C341.3 288 352 298.7 352 312L352 400L360 400C373.3 400 384 410.7 384 424C384 437.3 373.3 448 360 448L280 448C266.7 448 256 437.3 256 424C256 410.7 266.7 400 280 400L304 400L304 336L280 336C266.7 336 256 325.3 256 312zM352 224C352 241.7 337.7 256 320 256C302.3 256 288 241.7 288 224C288 206.3 302.3 192 320 192C337.7 192 352 206.3 352 224z"/><path d="M320 112C434.9 112 528 205.1 528 320C528 434.9 434.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112zM320 576C461.4 576 576 461.4 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576zM280 400C266.7 400 256 410.7 256 424C256 437.3 266.7 448 280 448L360 448C373.3 448 384 437.3 384 424C384 410.7 373.3 400 360 400L352 400L352 312C352 298.7 341.3 288 328 288L280 288C266.7 288 256 298.7 256 312C256 325.3 266.7 336 280 336L304 336L304 400L280 400zM320 256C337.7 256 352 241.7 352 224C352 206.3 337.7 192 320 192C302.3 192 288 206.3 288 224C288 241.7 302.3 256 320 256z"/></svg>`,
'zone-transfer-safe': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 128C112 119.2 119.2 112 128 112L384 112C392.8 112 400 119.2 400 128L400 283.3C380.1 305.9 368 335.5 368 368L368 392.4C348.4 410 336 435.5 336 463.9L336 528L304 528L304 448C304 430.3 289.7 416 272 416L240 416C222.3 416 208 430.3 208 448L208 528L128 528C119.2 528 112 520.8 112 512L112 128zM160 176L160 208C160 216.8 167.2 224 176 224L208 224C216.8 224 224 216.8 224 208L224 176C224 167.2 216.8 160 208 160L176 160C167.2 160 160 167.2 160 176zM160 304L160 336C160 344.8 167.2 352 176 352L208 352C216.8 352 224 344.8 224 336L224 304C224 295.2 216.8 288 208 288L176 288C167.2 288 160 295.2 160 304zM288 176L288 208C288 216.8 295.2 224 304 224L336 224C344.8 224 352 216.8 352 208L352 176C352 167.2 344.8 160 336 160L304 160C295.2 160 288 167.2 288 176zM288 304L288 336C288 344.8 295.2 352 304 352L336 352C344.8 352 352 344.8 352 336L352 304C352 295.2 344.8 288 336 288L304 288C295.2 288 288 295.2 288 304z"/><path d="M128 112L384 112C392.8 112 400 119.2 400 128L400 283.3C413 268.5 429.4 256.8 448 249.3L448 128C448 92.7 419.3 64 384 64L128 64C92.7 64 64 92.7 64 128L64 512C64 547.3 92.7 576 128 576L337.3 576C336.4 570.8 336 565.4 336 559.9L336 528L304 528L304 448C304 430.3 289.7 416 272 416L240 416C222.3 416 208 430.3 208 448L208 528L128 528C119.2 528 112 520.8 112 512L112 128C112 119.2 119.2 112 128 112zM160 176L160 208C160 216.8 167.2 224 176 224L208 224C216.8 224 224 216.8 224 208L224 176C224 167.2 216.8 160 208 160L176 160C167.2 160 160 167.2 160 176zM304 160C295.2 160 288 167.2 288 176L288 208C288 216.8 295.2 224 304 224L336 224C344.8 224 352 216.8 352 208L352 176C352 167.2 344.8 160 336 160L304 160zM160 304L160 336C160 344.8 167.2 352 176 352L208 352C216.8 352 224 344.8 224 336L224 304C224 295.2 216.8 288 208 288L176 288C167.2 288 160 295.2 160 304zM304 288C295.2 288 288 295.2 288 304L288 336C288 344.8 295.2 352 304 352L336 352C344.8 352 352 344.8 352 336L352 304C352 295.2 344.8 288 336 288L304 288zM528 368.1L528 416L464 416L464 368.1C464 350.4 478.3 336.1 496 336.1C513.7 336.1 528 350.4 528 368.1zM384 464L384 560C384 586.5 405.5 608 432 608L560 608C586.5 608 608 586.5 608 560L608 464C608 443.1 594.6 425.3 576 418.7L576 368.1C576 323.9 540.2 288.1 496 288.1C451.8 288.1 416 323.9 416 368.1L416 418.7C397.4 425.3 384 443.1 384 464z"/></svg>`,
// '': ``,
// 'pie-chart': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112.4 336C112.4 442 198.4 528 304.4 528C329 528 352.4 523.4 373.9 515.1L257 373.9C246.3 361 240.4 344.7 240.4 328L240.4 154.9C165.8 181.3 112.4 252.4 112.4 336z"/><path d="M384.4 118L384.4 256L522.4 256C505 188.6 451.9 135.4 384.4 118zM240.4 328L240.4 154.9C165.8 181.3 112.4 252.4 112.4 336C112.4 442 198.4 528 304.4 528C329 528 352.4 523.4 373.9 515.1L257 373.9C246.3 361 240.4 344.7 240.4 328zM574.3 272.1C576.6 289.6 562.1 304 544.4 304L368.4 304C350.7 304 336.4 289.7 336.4 272L336.4 96C336.4 78.3 350.8 63.8 368.3 66.1C475.3 80.3 560.1 165.1 574.3 272.1zM288.4 130.7L288.4 328C288.4 333.6 290.4 339 293.9 343.3L426 502.7C437.7 516.8 435.2 538.1 419.1 546.8C385 565.4 345.9 576 304.4 576C171.9 576 64.4 468.5 64.4 336C64.4 220.5 145.9 124.1 254.6 101.2C272.7 97.4 288.4 112.2 288.4 130.7zM573.7 352C592.2 352 607 367.7 603.2 385.8C593 434.2 568.2 477.2 533.6 510C521.3 521.7 502 519.2 491.2 506.1L406.9 404.4C389.6 383.5 404.5 352 431.5 352L573.7 352z"/></svg>`,
+7
View File
@@ -1188,6 +1188,13 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
'delisting',
],
},
{
href: makePath('/diagnostics/dns/axfr-tester'),
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'],
},
{
href: makePath('/diagnostics/dns/query-performance'),
label: 'DNS Query Performance',
+298
View File
@@ -0,0 +1,298 @@
export const axfrContent = {
title: 'DNS Zone Transfer (AXFR) Security Tester',
description:
'Test if your DNS zone transfers are improperly exposed. AXFR vulnerabilities can leak entire DNS records to unauthorized parties.',
sections: {
whatIsAXFR: {
title: 'What is DNS Zone Transfer (AXFR)?',
content: `DNS Zone Transfer (AXFR) is a mechanism for replicating DNS zone data between authoritative nameservers. When configured properly, it allows secondary nameservers to maintain synchronized copies of zone data from primary servers.
However, if AXFR is misconfigured to allow transfers from any source, it becomes a serious security vulnerability. Attackers can download your entire DNS zone, revealing all subdomains, internal hostnames, IP addresses, and infrastructure details that should remain private.`,
},
security: {
title: 'Security Implications',
risks: [
{
risk: 'Information Disclosure',
severity: 'High',
description:
'Entire DNS zone exposed, revealing all subdomains, internal hostnames, IP addresses, mail servers, and infrastructure topology.',
impact: 'Provides attackers with complete map of your DNS infrastructure',
},
{
risk: 'Reconnaissance for Attacks',
severity: 'High',
description:
'Leaked zone data enables targeted attacks on discovered internal systems, dev/staging environments, and admin interfaces.',
impact: 'Significantly increases attack surface and enables focused exploitation',
},
{
risk: 'Subdomain Enumeration',
severity: 'Medium',
description:
'Discovery of hidden subdomains like admin.example.com, staging.example.com, vpn.example.com that attackers can target.',
impact: 'Exposes systems intended to be hidden from public knowledge',
},
{
risk: 'Internal IP Exposure',
severity: 'Medium',
description:
'Private IP addresses and internal network topology revealed through zone records.',
impact: 'Helps attackers understand internal network architecture',
},
],
},
howItWorks: {
title: 'How AXFR Testing Works',
steps: [
'Query nameservers (NS records) for the target domain',
'Resolve each nameserver to its IP address',
'Attempt AXFR query against each nameserver using dig',
'Analyze response to determine if transfer succeeded',
'Parse and count zone records if transfer allowed',
'Report vulnerability status for each nameserver',
],
},
interpretation: {
title: 'Understanding Test Results',
statuses: [
{
status: 'Vulnerable',
color: 'error',
meaning: 'Zone transfer succeeded',
description:
'The nameserver allowed unrestricted zone transfer and returned DNS records. This is a critical security vulnerability.',
action: 'Immediately restrict AXFR to authorized secondary nameservers only',
},
{
status: 'Secure',
color: 'success',
meaning: 'Transfer refused',
description:
'The nameserver properly rejected the zone transfer request. This is the correct configuration for public queries.',
action: 'No action needed - nameserver is properly configured',
},
{
status: 'Error',
color: 'warning',
meaning: 'Query failed',
description:
'Could not complete the AXFR test due to timeout, connection failure, or other error. Nameserver may be unreachable.',
action: 'Verify nameserver is functioning properly',
},
],
},
properConfiguration: {
title: 'Proper AXFR Configuration',
configurations: [
{
server: 'BIND',
syntax: `zone "example.com" {
type master;
file "/etc/bind/zones/example.com";
allow-transfer {
192.0.2.1; // Secondary NS IP
203.0.113.5; // Another authorized secondary
};
};`,
description: 'Restrict transfers to specific IP addresses of secondary nameservers',
},
{
server: 'NSD',
syntax: `zone:
name: "example.com"
zonefile: "example.com.zone"
provide-xfr: 192.0.2.1 NOKEY
provide-xfr: 203.0.113.5 NOKEY`,
description: 'Explicitly list authorized IPs for zone transfers',
},
{
server: 'PowerDNS',
syntax: `allow-axfr-ips=192.0.2.1,203.0.113.5
# Or in SQL zone metadata:
INSERT INTO domainmetadata (domain_id, kind, content)
VALUES (1, 'ALLOW-AXFR-FROM', '192.0.2.1');`,
description: 'Configure allowed transfer IPs in configuration or database',
},
{
server: 'Microsoft DNS',
syntax: `Right-click zone → Properties → Zone Transfers:
☑ Allow zone transfers
○ Only to servers listed on the Name Servers tab
○ Only to the following servers: [Add IPs]
☐ To any server`,
description: 'Use GUI to restrict transfers to specific servers only',
},
],
},
bestPractices: {
title: 'DNS Security Best Practices',
practices: [
{
practice: 'Restrict Zone 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.',
priority: 'High',
},
{
practice: 'Regular Security Audits',
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.",
priority: 'Medium',
},
{
practice: 'Split-Horizon DNS',
description:
'Use separate internal and external DNS zones. Internal zone contains private records, external only public ones.',
priority: 'Medium',
},
{
practice: 'Monitor DNS Query Logs',
description: 'Log and monitor AXFR requests to detect unauthorized transfer attempts.',
priority: 'Medium',
},
],
},
remediation: {
title: 'Fixing AXFR Vulnerabilities',
steps: [
{
step: 'Identify Vulnerable Nameservers',
details: 'Use this tool or manual dig commands to test all authoritative nameservers',
command: 'dig @nameserver.example.com example.com AXFR',
},
{
step: 'Configure Transfer Restrictions',
details: 'Edit nameserver config to allow transfers only from secondary NS IP addresses',
command: 'allow-transfer { 192.0.2.1; 203.0.113.5; };',
},
{
step: 'Reload DNS Configuration',
details: 'Apply configuration changes and reload the nameserver',
command: 'rndc reload (BIND) or service nsd reload (NSD)',
},
{
step: 'Verify Fix',
details:
'Test from external IP to confirm AXFR is now refused, and from secondary to confirm authorized transfers still work',
command: 'dig @nameserver.example.com example.com AXFR',
},
{
step: 'Implement TSIG',
details: 'Add TSIG keys for cryptographic authentication of zone transfers',
command: 'tsig-keygen -a hmac-sha256 transfer-key',
},
],
},
commonMisconfigurations: {
title: 'Common AXFR Misconfigurations',
misconfigurations: [
{
issue: 'No Transfer Restrictions',
example: 'allow-transfer { any; };',
problem: 'Allows anyone to download entire zone',
fix: 'Replace "any" with specific secondary NS IPs',
},
{
issue: 'Network-Based Trust',
example: 'allow-transfer { 192.168.0.0/16; };',
problem: 'Trusts entire network range - too permissive',
fix: 'Specify exact IP addresses of secondary nameservers',
},
{
issue: 'Default Permit Configuration',
example: 'Zone transfers enabled by default without restrictions',
problem: 'Many DNS servers default to allowing transfers',
fix: 'Explicitly configure allow-transfer directive',
},
{
issue: 'Forgotten Test Nameserver',
example: 'Old test/dev nameserver still in production with open AXFR',
problem: 'Test servers often have relaxed security',
fix: 'Remove or properly secure all nameservers',
},
],
},
detectionMethods: {
title: 'How Attackers Exploit AXFR',
methods: [
{
method: 'Manual dig Query',
command: 'dig @ns1.target.com target.com AXFR',
description: 'Direct zone transfer request to each nameserver',
},
{
method: 'Automated Scanning',
command: 'fierce --domain target.com',
description: 'Tools like fierce, dnsrecon automatically test AXFR',
},
{
method: 'Subdomain Enumeration',
command: 'After successful AXFR, extract all A/AAAA records for subdomain list',
description: 'Parse zone file to discover all subdomains and targets',
},
{
method: 'Infrastructure Mapping',
command: 'grep "IN A\\|IN AAAA\\|IN MX\\|IN CNAME" zone_dump.txt',
description: 'Map entire infrastructure from leaked zone data',
},
],
},
compliance: {
title: 'Compliance & Standards',
standards: [
{
standard: 'CIS DNS Benchmark',
requirement: 'Restrict zone transfers to authorized secondary nameservers',
reference: 'Section 3.7',
},
{
standard: 'PCI DSS',
requirement: 'Secure DNS configuration to prevent information disclosure',
reference: 'Requirement 2.2',
},
{
standard: 'NIST 800-81-2',
requirement: 'DNS Security Recommendations - Restrict AXFR',
reference: 'Section 3.1.1',
},
{
standard: 'ISO 27001',
requirement: 'Protection against information leakage',
reference: 'A.13.2.1',
},
],
},
},
quickTips: [
'Zone transfers should only work from authorized secondary nameservers',
'Test all your nameservers - one misconfigured server compromises the entire zone',
'Use TSIG authentication for additional transfer security',
'Monitor DNS logs for unauthorized AXFR attempts',
'Regular security audits help catch configuration drift',
'Split internal and external DNS to minimize exposure',
],
};
@@ -0,0 +1,255 @@
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';
const execAsync = promisify(exec);
interface AXFRRequest {
domain: string;
nameserver?: string;
}
interface NameserverResult {
nameserver: string;
ip: string;
vulnerable: boolean;
recordCount?: number;
records?: string[];
error?: string;
responseTime: number;
}
interface AXFRResponse {
domain: string;
nameservers: NameserverResult[];
summary: {
total: number;
vulnerable: number;
secure: number;
errors: number;
};
timestamp: string;
}
const DOMAIN_PATTERN = /^([a-zA-Z0-9_]([a-zA-Z0-9_-]{0,61}[a-zA-Z0-9_])?\.)+[a-zA-Z]{2,}$/;
const MAX_DOMAIN_LENGTH = 253;
const AXFR_TIMEOUT_MS = 10000;
const MAX_RECORDS_DISPLAY = 50;
function validateDomain(domain: string): boolean {
if (!domain || domain.length > MAX_DOMAIN_LENGTH) return false;
return DOMAIN_PATTERN.test(domain);
}
async function resolveNameserverIP(nameserver: string): Promise<string> {
try {
const addresses = await dns.resolve4(nameserver);
return addresses[0];
} catch {
try {
const addresses = await dns.resolve6(nameserver);
return addresses[0];
} catch {
throw new Error(`Failed to resolve nameserver: ${nameserver}`);
}
}
}
async function testAXFR(domain: string, nameserver: string, ip: string): Promise<NameserverResult> {
const startTime = performance.now();
try {
// Use dig for AXFR query with timeout
const command = `dig @${ip} ${domain} AXFR +time=5 +retry=1 +noidnout 2>&1`;
const { stdout, stderr } = await Promise.race([
execAsync(command, { maxBuffer: 1024 * 1024 * 5 }), // 5MB max
new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('AXFR query timeout')), AXFR_TIMEOUT_MS)
),
]);
const endTime = performance.now();
const responseTime = Math.round((endTime - startTime) * 100) / 100;
const output = stdout + stderr;
// Check for transfer success indicators
if (output.includes('Transfer failed') || output.includes('failed')) {
return {
nameserver,
ip,
vulnerable: false,
error: 'Transfer refused (secure)',
responseTime,
};
}
// Check for timeout
if (output.includes('connection timed out') || output.includes('no servers could be reached')) {
return {
nameserver,
ip,
vulnerable: false,
error: 'Connection timeout',
responseTime,
};
}
// Parse records from output
const lines = output.split('\n').filter((line: string) => {
const trimmed = line.trim();
return (
trimmed &&
!trimmed.startsWith(';') &&
!trimmed.startsWith('<<>>') &&
!trimmed.match(/^(DiG|global|Query|Transfer|connection|WARNING)/)
);
});
// If we got actual zone records, it's vulnerable
if (lines.length > 0) {
// Filter out metadata lines
const zoneRecords = lines.filter((line: string) => {
return line.match(/^\S+\s+\d+\s+IN\s+\w+\s+/);
});
if (zoneRecords.length > 0) {
return {
nameserver,
ip,
vulnerable: true,
recordCount: zoneRecords.length,
records: zoneRecords.slice(0, MAX_RECORDS_DISPLAY),
responseTime,
};
}
}
// No records returned - secure
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;
let errorMsg = 'Unknown error';
if (err.message?.includes('timeout')) {
errorMsg = 'Query timeout';
} else if (err.message?.includes('not found')) {
errorMsg = 'Nameserver not found';
} else if (err.code === 'ENOENT') {
errorMsg = 'dig command not available';
} else if (err.message) {
errorMsg = err.message.split('\n')[0].substring(0, 100);
}
return {
nameserver,
ip,
vulnerable: false,
error: errorMsg,
responseTime,
};
}
}
export const POST: RequestHandler = async ({ request }) => {
try {
let body: AXFRRequest;
try {
body = await request.json();
} catch {
throw error(400, 'Invalid JSON in request body');
}
const { domain, nameserver } = body;
if (!domain || typeof domain !== 'string' || !domain.trim()) {
throw error(400, 'Domain is required');
}
const trimmedDomain = domain.trim().toLowerCase();
if (!validateDomain(trimmedDomain)) {
throw error(400, 'Invalid domain name format');
}
// Get nameservers to test
let nameserversToTest: string[] = [];
if (nameserver && typeof nameserver === 'string' && nameserver.trim()) {
// Single nameserver specified
nameserversToTest = [nameserver.trim()];
} else {
// Get all nameservers for domain
try {
nameserversToTest = await dns.resolveNs(trimmedDomain);
} catch (err: any) {
if (err.code === 'ENOTFOUND') {
throw error(400, 'Domain not found or has no nameservers');
}
throw error(500, `Failed to resolve nameservers: ${err.message}`);
}
}
if (nameserversToTest.length === 0) {
throw error(400, 'No nameservers found for domain');
}
// Limit to 10 nameservers for safety
if (nameserversToTest.length > 10) {
nameserversToTest = nameserversToTest.slice(0, 10);
}
// Test AXFR on all nameservers
const results = await Promise.all(
nameserversToTest.map(async (ns): Promise<NameserverResult> => {
try {
const ip = await resolveNameserverIP(ns);
return await testAXFR(trimmedDomain, ns, ip);
} catch (err: any) {
return {
nameserver: ns,
ip: 'N/A',
vulnerable: false,
error: err.message || 'Failed to resolve nameserver',
responseTime: 0,
};
}
})
);
// Calculate summary
const vulnerable = results.filter((r) => r.vulnerable).length;
const secure = results.filter((r) => !r.vulnerable && !r.error).length;
const errors = results.filter((r) => r.error).length;
const response: AXFRResponse = {
domain: trimmedDomain,
nameservers: results,
summary: {
total: results.length,
vulnerable,
secure,
errors,
},
timestamp: new Date().toISOString(),
};
return json(response);
} catch (err) {
console.error('AXFR test error:', err);
if (err && typeof err === 'object' && 'status' in err) {
throw err;
}
throw error(500, `AXFR test failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
}
};
File diff suppressed because it is too large. Load diff
+325
View File
@@ -0,0 +1,325 @@
import { describe, it, expect } from 'vitest';
describe('AXFR Security Tester API', () => {
const BASE_URL = 'http://localhost:5173';
async function makeRequest(domain: string, nameserver?: string) {
const response = await fetch(`${BASE_URL}/api/internal/diagnostics/axfr`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ domain, nameserver }),
});
const data = await response.json();
return { status: response.status, data };
}
describe('Basic Functionality', () => {
it('should test domain for AXFR vulnerability', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
expect(data.domain).toBe('example.com');
expect(data.nameservers).toBeInstanceOf(Array);
expect(data.nameservers.length).toBeGreaterThan(0);
expect(data.summary).toBeDefined();
expect(data.summary.total).toBe(data.nameservers.length);
expect(data.timestamp).toBeDefined();
});
it('should include all required fields in nameserver results', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
for (const ns of data.nameservers) {
expect(ns).toHaveProperty('nameserver');
expect(ns).toHaveProperty('ip');
expect(ns).toHaveProperty('vulnerable');
expect(ns).toHaveProperty('responseTime');
expect(typeof ns.nameserver).toBe('string');
expect(typeof ns.vulnerable).toBe('boolean');
expect(typeof ns.responseTime).toBe('number');
}
});
it('should calculate correct summary counts', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
const vulnerable = data.nameservers.filter((ns: any) => ns.vulnerable).length;
const secure = data.nameservers.filter((ns: any) => !ns.vulnerable && !ns.error).length;
const errors = data.nameservers.filter((ns: any) => ns.error).length;
expect(data.summary.vulnerable).toBe(vulnerable);
expect(data.summary.secure).toBe(secure);
expect(data.summary.errors).toBe(errors);
expect(data.summary.total).toBe(data.nameservers.length);
});
});
describe('Secure Domains', () => {
it('should report google.com as secure', async () => {
const { status, data } = await makeRequest('google.com');
expect(status).toBe(200);
expect(data.domain).toBe('google.com');
expect(data.summary.vulnerable).toBe(0);
// Most/all should be secure (AXFR properly refused)
expect(data.summary.secure + data.summary.errors).toBeGreaterThan(0);
});
it('should report cloudflare.com as secure', async () => {
const { status, data } = await makeRequest('cloudflare.com');
expect(status).toBe(200);
expect(data.summary.vulnerable).toBe(0);
});
it('should report github.com as secure', async () => {
const { status, data } = await makeRequest('github.com');
expect(status).toBe(200);
expect(data.summary.vulnerable).toBe(0);
});
});
describe('Vulnerable Test Domain', () => {
it('should detect vulnerability on zonetransfer.me', async () => {
const { status, data } = await makeRequest('zonetransfer.me');
expect(status).toBe(200);
expect(data.domain).toBe('zonetransfer.me');
// This domain is intentionally vulnerable for testing
// It should have at least one vulnerable nameserver
const vulnerableNS = data.nameservers.find((ns: any) => ns.vulnerable);
if (vulnerableNS) {
expect(vulnerableNS.vulnerable).toBe(true);
expect(vulnerableNS.recordCount).toBeGreaterThan(0);
expect(vulnerableNS.records).toBeInstanceOf(Array);
expect(vulnerableNS.records.length).toBeGreaterThan(0);
}
});
it('should include zone records when vulnerable', async () => {
const { status, data } = await makeRequest('zonetransfer.me');
expect(status).toBe(200);
const vulnerableNS = data.nameservers.find((ns: any) => ns.vulnerable);
if (vulnerableNS) {
expect(vulnerableNS.records).toBeInstanceOf(Array);
expect(vulnerableNS.recordCount).toBeGreaterThan(0);
// Records should be DNS zone format
if (vulnerableNS.records.length > 0) {
const firstRecord = vulnerableNS.records[0];
expect(typeof firstRecord).toBe('string');
// Should contain IN and record type
expect(firstRecord).toMatch(/\s+IN\s+/);
}
}
});
});
describe('Single Nameserver Testing', () => {
it('should test single nameserver when specified', async () => {
const { status, data } = await makeRequest('example.com', 'a.iana-servers.net');
expect(status).toBe(200);
expect(data.nameservers.length).toBe(1);
expect(data.nameservers[0].nameserver).toBe('a.iana-servers.net');
});
it('should handle invalid nameserver gracefully', async () => {
const { status, data } = await makeRequest('example.com', 'nonexistent-ns.example.com');
expect(status).toBe(200);
expect(data.nameservers.length).toBe(1);
expect(data.nameservers[0].error).toBeDefined();
expect(data.nameservers[0].vulnerable).toBe(false);
});
});
describe('Domain Normalization', () => {
it('should normalize domain to lowercase', async () => {
const { status, data } = await makeRequest('Example.COM');
expect(status).toBe(200);
expect(data.domain).toBe('example.com');
});
it('should trim whitespace from domain', async () => {
const { status, data } = await makeRequest(' example.com ');
expect(status).toBe(200);
expect(data.domain).toBe('example.com');
});
});
describe('Error Handling', () => {
it('should reject empty domain', async () => {
const { status, data } = await makeRequest('');
expect(status).toBe(400);
expect(data.message).toMatch(/required/i);
});
it('should reject missing domain', async () => {
const response = await fetch(`${BASE_URL}/api/internal/diagnostics/axfr`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
});
expect(response.status).toBe(400);
const data = await response.json();
expect(data.message).toMatch(/required/i);
});
it('should reject whitespace-only domain', async () => {
const { status, data } = await makeRequest(' ');
expect(status).toBe(400);
expect(data.message).toMatch(/required/i);
});
it('should reject invalid domain format', async () => {
const { status, data } = await makeRequest('invalid domain with spaces');
expect(status).toBe(400);
expect(data.message).toMatch(/invalid|format/i);
});
it('should handle domain with no nameservers', async () => {
const { status, data } = await makeRequest('this-domain-definitely-does-not-exist-12345.com');
expect(status).toBeGreaterThanOrEqual(400);
expect(data.message).toMatch(/not found|nameserver/i);
});
it('should reject invalid JSON', async () => {
const response = await fetch(`${BASE_URL}/api/internal/diagnostics/axfr`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: 'not valid json',
});
expect(response.status).toBe(400);
const data = await response.json();
expect(data.message).toMatch(/json/i);
});
});
describe('Response Time Tracking', () => {
it('should include response times for all nameservers', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
for (const ns of data.nameservers) {
expect(ns.responseTime).toBeGreaterThanOrEqual(0);
expect(typeof ns.responseTime).toBe('number');
}
});
it('should complete within reasonable time', async () => {
const startTime = Date.now();
const { status } = await makeRequest('example.com');
const duration = Date.now() - startTime;
expect(status).toBe(200);
// Should complete within 30 seconds (generous timeout for multiple NS)
expect(duration).toBeLessThan(30000);
});
});
describe('Nameserver Limits', () => {
it('should limit to 10 nameservers', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
// Should not exceed 10 nameservers even if domain has more
expect(data.nameservers.length).toBeLessThanOrEqual(10);
});
});
describe('Record Count Limits', () => {
it('should limit exposed records to 50', async () => {
const { status, data } = await makeRequest('zonetransfer.me');
expect(status).toBe(200);
const vulnerableNS = data.nameservers.find((ns: any) => ns.vulnerable);
if (vulnerableNS && vulnerableNS.records) {
// Should not return more than 50 records
expect(vulnerableNS.records.length).toBeLessThanOrEqual(50);
// But recordCount can be higher
if (vulnerableNS.recordCount > 50) {
expect(vulnerableNS.records.length).toBe(50);
}
}
});
});
describe('IP Resolution', () => {
it('should resolve nameserver IPs', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
for (const ns of data.nameservers) {
// IP should be present (unless resolution failed)
if (!ns.error || !ns.error.includes('resolve')) {
expect(ns.ip).toBeDefined();
expect(ns.ip).not.toBe('N/A');
// Should be valid IP format (simplified check)
expect(ns.ip).toMatch(/[\d.:a-fA-F]+/);
}
}
});
});
describe('Timestamp Validation', () => {
it('should include valid timestamp', async () => {
const { status, data } = await makeRequest('example.com');
expect(status).toBe(200);
expect(data.timestamp).toBeDefined();
const timestamp = new Date(data.timestamp);
expect(timestamp.getTime()).toBeLessThanOrEqual(Date.now());
expect(timestamp.getTime()).toBeGreaterThan(Date.now() - 60000); // Within last minute
});
});
describe('Different Domain TLDs', () => {
it('should handle .org domains', async () => {
const { status, data } = await makeRequest('wikipedia.org');
expect(status).toBe(200);
expect(data.domain).toBe('wikipedia.org');
expect(data.nameservers.length).toBeGreaterThan(0);
});
it('should handle .net domains', async () => {
const { status, data } = await makeRequest('cloudflare.net');
expect(status).toBe(200);
expect(data.domain).toBe('cloudflare.net');
});
it('should handle country code TLDs', async () => {
const { status, data } = await makeRequest('bbc.co.uk');
expect(status).toBe(200);
expect(data.domain).toBe('bbc.co.uk');
expect(data.nameservers.length).toBeGreaterThan(0);
});
});
});