cybersecurity · intermediate · ~15 min · safe pentest lab

Read a banner from a local service

Combine a sockets exercise with the local-only safety pattern.

Challenge

Implement int read_local_banner(int port, char *out, size_t out_sz) that opens a TCP connection to 127.0.0.1:port, reads up to out_sz - 1 bytes, NUL-terminates, and closes. Return 0 on success, -1 on failure.

The harness spawns a tiny banner-emitting server in a thread for you to read.

Starter code

#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stddef.h>

int read_local_banner(int port, char *out, size_t out_sz) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.