From 50d1da929fb618f9a200f1a4a3fa85a574bb1ecf Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 4 Jun 2025 16:50:04 +0900 Subject: [PATCH] Validate thread count --- ReadMe.md | 2 +- Subdominator.Tests/ThreadValidationTests.cs | 15 +++++++++++++++ Subdominator/Program.cs | 9 +++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 Subdominator.Tests/ThreadValidationTests.cs diff --git a/ReadMe.md b/ReadMe.md index 328ed86..f629dc6 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -30,7 +30,7 @@ Subdominator -d sub.example.com -d, --domain A single domain to check -l, --list A list of domains to check (line delimited) -o, --output Output subdomains to a file --t, --threads Number of domains to check at once [default: 50] +-t, --threads Number of domains to check at once; values \<= 0 use the default [default: 50] -v, --verbose Print extra information -q, --quiet Quiet mode: Only print found results -eu, --exclude-unlikely Exclude unlikely (edge-case) fingerprints diff --git a/Subdominator.Tests/ThreadValidationTests.cs b/Subdominator.Tests/ThreadValidationTests.cs new file mode 100644 index 0000000..02335eb --- /dev/null +++ b/Subdominator.Tests/ThreadValidationTests.cs @@ -0,0 +1,15 @@ +using Subdominator; + +namespace Subdominator.Tests; + +[TestClass] +public class ThreadValidationTests +{ + [TestMethod] + public void InvalidThreadValuesDefaultTo50() + { + Assert.AreEqual(50, Program.ValidateThreadCount(0)); + Assert.AreEqual(50, Program.ValidateThreadCount(-5)); + Assert.AreEqual(10, Program.ValidateThreadCount(10)); + } +} diff --git a/Subdominator/Program.cs b/Subdominator/Program.cs index c4a9dc5..319dfc6 100644 --- a/Subdominator/Program.cs +++ b/Subdominator/Program.cs @@ -29,7 +29,7 @@ public static async Task Main(string[] args = null) new Option(["-d", "--domain"], "A single domain to check"), new Option(["-l", "--list"], "A list of domains to check (line delimited)") { Name = "DomainsFile" }, new Option(["-o", "--output"], "Output subdomains to a file") { Name = "OutputFile" }, - new Option(["-t", "--threads"], () => 50, "Number of domains to check at once"), + new Option(["-t", "--threads"], () => 50, "Number of domains to check at once (0 or less uses default of 50)"), new Option(["-v", "--verbose"], "Print extra information"), new Option(["-q", "--quiet"], "Quiet mode: Only print found results"), new Option(["-c", "--csv"], "Heading or column index to parse for CSV file. Forces -l to read as CSV instead of line-delimited") { Name = "CsvHeading" }, @@ -120,7 +120,7 @@ _____ _ _ _ _ } // Define maximum concurrent tasks - int maxConcurrentTasks = o.Threads; + int maxConcurrentTasks = ValidateThreadCount(o.Threads); var vulnerableCount = 0; // Pre-check domains passed in and filter any that are invalid @@ -296,4 +296,9 @@ static async Task CheckAndLogDomain(SubdomainHijack hijackChecker, string } return isFound; } + + public static int ValidateThreadCount(int threads) + { + return threads > 0 ? threads : 50; + } } \ No newline at end of file