-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Support multiple IPs per hostname in ScanTarget #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,19 @@ private boolean isInSubnet(String ip, SubnetUtils.SubnetInfo subnetInfo) { | |
|
|
||
| @Override | ||
| public synchronized boolean isDenylisted(ScanTarget target) { | ||
| return domainDenylistSet.contains(target.getHostname()) | ||
| || ipDenylistSet.contains(target.getIp()) | ||
| || cidrDenylist.stream() | ||
| .anyMatch(subnetInfo -> isInSubnet(target.getIp(), subnetInfo)); | ||
| // Check if hostname is denylisted | ||
| if (domainDenylistSet.contains(target.getHostname())) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check if any of the IPs are denylisted | ||
| for (String ip : target.getIps()) { | ||
| if (ipDenylistSet.contains(ip) | ||
| || cidrDenylist.stream().anyMatch(subnetInfo -> isInSubnet(ip, subnetInfo))) { | ||
| return true; | ||
| } | ||
| } | ||
|
Comment on lines
+78
to
+83
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure what the correct behavior is, if a domain resolves to two IPs and only one is denylisted: 1: We do not scan this domain at all. Maybe the domain owner just forgot to tell us all IPs -> the intention of the denylist entry is to not be scanned at all. |
||
|
|
||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * TLS-Crawler - A TLS scanning tool to perform large scale scans with the TLS-Scanner | ||
| * | ||
| * Copyright 2018-2022 Ruhr University Bochum, Paderborn University, and Hackmanit GmbH | ||
| * | ||
| * Licensed under Apache License, Version 2.0 | ||
| * http://www.apache.org/licenses/LICENSE-2.0.txt | ||
| */ | ||
| package de.rub.nds.crawler.data; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import de.rub.nds.crawler.constant.JobStatus; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ScanTargetTest { | ||
|
|
||
| @Test | ||
| void testFromTargetStringWithHostname() { | ||
| // Test hostname resolution to multiple IPs | ||
| Pair<ScanTarget, JobStatus> result = ScanTarget.fromTargetString("localhost", 443, null); | ||
|
|
||
| assertEquals(JobStatus.TO_BE_EXECUTED, result.getRight()); | ||
| ScanTarget target = result.getLeft(); | ||
|
|
||
| assertEquals("localhost", target.getHostname()); | ||
| assertEquals(443, target.getPort()); | ||
| assertNotNull(target.getIps()); | ||
| assertFalse(target.getIps().isEmpty()); | ||
| // localhost should resolve to at least one IP | ||
| assertTrue(target.getIps().size() >= 1); | ||
| // The deprecated getIp() should return the first IP | ||
| assertEquals(target.getIps().get(0), target.getIp()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFromTargetStringWithIpAddress() { | ||
| Pair<ScanTarget, JobStatus> result = ScanTarget.fromTargetString("127.0.0.1", 443, null); | ||
|
|
||
| assertEquals(JobStatus.TO_BE_EXECUTED, result.getRight()); | ||
| ScanTarget target = result.getLeft(); | ||
|
|
||
| assertNull(target.getHostname()); | ||
| assertEquals("127.0.0.1", target.getIp()); | ||
| assertEquals(Arrays.asList("127.0.0.1"), target.getIps()); | ||
| assertEquals(443, target.getPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFromTargetStringWithPort() { | ||
| Pair<ScanTarget, JobStatus> result = | ||
| ScanTarget.fromTargetString("127.0.0.1:8443", 443, null); | ||
|
|
||
| assertEquals(JobStatus.TO_BE_EXECUTED, result.getRight()); | ||
| ScanTarget target = result.getLeft(); | ||
|
|
||
| assertEquals("127.0.0.1", target.getIp()); | ||
| assertEquals(Arrays.asList("127.0.0.1"), target.getIps()); | ||
| assertEquals(8443, target.getPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFromTargetStringWithTrancoRank() { | ||
| Pair<ScanTarget, JobStatus> result = | ||
| ScanTarget.fromTargetString("100,127.0.0.1", 443, null); | ||
|
|
||
| assertEquals(JobStatus.TO_BE_EXECUTED, result.getRight()); | ||
| ScanTarget target = result.getLeft(); | ||
|
|
||
| assertEquals(100, target.getTrancoRank()); | ||
| assertEquals("127.0.0.1", target.getIp()); | ||
| assertEquals(Arrays.asList("127.0.0.1"), target.getIps()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFromTargetStringUnresolvableHost() { | ||
| Pair<ScanTarget, JobStatus> result = | ||
| ScanTarget.fromTargetString("this-host-should-not-exist-12345.invalid", 443, null); | ||
|
|
||
| assertEquals(JobStatus.UNRESOLVABLE, result.getRight()); | ||
| } | ||
|
|
||
| @Test | ||
| void testSetIpsAndBackwardCompatibility() { | ||
| ScanTarget target = new ScanTarget(); | ||
| List<String> ips = Arrays.asList("192.168.1.1", "192.168.1.2", "192.168.1.3"); | ||
|
|
||
| target.setIps(ips); | ||
|
|
||
| // Check that all IPs are stored | ||
| assertEquals(ips, target.getIps()); | ||
| // Check backward compatibility - getIp() should return the first IP | ||
| assertEquals("192.168.1.1", target.getIp()); | ||
| } | ||
|
|
||
| @Test | ||
| void testSetIpBackwardCompatibility() { | ||
| ScanTarget target = new ScanTarget(); | ||
|
|
||
| // Test deprecated setIp method | ||
| target.setIp("10.0.0.1"); | ||
|
|
||
| assertEquals("10.0.0.1", target.getIp()); | ||
| assertEquals(Arrays.asList("10.0.0.1"), target.getIps()); | ||
|
|
||
| // Setting another IP should update the list | ||
| target.setIp("10.0.0.2"); | ||
| assertEquals("10.0.0.2", target.getIp()); | ||
| assertEquals(Arrays.asList("10.0.0.2"), target.getIps()); | ||
| } | ||
|
|
||
| @Test | ||
| void testToStringWithMultipleIps() { | ||
| ScanTarget target = new ScanTarget(); | ||
|
|
||
| // Test with hostname | ||
| target.setHostname("example.com"); | ||
| target.setIps(Arrays.asList("192.168.1.1", "192.168.1.2")); | ||
| assertEquals("example.com", target.toString()); | ||
|
|
||
| // Test with single IP (no hostname) | ||
| target = new ScanTarget(); | ||
| target.setIps(Arrays.asList("192.168.1.1")); | ||
| assertEquals("192.168.1.1", target.toString()); | ||
|
|
||
| // Test with multiple IPs (no hostname) | ||
| target = new ScanTarget(); | ||
| target.setIps(Arrays.asList("192.168.1.1", "192.168.1.2", "192.168.1.3")); | ||
| assertEquals("[192.168.1.1, 192.168.1.2, 192.168.1.3]", target.toString()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could cause weird effects. I would assume that this function just sets
ipsto a list of size 1.