Commit ae32691
committed
Fix ICMP false positives by validating response type
## Problem
The socket_icmp() method treated any ICMP response as host detection,
causing false positives when firewalls sent ICMP Type 3 errors.
## Root Cause
Code only validated packet_id match, not ICMP response type.
RFC 792 specifies only Type 0 (Echo Reply) indicates host is alive.
## Solution
1. Initialize delay/type/code to None (prevents UnboundLocalError)
2. Capture ICMP type and code from response packet
3. Validate type before declaring host alive
4. Only ICMP Echo Reply (type 0) = host alive
5. ICMP Type 3 errors = host unreachable
6. No response (timeout) = filtered/blocked
## Changes
- Modified socket_icmp() to extract ICMP type/code
- Added validation: status = 'alive' only if type == 0
- Updated return to include icmp_type, icmp_code, status fields
- Modified response_conditions_matched() to validate status field
- Added 4 comprehensive unit tests
## Testing
- Unit tests: 4 new tests cover all scenarios
* Echo Reply (type 0) = match
* Destination Unreachable (type 3) = no match
* Network Unreachable (type 3, code 0) = no match
* No response (timeout) = no match
- Integration tests: Validated with real hosts
- RFC 792 compliance: Only type 0 marked as alive
## Impact
- Eliminates false positives from firewall error responses
- More accurate ICMP scanning results
- Better error diagnostics with type/code fields
Fixes #11861 parent 9b5ef1c commit ae32691
2 files changed
+115
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
224 | 234 | | |
225 | 235 | | |
226 | 236 | | |
227 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
228 | 241 | | |
229 | 242 | | |
230 | 243 | | |
231 | 244 | | |
232 | 245 | | |
233 | 246 | | |
234 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
235 | 269 | | |
236 | 270 | | |
237 | 271 | | |
| |||
288 | 322 | | |
289 | 323 | | |
290 | 324 | | |
291 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
292 | 341 | | |
293 | 342 | | |
294 | 343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
11 | 50 | | |
12 | 51 | | |
13 | 52 | | |
| |||
153 | 192 | | |
154 | 193 | | |
155 | 194 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
161 | 220 | | |
162 | 221 | | |
163 | 222 | | |
| |||
0 commit comments