diff --git a/resources/messages.properties b/resources/messages.properties index ea622257..77977ab6 100644 --- a/resources/messages.properties +++ b/resources/messages.properties @@ -240,7 +240,7 @@ fetcher.webDetect.info=Detects the web server software name and version, if poss fetcher.httpSender=HTTP Sender fetcher.httpSender.info=Sends the specified textual requests to the specified TCP port (eg 80), retrieves the response and uses the specified regular expression to extract the needed information out.\n\nVery customizable, can be used for any textual protocol, like HTTP, SMTP, POP3, IMAP, etc. For advanced users. fetcher.httpProxy=HTTP Proxy -fetcher.httpProxy.info=Detects whether a working HTTP proxy is running on the host on either port 3128 or the requested port loaded using File Feeder in host:port format. +fetcher.httpProxy.info=Detects whether a working HTTP proxy is running on the host on either port 3128, any scanned open ports, or the requested port loaded using File Feeder in host:port format. fetcher.portText.custom=Custom fetcher.netbios=NetBIOS Info fetcher.netbios.info=Retrieves the NetBIOS information about Windows machines.\n\nThe response has the following format:\nDOMAIN\\USER@COMPUTER [MAC]\n\nWhere:\nDOMAIN - Windows domain or workgroup\nUSER - currently logged in user\nCOMPUTER - Windows computer name (may be different from DNS name)\nSome parts may be absent, depending on the response.\n\nNote that this won't work with machines that have firewall enabled (which are most modern installations).\nThis fetcher is provided mostly for feature-compatibility with version 2.x. diff --git a/src/net/azib/ipscan/fetchers/HTTPProxyFetcher.java b/src/net/azib/ipscan/fetchers/HTTPProxyFetcher.java index e1f6f640..c2c4abec 100644 --- a/src/net/azib/ipscan/fetchers/HTTPProxyFetcher.java +++ b/src/net/azib/ipscan/fetchers/HTTPProxyFetcher.java @@ -18,6 +18,7 @@ import javax.inject.Inject; public class HTTPProxyFetcher extends PortTextFetcher { @Inject public HTTPProxyFetcher(ScannerConfig scannerConfig) { super(scannerConfig, 3128, "HEAD http://www.google.com HTTP/1.0\r\n\r\n", "^(HTTP/[\\d\\.]+ [23].*)$"); + this.scanOpenPorts = true; } public String getId() { diff --git a/src/net/azib/ipscan/fetchers/PortTextFetcher.java b/src/net/azib/ipscan/fetchers/PortTextFetcher.java index 0a55d939..69ae2283 100644 --- a/src/net/azib/ipscan/fetchers/PortTextFetcher.java +++ b/src/net/azib/ipscan/fetchers/PortTextFetcher.java @@ -16,6 +16,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.*; import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -23,6 +25,7 @@ import java.util.regex.Pattern; import static java.lang.Thread.currentThread; import static java.util.Collections.singleton; +import static net.azib.ipscan.fetchers.PortsFetcher.PARAMETER_OPEN_PORTS; /** * PortTextFetcher - generic configurable fetcher to read some particular information from a port. @@ -35,6 +38,7 @@ public abstract class PortTextFetcher extends AbstractFetcher { private ScannerConfig scannerConfig; private int defaultPort; + protected boolean scanOpenPorts; protected String textToSend; protected Pattern matchingRegexp; protected int extractGroup; @@ -42,13 +46,14 @@ public abstract class PortTextFetcher extends AbstractFetcher { public PortTextFetcher(ScannerConfig scannerConfig, int defaultPort, String textToSend, String matchingRegexp) { this.scannerConfig = scannerConfig; this.defaultPort = defaultPort; + this.scanOpenPorts = scanOpenPorts; this.textToSend = getPreferences().get("textToSend", textToSend); this.matchingRegexp = Pattern.compile(getPreferences().get("matchingRegexp", matchingRegexp)); this.extractGroup = getPreferences().getInt("extractGroup", 1); } public Object scan(ScanningSubject subject) { - Iterator portIterator = subject.isAnyPortRequested() ? subject.requestedPortsIterator() : singleton(defaultPort).iterator(); + Iterator portIterator = getPortIterator(subject); while (portIterator.hasNext() && !currentThread().isInterrupted()) { try (Socket socket = new Socket()) { @@ -86,7 +91,20 @@ public abstract class PortTextFetcher extends AbstractFetcher { } return null; } - + + private Iterator getPortIterator(ScanningSubject subject) { + if (scanOpenPorts) { + @SuppressWarnings("unchecked") + SortedSet openPorts = (SortedSet) subject.getParameter(PARAMETER_OPEN_PORTS); + if (openPorts != null) { + SortedSet ports = new TreeSet<>(openPorts); + ports.add(defaultPort); + return ports.iterator(); + } + } + return subject.isAnyPortRequested() ? subject.requestedPortsIterator() : singleton(defaultPort).iterator(); + } + @Override public Class getPreferencesClass() { return PortTextFetcherPrefs.class; diff --git a/src/net/azib/ipscan/fetchers/PortsFetcher.java b/src/net/azib/ipscan/fetchers/PortsFetcher.java index 5ee31a8b..74f7678a 100644 --- a/src/net/azib/ipscan/fetchers/PortsFetcher.java +++ b/src/net/azib/ipscan/fetchers/PortsFetcher.java @@ -35,8 +35,8 @@ public class PortsFetcher extends AbstractFetcher { public static final String ID = "fetcher.ports"; - private static final String PARAMETER_OPEN_PORTS = "openPorts"; - private static final String PARAMETER_FILTERED_PORTS = "filteredPorts"; + static final String PARAMETER_OPEN_PORTS = "openPorts"; + static final String PARAMETER_FILTERED_PORTS = "filteredPorts"; private ScannerConfig config; private ThreadResourceBinder sockets = new ThreadResourceBinder<>();