#193 return found port number from HTTPProxyFetcher

This commit is contained in:
Anton Keks 2019-07-25 00:42:34 +03:00
parent a93ee86acb
commit cfef765dac
2 changed files with 12 additions and 2 deletions

View File

@ -9,6 +9,7 @@ package net.azib.ipscan.fetchers;
import net.azib.ipscan.config.ScannerConfig;
import javax.inject.Inject;
import java.util.regex.Matcher;
/**
* HTTPProxyFetcher - detects HTTP proxy on port 3128 (or other requested port)
@ -24,4 +25,9 @@ public class HTTPProxyFetcher extends PortTextFetcher {
public String getId() {
return "fetcher.httpProxy";
}
@Override
protected String getResult(Matcher matcher, int port) {
return port + ": " + super.getResult(matcher, port);
}
}

View File

@ -46,7 +46,6 @@ 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);
@ -72,7 +71,7 @@ public abstract class PortTextFetcher extends AbstractFetcher {
// mark that additional info is available
subject.setResultType(ResultType.WITH_PORTS);
// return the required contents
return matcher.group(extractGroup);
return getResult(matcher, socket.getPort());
}
}
}
@ -92,6 +91,11 @@ public abstract class PortTextFetcher extends AbstractFetcher {
return null;
}
protected String getResult(Matcher matcher, int port) {
String result = matcher.group(extractGroup);
return result.isEmpty() ? String.valueOf(port) : result;
}
private Iterator<Integer> getPortIterator(ScanningSubject subject) {
if (scanOpenPorts) {
@SuppressWarnings("unchecked")