#193 also scan detected open ports for proxies

This commit is contained in:
Anton Keks 2019-07-25 00:35:27 +03:00
parent d990b17c46
commit a93ee86acb
4 changed files with 24 additions and 5 deletions

View File

@ -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.

View File

@ -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() {

View File

@ -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<Integer> portIterator = subject.isAnyPortRequested() ? subject.requestedPortsIterator() : singleton(defaultPort).iterator();
Iterator<Integer> 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<Integer> getPortIterator(ScanningSubject subject) {
if (scanOpenPorts) {
@SuppressWarnings("unchecked")
SortedSet<Integer> openPorts = (SortedSet<Integer>) subject.getParameter(PARAMETER_OPEN_PORTS);
if (openPorts != null) {
SortedSet<Integer> ports = new TreeSet<>(openPorts);
ports.add(defaultPort);
return ports.iterator();
}
}
return subject.isAnyPortRequested() ? subject.requestedPortsIterator() : singleton(defaultPort).iterator();
}
@Override
public Class<? extends FetcherPrefs> getPreferencesClass() {
return PortTextFetcherPrefs.class;

View File

@ -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<Socket> sockets = new ThreadResourceBinder<>();