Skip to content

Commit dde0115

Browse files
committed
Handle IPv6 only domains failing to be submitted.
While at that, also add more error handling. Also add the possibility of comments in the TargetFileProvider.
1 parent 2b10c06 commit dde0115

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

src/main/java/de/rub/nds/crawler/constant/JobStatus.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public enum JobStatus {
1313
TO_BE_EXECUTED(false),
1414
/** The domain was not resolvable. An empty result was written to DB. */
1515
UNRESOLVABLE(true),
16+
/** An uncaught exception occurred while resolving the host. */
17+
RESOLUTION_ERROR(true),
1618
/** The domain was denylisted. An empty result was written to DB. */
1719
DENYLISTED(true),
1820
/** Job was successfully executed. Result was written to db. */

src/main/java/de/rub/nds/crawler/core/jobs/PublishBulkScanJob.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
7676
Function.identity(), Collectors.counting()));
7777

7878
long submittedJobs = parsedJobStatuses.getOrDefault(JobStatus.TO_BE_EXECUTED, 0L);
79+
long unresolvedJobs = parsedJobStatuses.getOrDefault(JobStatus.UNRESOLVABLE, 0L);
80+
long denylistedJobs = parsedJobStatuses.getOrDefault(JobStatus.DENYLISTED, 0L);
81+
long resolutionErrorJobs = parsedJobStatuses.getOrDefault(JobStatus.RESOLUTION_ERROR, 0L);
7982
bulkScan.setScanJobsPublished(submittedJobs);
80-
bulkScan.setScanJobsResolutionErrors(
81-
parsedJobStatuses.getOrDefault(JobStatus.UNRESOLVABLE, 0L));
82-
bulkScan.setScanJobsDenylisted(
83-
parsedJobStatuses.getOrDefault(JobStatus.DENYLISTED, 0L));
83+
bulkScan.setScanJobsResolutionErrors(unresolvedJobs+resolutionErrorJobs);
84+
bulkScan.setScanJobsDenylisted(denylistedJobs);
8485
persistenceProvider.updateBulkScan(bulkScan);
8586

8687
if (controllerConfig.isMonitored() && submittedJobs == 0) {
8788
progressMonitor.stopMonitoringAndFinalizeBulkScan(bulkScan.get_id());
8889
}
89-
LOGGER.info("Submitted {} scan jobs to RabbitMq", submittedJobs);
90+
LOGGER.info("Submitted {} scan jobs to RabbitMq (Not submitted: {} Unresolvable, {} Denylisted, {} unhandled Error)", submittedJobs,unresolvedJobs, denylistedJobs, resolutionErrorJobs);
9091
} catch (Exception e) {
9192
LOGGER.error("Exception while publishing BulkScan: ", e);
9293
JobExecutionException e2 = new JobExecutionException(e);
@@ -117,15 +118,26 @@ public JobSubmitter(
117118

118119
@Override
119120
public JobStatus apply(String targetString) {
120-
var targetInfo =
121-
ScanTarget.fromTargetString(targetString, defaultPort, denylistProvider);
122-
ScanJobDescription jobDescription =
123-
new ScanJobDescription(targetInfo.getLeft(), bulkScan, targetInfo.getRight());
121+
ScanJobDescription jobDescription;
122+
ScanResult errorResult = null;
123+
try {
124+
var targetInfo =
125+
ScanTarget.fromTargetString(targetString, defaultPort, denylistProvider);
126+
jobDescription =
127+
new ScanJobDescription(targetInfo.getLeft(), bulkScan, targetInfo.getRight());
128+
}catch (Exception e){
129+
jobDescription = new ScanJobDescription(new ScanTarget(), bulkScan, JobStatus.RESOLUTION_ERROR);
130+
errorResult = ScanResult.fromException(jobDescription, e);
131+
LOGGER.error("Error while creating ScanJobDescription for target '{}'", targetString, e);
132+
}
133+
124134
if (jobDescription.getStatus() == JobStatus.TO_BE_EXECUTED) {
125135
orchestrationProvider.submitScanJob(jobDescription);
126136
} else {
127-
persistenceProvider.insertScanResult(
128-
new ScanResult(jobDescription, null), jobDescription);
137+
if(errorResult == null){
138+
errorResult = new ScanResult(jobDescription, null);
139+
}
140+
persistenceProvider.insertScanResult(errorResult, jobDescription);
129141
}
130142
return jobDescription.getStatus();
131143
}

src/main/java/de/rub/nds/crawler/denylist/DenylistFileProvider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,20 @@ public DenylistFileProvider(String denylistFilename) {
5858
}
5959
}
6060

61+
private boolean isInSubnet(String ip, SubnetUtils.SubnetInfo subnetInfo) {
62+
try {
63+
return subnetInfo.isInRange(ip);
64+
} catch (IllegalArgumentException e) {
65+
// most likely we tried to check an IPv6 address against an IPv4 subnet
66+
return false;
67+
}
68+
}
69+
6170
@Override
6271
public synchronized boolean isDenylisted(ScanTarget target) {
6372
return domainDenylistSet.contains(target.getHostname())
6473
|| ipDenylistSet.contains(target.getIp())
6574
|| cidrDenylist.stream()
66-
.anyMatch(subnetInfo -> subnetInfo.isInRange(target.getIp()));
75+
.anyMatch(subnetInfo -> isInSubnet(target.getIp(), subnetInfo));
6776
}
6877
}

src/main/java/de/rub/nds/crawler/targetlist/TargetFileProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public List<String> getTargetList() {
3232
LOGGER.info("Reading hostName list");
3333
List<String> targetList;
3434
try (Stream<String> lines = Files.lines(Paths.get(filename))) {
35-
targetList = lines.collect(Collectors.toList());
35+
// remove comments and empty lines
36+
targetList = lines.filter(line -> !(line.startsWith("#") || line.isEmpty()))
37+
.collect(Collectors.toList());
3638
} catch (IOException ex) {
3739
throw new RuntimeException("Could not load " + filename, ex);
3840
}

0 commit comments

Comments
 (0)