Skip to content
Mrityunjay Kumar
All projects

02 · Case study · MIT licensed

PortForge

A port scanner built from raw packets up.

The problem

Production scanners are powerful but opaque — it's easy to run a SYN scan without understanding what actually goes on the wire. PortForge reimplements the core of network reconnaissance in a single readable Python file, constructing its own IP and TCP headers, so every technique can be inspected, modified and learned from — and run anywhere without installing a toolchain.

FIN, PSH and URG lit up together — the packet is “lit like a tree”.

Flags byte0010 10010x29

TCP header, illustrative

0000d4310050000003e8
000800000000502916d0
0010····0000

Flags at offset 13, highlighted; window 5840 as PortForge sets it; checksum computed per packet.

portforgetarget

$ sudo python3 portforge.py <target> -sX

How it works

  1. 01

    A raw-socket scanner that hand-builds IPv4 and TCP headers (flags, window, checksums) for SYN, ACK and flag-based (NULL, FIN, XMAS) scans, and interprets SYN-ACK / RST responses.

  2. 02

    ICMP host discovery with a TCP connect fallback; -Pn skips discovery.

  3. 03

    TTL-based OS guess from the ICMP reply (Linux/Unix, Windows, network device).

  4. 04

    Banner grabbing with protocol-specific probes (HTTP, SSH, FTP, SMTP, MySQL, Redis, MongoDB) and regex version detection for services such as OpenSSH, Apache, nginx, IIS, vsftpd, ProFTPD, Postfix, Exim, MySQL and MariaDB.

  5. 05

    --script runs signature checks against banners, e.g. flagging vsFTPd 2.3.4 (CVE-2011-2523) or unauthenticated Redis.

  6. 06

    Concurrent scanning with ThreadPoolExecutor, timing profiles T0–T5, adjustable threads, delay and port-order randomisation.

Usage

SYN scan, ports 1–1000
$ sudo python3 portforge.py 192.168.1.1 -sS -p 1-1000
Service checks + JSON
$ python3 portforge.py 192.168.1.1 --script -o results.json
Next case fileLLMSec