Skip to content

Commit a26de28

Browse files
committed
poc
1 parent f52ab7b commit a26de28

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/scan.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int scan_main(const char *interface, int quiet)
129129
int fflags = RAWSOCK_FILTER_IPTYPE | RAWSOCK_FILTER_DSTADDR;
130130
if(source_port != -1 && ip_type != IP_TYPE_ICMPV6)
131131
fflags |= RAWSOCK_FILTER_DSTPORT;
132-
if(ip_type == IP_TYPE_UDP)
132+
if(1)
133133
fflags |= RAWSOCK_FILTER_RELATED_ICMP; // to detect closed ports
134134
if(rawsock_setfilter(fflags, ip_type, source_addr, source_port) < 0)
135135
goto err;
@@ -552,24 +552,31 @@ static void handle_icmp_error(uint64_t ts, u_int len, const uint8_t *packet, con
552552
// via rawsock_setfilter(), so we know that this is not a stray ICMP error
553553
// unrelated to the scan.
554554

555+
bool closed = true;
555556
if(ICMP_HEADER(packet)->type != 1) // Destination unreachable
556-
return;
557+
closed = false;
557558

558559
// Interpreting an ICMP error can be complex but we apply this rule of thumb:
559560
// If the error sender is the IP we scanned, then it's not a router sending
560561
// a generic error but the port is actually closed.
561562
const uint8_t *inner_dstaddr;
562563
rawsock_ip_decode(INNER_IP_FRAME(packet), NULL, NULL, NULL, NULL, &inner_dstaddr);
563564
if(memcmp(csrcaddr, inner_dstaddr, 16) != 0)
564-
return;
565+
closed = false;
565566

566-
if(outdef.raw || show_closed) {
567+
if(closed && (outdef.raw || show_closed)) {
567568
int v;
568569
// (read the *dest* port, since the packet is a copy of what we sent)
569570
udp_decode(INNER_UDP_HEADER(packet), NULL, &v);
570571
int v2;
571572
rawsock_ip_decode(IP_FRAME(packet), NULL, NULL, &v2, NULL, NULL);
572573
outdef.output_status(outfile, ts, csrcaddr, OUTPUT_PROTO_UDP, v, v2, OUTPUT_STATUS_CLOSED);
574+
} else {
575+
char buf[128], tmp[IPV6_STRING_MAX];
576+
ipv6_string(tmp, inner_dstaddr);
577+
snprintf(buf, sizeof(buf), "%d %d for %s",
578+
ICMP_HEADER(packet)->type, ICMP_HEADER(packet)->code, tmp);
579+
outdef.output_banner(outfile, ts, csrcaddr, OUTPUT_PROTO_ICMP, 1, buf, strlen(buf));
573580
}
574581

575582
return;

0 commit comments

Comments
 (0)