|
22 | 22 | import java.io.IOException;
|
23 | 23 | import java.nio.charset.Charset;
|
24 | 24 | import java.util.ArrayList;
|
| 25 | +import java.util.Collections; |
25 | 26 | import java.util.HashSet;
|
26 | 27 | import java.util.List;
|
27 | 28 | import java.util.Map;
|
@@ -64,83 +65,104 @@ public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {
|
64 | 65 | if (!v.isValid()) return;
|
65 | 66 |
|
66 | 67 | if (!v.hasMACtest1() || !v.hasMACtest2())
|
67 |
| - if (!v.hasMACtest1() && !v.hasMACtest2()) alertNoMACforSure(msg, id); |
68 |
| - else alertNoMACUnsure(msg, id); |
| 68 | + if (!v.hasMACtest1() && !v.hasMACtest2()) alertNoMACforSure().raise(); |
| 69 | + else alertNoMACUnsure().raise(); |
69 | 70 |
|
70 |
| - if (!v.isLatestAspNetVersion()) alertOldAspVersion(msg, id); |
| 71 | + if (!v.isLatestAspNetVersion()) alertOldAspVersion().raise(); |
71 | 72 |
|
72 | 73 | List<ViewstateAnalyzerResult> listOfMatches = ViewstateAnalyzer.getSearchResults(v, this);
|
73 | 74 | for (ViewstateAnalyzerResult var : listOfMatches) {
|
74 |
| - if (var.hasResults()) alertViewstateAnalyzerResult(msg, id, var); |
| 75 | + if (var.hasResults()) alertViewstateAnalyzerResult(var).raise(); |
75 | 76 | }
|
76 | 77 |
|
77 |
| - if (v.isSplit()) alertSplitViewstate(msg, id); |
| 78 | + if (v.isSplit()) alertSplitViewstate().raise(); |
78 | 79 | }
|
79 | 80 |
|
80 |
| - private void alertViewstateAnalyzerResult( |
81 |
| - HttpMessage msg, int id, ViewstateAnalyzerResult var) { |
82 |
| - newAlert() |
| 81 | + private AlertBuilder alertViewstateAnalyzerResult(ViewstateAnalyzerResult var) { |
| 82 | + return newAlert() |
83 | 83 | .setName(var.pattern.getAlertHeader())
|
84 | 84 | .setRisk(Alert.RISK_MEDIUM)
|
85 | 85 | .setConfidence(Alert.CONFIDENCE_MEDIUM)
|
86 | 86 | .setDescription(var.pattern.getAlertDescription())
|
87 | 87 | .setOtherInfo(var.getResultExtract().toString())
|
88 | 88 | .setSolution(getSolution())
|
89 | 89 | .setCweId(16) // CWE Id 16 - Configuration
|
90 |
| - .setWascId(14) // WASC Id - Server Misconfiguration |
91 |
| - .raise(); |
| 90 | + .setWascId(14); // WASC Id - Server Misconfiguration |
92 | 91 | }
|
93 | 92 |
|
94 |
| - private void alertOldAspVersion(HttpMessage msg, int id) { |
95 |
| - newAlert() |
| 93 | + private AlertBuilder alertOldAspVersion() { |
| 94 | + return newAlert() |
96 | 95 | .setName(Constant.messages.getString(MESSAGE_PREFIX + "oldver.name"))
|
97 | 96 | .setRisk(Alert.RISK_LOW)
|
98 | 97 | .setConfidence(Alert.CONFIDENCE_MEDIUM)
|
99 | 98 | .setDescription(Constant.messages.getString(MESSAGE_PREFIX + "oldver.desc"))
|
100 | 99 | .setSolution(Constant.messages.getString(MESSAGE_PREFIX + "oldver.soln"))
|
101 | 100 | .setCweId(16) // CWE Id 16 - Configuration
|
102 |
| - .setWascId(14) // WASC Id - Server Misconfiguration |
103 |
| - .raise(); |
| 101 | + .setWascId(14); // WASC Id - Server Misconfiguration |
104 | 102 | }
|
105 | 103 |
|
106 | 104 | // TODO: see if this alert triggers too often, as the detection rule is far from being robust
|
107 | 105 | // for the moment
|
108 |
| - private void alertNoMACUnsure(HttpMessage msg, int id) { |
109 |
| - newAlert() |
| 106 | + private AlertBuilder alertNoMACUnsure() { |
| 107 | + return newAlert() |
110 | 108 | .setName(Constant.messages.getString(MESSAGE_PREFIX + "nomac.unsure.name"))
|
111 | 109 | .setRisk(Alert.RISK_HIGH)
|
112 | 110 | .setConfidence(Alert.CONFIDENCE_LOW)
|
113 | 111 | .setDescription(Constant.messages.getString(MESSAGE_PREFIX + "nomac.unsure.desc"))
|
114 | 112 | .setSolution(Constant.messages.getString(MESSAGE_PREFIX + "nomac.unsure.soln"))
|
115 | 113 | .setReference(Constant.messages.getString(MESSAGE_PREFIX + "nomac.unsure.refs"))
|
116 | 114 | .setCweId(642) // CWE Id 642 - External Control of Critical State Data
|
117 |
| - .setWascId(14) // WASC Id - Server Misconfiguration |
118 |
| - .raise(); |
| 115 | + .setWascId(14); // WASC Id - Server Misconfiguration |
119 | 116 | }
|
120 | 117 |
|
121 |
| - private void alertNoMACforSure(HttpMessage msg, int id) { |
122 |
| - newAlert() |
| 118 | + private AlertBuilder alertNoMACforSure() { |
| 119 | + return newAlert() |
123 | 120 | .setName(Constant.messages.getString(MESSAGE_PREFIX + "nomac.sure.name"))
|
124 | 121 | .setRisk(Alert.RISK_HIGH)
|
125 | 122 | .setConfidence(Alert.CONFIDENCE_MEDIUM)
|
126 | 123 | .setDescription(Constant.messages.getString(MESSAGE_PREFIX + "nomac.sure.desc"))
|
127 | 124 | .setSolution(Constant.messages.getString(MESSAGE_PREFIX + "nomac.sure.soln"))
|
128 | 125 | .setReference(Constant.messages.getString(MESSAGE_PREFIX + "nomac.sure.refs"))
|
129 | 126 | .setCweId(642) // CWE Id 642 - External Control of Critical State Data
|
130 |
| - .setWascId(14) // WASC Id - Server Misconfiguration |
131 |
| - .raise(); |
| 127 | + .setWascId(14); // WASC Id - Server Misconfiguration |
132 | 128 | }
|
133 | 129 |
|
134 |
| - private void alertSplitViewstate(HttpMessage msg, int id) { |
135 |
| - newAlert() |
| 130 | + private AlertBuilder alertSplitViewstate() { |
| 131 | + return newAlert() |
136 | 132 | .setName(Constant.messages.getString(MESSAGE_PREFIX + "split.name"))
|
137 | 133 | .setRisk(Alert.RISK_INFO)
|
138 | 134 | .setConfidence(Alert.CONFIDENCE_LOW)
|
139 | 135 | .setDescription(Constant.messages.getString(MESSAGE_PREFIX + "split.desc"))
|
140 | 136 | .setSolution(Constant.messages.getString(MESSAGE_PREFIX + "split.soln"))
|
141 | 137 | .setCweId(16) // CWE Id 16 - Configuration
|
142 |
| - .setWascId(14) // WASC Id - Server Misconfiguration |
143 |
| - .raise(); |
| 138 | + .setWascId(14); // WASC Id - Server Misconfiguration |
| 139 | + } |
| 140 | + |
| 141 | + public List<Alert> getExampleAlerts() { |
| 142 | + List<Alert> alerts = new ArrayList<Alert>(); |
| 143 | + alerts.add( |
| 144 | + alertViewstateAnalyzerResult( |
| 145 | + new ViewstateAnalyzerResult(ViewstateAnalyzerPattern.IPADDRESS) { |
| 146 | + @Override |
| 147 | + public Set<String> getResultExtract() { |
| 148 | + return Collections.emptySet(); |
| 149 | + } |
| 150 | + }) |
| 151 | + .build()); |
| 152 | + alerts.add( |
| 153 | + alertViewstateAnalyzerResult( |
| 154 | + new ViewstateAnalyzerResult(ViewstateAnalyzerPattern.EMAIL) { |
| 155 | + @Override |
| 156 | + public Set<String> getResultExtract() { |
| 157 | + return Collections.emptySet(); |
| 158 | + } |
| 159 | + }) |
| 160 | + .build()); |
| 161 | + alerts.add(alertOldAspVersion().build()); |
| 162 | + alerts.add(alertNoMACUnsure().build()); |
| 163 | + alerts.add(alertNoMACforSure().build()); |
| 164 | + alerts.add(alertSplitViewstate().build()); |
| 165 | + return alerts; |
144 | 166 | }
|
145 | 167 |
|
146 | 168 | @Override
|
|
0 commit comments