|
10 | 10 |
|
11 | 11 | import de.rub.nds.tlsattacker.attacks.connectivity.ConnectivityChecker;
|
12 | 12 | import de.rub.nds.tlsattacker.core.config.Config;
|
13 |
| -import de.rub.nds.tlsattacker.core.config.delegate.ClientDelegate; |
14 |
| -import de.rub.nds.tlsattacker.core.config.delegate.GeneralDelegate; |
| 13 | +import de.rub.nds.tlsattacker.core.workflow.NamedThreadFactory; |
| 14 | +import de.rub.nds.tlsattacker.core.workflow.ParallelExecutor; |
15 | 15 | import de.rub.nds.tlsscanner.config.ScannerConfig;
|
16 | 16 | import de.rub.nds.tlsscanner.constants.ProbeType;
|
17 | 17 | import de.rub.nds.tlsscanner.probe.BleichenbacherProbe;
|
18 | 18 | import de.rub.nds.tlsscanner.probe.CertificateProbe;
|
19 | 19 | import de.rub.nds.tlsscanner.probe.CiphersuiteOrderProbe;
|
20 | 20 | import de.rub.nds.tlsscanner.probe.CiphersuiteProbe;
|
| 21 | +import de.rub.nds.tlsscanner.probe.CommonBugProbe; |
21 | 22 | import de.rub.nds.tlsscanner.probe.CompressionsProbe;
|
22 | 23 | import de.rub.nds.tlsscanner.probe.Cve20162107Probe;
|
23 | 24 | import de.rub.nds.tlsscanner.probe.DrownProbe;
|
24 | 25 | import de.rub.nds.tlsscanner.probe.EarlyCcsProbe;
|
25 | 26 | import de.rub.nds.tlsscanner.probe.ExtensionProbe;
|
26 | 27 | import de.rub.nds.tlsscanner.probe.HeartbleedProbe;
|
| 28 | +import de.rub.nds.tlsscanner.probe.HttpHeaderProbe; |
27 | 29 | import de.rub.nds.tlsscanner.probe.InvalidCurveProbe;
|
28 | 30 | import de.rub.nds.tlsscanner.probe.MacProbe;
|
29 | 31 | import de.rub.nds.tlsscanner.probe.NamedCurvesProbe;
|
|
40 | 42 | import de.rub.nds.tlsscanner.probe.TokenbindingProbe;
|
41 | 43 | import de.rub.nds.tlsscanner.report.after.AfterProbe;
|
42 | 44 | import de.rub.nds.tlsscanner.report.after.FreakAfterProbe;
|
| 45 | +import de.rub.nds.tlsscanner.report.after.LogjamAfterprobe; |
43 | 46 | import de.rub.nds.tlsscanner.report.after.Sweet32AfterProbe;
|
44 | 47 | import java.util.LinkedList;
|
45 | 48 | import java.util.List;
|
46 |
| -import org.apache.logging.log4j.Level; |
47 |
| -import org.apache.logging.log4j.core.config.Configurator; |
| 49 | +import org.apache.logging.log4j.LogManager; |
| 50 | +import org.apache.logging.log4j.Logger; |
48 | 51 |
|
49 | 52 | /**
|
50 | 53 | *
|
51 | 54 | * @author Robert Merget - [email protected]
|
52 | 55 | */
|
53 | 56 | public class TlsScanner {
|
54 | 57 |
|
| 58 | + private final Logger LOGGER = LogManager.getLogger(); |
| 59 | + |
55 | 60 | private final ScanJobExecutor executor;
|
| 61 | + private final ParallelExecutor parallelExecutor; |
56 | 62 | private final ScannerConfig config;
|
57 |
| - |
58 |
| - public TlsScanner(String websiteHost, boolean attackingScans) { |
59 |
| - config = new ScannerConfig(new GeneralDelegate()); |
60 |
| - this.executor = ScanJobExecutorFactory.getScanJobExecutor(config); |
61 |
| - ClientDelegate clientDelegate = (ClientDelegate) config.getDelegateList().get(1); |
62 |
| - clientDelegate.setHost(websiteHost); |
63 |
| - Configurator.setAllLevels("de.rub.nds.tlsattacker", Level.WARN); |
64 |
| - } |
| 63 | + private final boolean closeAfterFinish; |
| 64 | + private final boolean closeAfterFinishParallel; |
| 65 | + private final List<TlsProbe> phaseOneTestList; |
| 66 | + private final List<TlsProbe> phaseTwoTestList; |
| 67 | + private final List<AfterProbe> afterList; |
65 | 68 |
|
66 | 69 | public TlsScanner(ScannerConfig config) {
|
67 | 70 | this.executor = ScanJobExecutorFactory.getScanJobExecutor(config);
|
68 | 71 | this.config = config;
|
| 72 | + closeAfterFinish = true; |
| 73 | + closeAfterFinishParallel = true; |
| 74 | + parallelExecutor = new ParallelExecutor(config.getAggroLevel(), 3, new NamedThreadFactory(config.getClientDelegate().getHost() + "-Worker")); |
| 75 | + this.phaseOneTestList = new LinkedList<>(); |
| 76 | + this.phaseTwoTestList = new LinkedList<>(); |
| 77 | + this.afterList = new LinkedList<>(); |
| 78 | + fillDefaultProbeLists(); |
69 | 79 | }
|
70 | 80 |
|
71 | 81 | public TlsScanner(ScannerConfig config, ScanJobExecutor executor) {
|
72 | 82 | this.config = config;
|
73 | 83 | this.executor = executor;
|
| 84 | + closeAfterFinish = false; |
| 85 | + closeAfterFinishParallel = true; |
| 86 | + parallelExecutor = new ParallelExecutor(config.getAggroLevel(), 3, new NamedThreadFactory(config.getClientDelegate().getHost() + "-Worker")); |
| 87 | + this.phaseOneTestList = new LinkedList<>(); |
| 88 | + this.phaseTwoTestList = new LinkedList<>(); |
| 89 | + this.afterList = new LinkedList<>(); |
| 90 | + fillDefaultProbeLists(); |
74 | 91 | }
|
75 | 92 |
|
76 |
| - public SiteReport scan() { |
77 |
| - List<TlsProbe> phaseOneTestList = new LinkedList<>(); |
78 |
| - List<TlsProbe> phaseTwoTestList = new LinkedList<>(); |
| 93 | + public TlsScanner(ScannerConfig config, ScanJobExecutor executor, ParallelExecutor parallelExecutor) { |
| 94 | + this.config = config; |
| 95 | + this.executor = executor; |
| 96 | + this.parallelExecutor = parallelExecutor; |
| 97 | + closeAfterFinish = false; |
| 98 | + closeAfterFinishParallel = false; |
| 99 | + this.phaseOneTestList = new LinkedList<>(); |
| 100 | + this.phaseTwoTestList = new LinkedList<>(); |
| 101 | + this.afterList = new LinkedList<>(); |
| 102 | + fillDefaultProbeLists(); |
| 103 | + } |
79 | 104 |
|
80 |
| - if (prechecks()) { |
81 |
| - phaseOneTestList.add(new SniProbe(config)); |
82 |
| - phaseOneTestList.add(new CompressionsProbe(config)); |
83 |
| - phaseOneTestList.add(new NamedCurvesProbe(config)); |
84 |
| - phaseOneTestList.add(new CertificateProbe(config)); |
85 |
| - phaseOneTestList.add(new ProtocolVersionProbe(config)); |
86 |
| - phaseOneTestList.add(new CiphersuiteProbe(config)); |
87 |
| - phaseOneTestList.add(new CiphersuiteOrderProbe(config)); |
88 |
| - phaseOneTestList.add(new ExtensionProbe(config)); |
89 |
| - phaseOneTestList.add(new Tls13Probe(config)); |
90 |
| - phaseOneTestList.add(new TokenbindingProbe(config)); |
| 105 | + public TlsScanner(ScannerConfig config, ScanJobExecutor executor, ParallelExecutor parallelExecutor, List<TlsProbe> phaseOneTestList, List<TlsProbe> phaseTwoTestList, List<AfterProbe> afterList) { |
| 106 | + this.executor = executor; |
| 107 | + this.parallelExecutor = parallelExecutor; |
| 108 | + this.config = config; |
| 109 | + this.phaseOneTestList = phaseOneTestList; |
| 110 | + this.phaseTwoTestList = phaseTwoTestList; |
| 111 | + this.afterList = afterList; |
| 112 | + closeAfterFinish = false; |
| 113 | + closeAfterFinishParallel = false; |
| 114 | + } |
91 | 115 |
|
92 |
| - phaseTwoTestList.add(new ResumptionProbe(config)); |
93 |
| - phaseTwoTestList.add(new RenegotiationProbe(config)); |
94 |
| - phaseTwoTestList.add(new HeartbleedProbe(config)); |
95 |
| - phaseTwoTestList.add(new PaddingOracleProbe(config)); |
96 |
| - phaseTwoTestList.add(new BleichenbacherProbe(config)); |
97 |
| - phaseTwoTestList.add(new PoodleProbe(config)); |
98 |
| - phaseTwoTestList.add(new TlsPoodleProbe(config)); |
99 |
| - phaseTwoTestList.add(new Cve20162107Probe(config)); |
100 |
| - phaseTwoTestList.add(new InvalidCurveProbe(config)); |
101 |
| - phaseTwoTestList.add(new DrownProbe(config)); |
102 |
| - phaseTwoTestList.add(new EarlyCcsProbe(config)); |
103 |
| - phaseTwoTestList.add(new MacProbe(config)); |
| 116 | + private void fillDefaultProbeLists() { |
| 117 | + phaseOneTestList.add(new CommonBugProbe(config, parallelExecutor)); |
| 118 | + phaseOneTestList.add(new SniProbe(config, parallelExecutor)); |
| 119 | + phaseOneTestList.add(new CompressionsProbe(config, parallelExecutor)); |
| 120 | + phaseOneTestList.add(new NamedCurvesProbe(config, parallelExecutor)); |
| 121 | + phaseOneTestList.add(new CertificateProbe(config, parallelExecutor)); |
| 122 | + phaseOneTestList.add(new ProtocolVersionProbe(config, parallelExecutor)); |
| 123 | + phaseOneTestList.add(new CiphersuiteProbe(config, parallelExecutor)); |
| 124 | + phaseOneTestList.add(new CiphersuiteOrderProbe(config, parallelExecutor)); |
| 125 | + phaseOneTestList.add(new ExtensionProbe(config, parallelExecutor)); |
| 126 | + phaseOneTestList.add(new Tls13Probe(config, parallelExecutor)); |
| 127 | + phaseOneTestList.add(new TokenbindingProbe(config, parallelExecutor)); |
| 128 | + phaseOneTestList.add(new HttpHeaderProbe(config, parallelExecutor)); |
| 129 | + phaseTwoTestList.add(new ResumptionProbe(config, parallelExecutor)); |
| 130 | + phaseTwoTestList.add(new RenegotiationProbe(config, parallelExecutor)); |
| 131 | + phaseTwoTestList.add(new HeartbleedProbe(config, parallelExecutor)); |
| 132 | + phaseTwoTestList.add(new PaddingOracleProbe(config, parallelExecutor)); |
| 133 | + phaseTwoTestList.add(new BleichenbacherProbe(config, parallelExecutor)); |
| 134 | + phaseTwoTestList.add(new PoodleProbe(config, parallelExecutor)); |
| 135 | + phaseTwoTestList.add(new TlsPoodleProbe(config, parallelExecutor)); |
| 136 | + phaseTwoTestList.add(new Cve20162107Probe(config, parallelExecutor)); |
| 137 | + phaseTwoTestList.add(new InvalidCurveProbe(config, parallelExecutor)); |
| 138 | + phaseTwoTestList.add(new DrownProbe(config, parallelExecutor)); |
| 139 | + phaseTwoTestList.add(new EarlyCcsProbe(config, parallelExecutor)); |
| 140 | + phaseTwoTestList.add(new MacProbe(config, parallelExecutor)); |
| 141 | + afterList.add(new Sweet32AfterProbe()); |
| 142 | + afterList.add(new FreakAfterProbe()); |
| 143 | + afterList.add(new LogjamAfterprobe()); |
| 144 | + } |
| 145 | + |
| 146 | + public SiteReport scan() { |
| 147 | + boolean isConnectable = false; |
| 148 | + try { |
| 149 | + if (isConnectable()) { |
| 150 | + LOGGER.debug(config.getClientDelegate().getHost() + " is connectable"); |
| 151 | + if (speaksTls()) { |
| 152 | + LOGGER.debug(config.getClientDelegate().getHost() + " is connectable"); |
| 153 | + ScanJob job = new ScanJob(phaseOneTestList, phaseTwoTestList, afterList); |
| 154 | + SiteReport report = executor.execute(config, job); |
| 155 | + return report; |
| 156 | + } else { |
| 157 | + isConnectable = true; |
| 158 | + } |
| 159 | + } |
| 160 | + SiteReport report = new SiteReport(config.getClientDelegate().getHost(), new LinkedList<ProbeType>(), config.isNoColor()); |
| 161 | + report.setServerIsAlive(isConnectable); |
| 162 | + report.setSupportsSslTls(false); |
| 163 | + return report; |
| 164 | + } finally { |
| 165 | + closeExecutorsIfNeeded(); |
| 166 | + } |
| 167 | + } |
104 | 168 |
|
105 |
| - List<AfterProbe> afterList = new LinkedList<>(); |
106 |
| - afterList.add(new Sweet32AfterProbe()); |
107 |
| - afterList.add(new FreakAfterProbe()); |
108 |
| - ScanJob job = new ScanJob(phaseOneTestList, phaseTwoTestList, afterList); |
109 |
| - return executor.execute(config, job); |
| 169 | + private void closeExecutorsIfNeeded() { |
| 170 | + if (closeAfterFinish) { |
| 171 | + executor.shutdown(); |
| 172 | + } |
| 173 | + if (closeAfterFinishParallel) { |
| 174 | + parallelExecutor.shutdown(); |
110 | 175 | }
|
111 |
| - // testList.add(new SignatureAndHashAlgorithmProbe(websiteHost)); |
112 |
| - SiteReport report = new SiteReport(config.getClientDelegate().getHost(), new LinkedList<ProbeType>(), config.isNoColor()); |
113 |
| - report.setServerIsAlive(false); |
114 |
| - return report; |
115 | 176 | }
|
116 | 177 |
|
117 |
| - public boolean prechecks() { |
| 178 | + public boolean isConnectable() { |
118 | 179 | Config tlsConfig = config.createConfig();
|
119 | 180 | ConnectivityChecker checker = new ConnectivityChecker(tlsConfig.getDefaultClientConnection());
|
120 | 181 | return checker.isConnectable();
|
121 | 182 | }
|
| 183 | + |
| 184 | + private boolean speaksTls() { |
| 185 | + Config tlsConfig = config.createConfig(); |
| 186 | + ConnectivityChecker checker = new ConnectivityChecker(tlsConfig.getDefaultClientConnection()); |
| 187 | + return checker.speaksTls(tlsConfig); |
| 188 | + } |
122 | 189 | }
|
0 commit comments