Skip to content

Commit

Permalink
Warning about packet streams and fixed dst port validation (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakird committed Nov 6, 2023
1 parent 146ded1 commit 86809e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/probe_modules/packet.h
Expand Up @@ -155,7 +155,11 @@ static inline int check_dst_port(uint16_t port, int num_ports,
int32_t min = validation[1] % num_ports;
int32_t max = (validation[1] + zconf.packet_streams - 1) % num_ports;

return (((max - min) % num_ports) >= ((to_validate - min) % num_ports));
if (min <= max) {
return (to_validate <= max && to_validate >= min);
} else {
return (to_validate <= max ^ to_validate >= min);
}
}

static inline uint16_t get_src_port(int num_ports, int probe_num,
Expand Down
14 changes: 14 additions & 0 deletions src/zmap.c
Expand Up @@ -553,6 +553,7 @@ int main(int argc, char *argv[])
SET_IF_GIVEN(zconf.max_sendto_failures, max_sendto_failures);
SET_IF_GIVEN(zconf.min_hitrate, min_hitrate);


if (zconf.num_retries < 0) {
log_fatal("zmap", "Invalid retry count");
}
Expand Down Expand Up @@ -646,6 +647,19 @@ int main(int argc, char *argv[])
zconf.source_port_first = port;
zconf.source_port_last = port;
}
int num_source_ports = (zconf.source_port_last - zconf.source_port_first) + 1;
if (zconf.packet_streams > num_source_ports) {
log_fatal("zmap", "The number of probes sent to each target ip/port (%i) "
"must be smaller than the size of the source port range (%u-%u, size: %i). "
"Otherwise, some generated probe packets will be identical.", zconf.packet_streams,
zconf.source_port_first, zconf.source_port_last,
(zconf.source_port_last - zconf.source_port_first) + 1);
} else if (((float)zconf.packet_streams / (float)num_source_ports) < 0.1) {
log_warn("zmap", "ZMap is configured to use a relatively small number"
" of source ports (fewer than 10x the number of probe packets per target ip/port),"
" which limits the entropy that ZMap has available for "
" validating responses. We recommend that you use a larger port range.");
}
}
if (!args.target_ports_given) {
log_fatal("zmap",
Expand Down

0 comments on commit 86809e3

Please sign in to comment.