cybersecurity · intermediate · ~12 min · safe pentest lab
Recognise scan signatures from a single bitfield.
#include <stdint.h>
#include <stddef.h>
int tcp_scan_type(const uint8_t *tcphdr, size_t n);
The TCP flags live in byte 13 (low 6 bits: FIN=0x01, SYN=0x02, RST=0x04, PSH=0x08, ACK=0x10, URG=0x20). Return:
1 SYN scan (SYN only, 0x02)2 NULL scan (no flags, 0x00)3 FIN scan (FIN only, 0x01)4 XMAS scan (FIN+PSH+URG, 0x29)0 anything else (e.g. a normal SYN-ACK)-1 NULL input or n < 140x3F to drop the reserved bits.SYN / NULL / FIN / XMAS scans each leave a tell-tale flag combination. Recognising them is how a detector classifies probe traffic.
#include <stdint.h>
#include <stddef.h>
int tcp_scan_type(const uint8_t *tcphdr, size_t n) {
/* TODO */
(void)tcphdr; (void)n;
return -1;
}
Not masking reserved bits. Treating SYN-ACK as a SYN scan.
NULL scan is genuinely zero flags. Short header.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.