■ ■ ■ ■ ■ ■ ■
plugin/src/main/java/com/google/tsunami/plugin/PluginManager.java
| skipped 21 lines |
22 | 22 | | import com.google.common.base.Ascii; |
23 | 23 | | import com.google.common.collect.ImmutableList; |
24 | 24 | | import com.google.common.collect.Streams; |
| 25 | + | import com.google.tsunami.proto.MatchedPlugin; |
25 | 26 | | import com.google.tsunami.proto.NetworkService; |
26 | 27 | | import com.google.tsunami.proto.ReconnaissanceReport; |
27 | 28 | | import java.util.Arrays; |
| skipped 67 lines |
95 | 96 | | public ImmutableList<PluginMatchingResult<VulnDetector>> getVulnDetectors( |
96 | 97 | | ReconnaissanceReport reconnaissanceReport) { |
97 | 98 | | return tsunamiPlugins.entrySet().stream() |
98 | | - | .filter(entry -> entry.getKey().type().equals(PluginType.VULN_DETECTION)) |
99 | | - | .map(entry -> matchVulnDetectors(entry.getKey(), entry.getValue(), reconnaissanceReport)) |
| 99 | + | .filter(entry -> isVulnDetector(entry.getKey())) |
| 100 | + | .map(entry -> matchAllVulnDetectors(entry.getKey(), entry.getValue(), reconnaissanceReport)) |
100 | 101 | | .flatMap(Streams::stream) |
101 | 102 | | .collect(toImmutableList()); |
| 103 | + | } |
| 104 | + | |
| 105 | + | private static boolean isVulnDetector(PluginDefinition pluginDefinition) { |
| 106 | + | return pluginDefinition.type().equals(PluginType.VULN_DETECTION) |
| 107 | + | || pluginDefinition.type().equals(PluginType.REMOTE_VULN_DETECTION); |
| 108 | + | } |
| 109 | + | |
| 110 | + | private static Optional<PluginMatchingResult<VulnDetector>> matchAllVulnDetectors( |
| 111 | + | PluginDefinition pluginDefinition, |
| 112 | + | Provider<TsunamiPlugin> vulnDetectorProvider, |
| 113 | + | ReconnaissanceReport reconnaissanceReport) { |
| 114 | + | if (pluginDefinition.type().equals(PluginType.REMOTE_VULN_DETECTION)) { |
| 115 | + | return matchRemoteVulnDetectors(pluginDefinition, vulnDetectorProvider, reconnaissanceReport); |
| 116 | + | } |
| 117 | + | return matchVulnDetectors(pluginDefinition, vulnDetectorProvider, reconnaissanceReport); |
102 | 118 | | } |
103 | 119 | | |
104 | 120 | | private static Optional<PluginMatchingResult<VulnDetector>> matchVulnDetectors( |
| skipped 27 lines |
132 | 148 | | .build()); |
133 | 149 | | } |
134 | 150 | | |
| 151 | + | private static Optional<PluginMatchingResult<VulnDetector>> matchRemoteVulnDetectors( |
| 152 | + | PluginDefinition pluginDefinition, |
| 153 | + | Provider<TsunamiPlugin> tsunamiPlugin, |
| 154 | + | ReconnaissanceReport reconnaissanceReport) { |
| 155 | + | var remoteVulnDetector = (RemoteVulnDetector) tsunamiPlugin.get(); |
| 156 | + | var builder = |
| 157 | + | PluginMatchingResult.<VulnDetector>builder() |
| 158 | + | .setTsunamiPlugin(remoteVulnDetector) |
| 159 | + | // PluginDefinition class for the RemoteVulnDetector. |
| 160 | + | .setPluginDefinition(pluginDefinition) |
| 161 | + | .addAllMatchedServices(reconnaissanceReport.getNetworkServicesList()); |
| 162 | + | for (com.google.tsunami.proto.PluginDefinition remotePluginDefinition : |
| 163 | + | remoteVulnDetector.getAllPlugins()) { |
| 164 | + | var matchedPlugin = |
| 165 | + | MatchedPlugin.newBuilder() |
| 166 | + | // PluginDefinition proto of the language-specific detector. |
| 167 | + | .setPlugin(remotePluginDefinition) |
| 168 | + | // TODO(b/239439169): Add plugin matching logic for remote plugins. |
| 169 | + | .addAllServices(reconnaissanceReport.getNetworkServicesList()) |
| 170 | + | .build(); |
| 171 | + | remoteVulnDetector.addMatchedPluginToDetect(matchedPlugin); |
| 172 | + | } |
| 173 | + | return Optional.of(builder.build()); |
| 174 | + | } |
| 175 | + | |
135 | 176 | | private static boolean hasMatchingServiceName( |
136 | 177 | | NetworkService networkService, PluginDefinition pluginDefinition) { |
137 | 178 | | String serviceName = networkService.getServiceName(); |
| skipped 21 lines |
159 | 200 | | @AutoValue |
160 | 201 | | public abstract static class PluginMatchingResult<T extends TsunamiPlugin> { |
161 | 202 | | public abstract PluginDefinition pluginDefinition(); |
| 203 | + | |
162 | 204 | | public abstract T tsunamiPlugin(); |
| 205 | + | |
163 | 206 | | public abstract ImmutableList<NetworkService> matchedServices(); |
164 | 207 | | |
165 | 208 | | public String pluginId() { |
| skipped 5 lines |
171 | 214 | | } |
172 | 215 | | |
173 | 216 | | /** Builder for {@link PluginMatchingResult}. */ |
| 217 | + | @SuppressWarnings("CanIgnoreReturnValueSuggester") |
174 | 218 | | @AutoValue.Builder |
175 | 219 | | public abstract static class Builder<T extends TsunamiPlugin> { |
176 | 220 | | public abstract Builder<T> setPluginDefinition(PluginDefinition value); |
| skipped 17 lines |