Cyberlium

Ethical › Module 3 › Lesson 4

BeginnerModule 3Lesson 4/5

Lab — Scan 127.0.0.1 Only

Hardcoded loopback scan of a tiny port list; optional local http.server.

25 min+40 XP4 quiz
Module progress4 of 5

Visual · localhost_scan_lab

HOST hardcoded 127.0.0.1. Tiny ports 22, 80, 443, 8000. Optional http.server on loopback:8000. Notes chmod 600. Never nmap café, campus, or the internet.

Opening

You hardcode loopback. You scan a tiny list. You may start a door you own. You lock the notes. That is the whole scan lab.

Lessons 1–3 named why scans exist, connect versus a half-open idea (without an evasion cookbook), and how to read OPEN versus closed_or_filtered without hunting the LAN. This lab is the hands that match those words. You will copy a short Python script that hardcodes HOST = "127.0.0.1", walks ports 22, 80, 443, and 8000, uses a sub-second timeout, and records OPEN versus closed_or_filtered. You will write the same rows into $HOME/cyberlium-lab/ceh-scan.txt (localhost-scan-lab-notes.txt is an acceptable same-content name if you already used it in Topic 7). chmod 600. Optional: in a second terminal, start python -m http.server bound to , scan again so 8000 is OPEN, then stop the server and recheck closed. You will not change HOST to argv, a café gateway, campus, a neighbor, or a cloud IP. You will not nmap the internet. You will not expand PORTS to 1–65535 for a screenshot. Empty OPEN before the optional server is a valid first run. This is original Cyberlium teaching mapped to a CEH v13 scanning domain — not official EC-Council training, not a cert, not exam dumps. Next is Quiz — Network Scanning, then Module 4 enumeration still on a listener YOU started.

1. Lab surface: HOST string frozen, four doors, short timeout

HOST must be the characters 127.0.0.1 inside the file — not a variable you read from the command line, not a pasted LAN address, not “I’ll add a SAFETY flag later.” A flag you forget is how yesterday’s localhost tool becomes today’s café scan. Print HOST on the first output line so the artifact is self-explaining. PORTS stay [22, 80, 443, 8000]. Timeout 0.5 seconds is plenty on loopback. A hang means you dropped settimeout; fix the script. Do not run as root to “see more.” Connecting to high ports on loopback does not need uid 0.

Each port is one question you already practiced: connect_ex((127.0.0.1, port)). 0 means OPEN from here — a process on this OS accepted TCP. Nonzero means closed_or_filtered in the wait window. Port 22 is often closed unless you installed SSH on this box. 80 and 443 closed unless you run a local web server. 8000 closed until you start Python’s http.server — that is the intended optional OPEN. Closed-only on the first pass is a complete scan, not a broken lab.

Command guide

Lab surface frozen — WHAT/WHY (HOST + four doors)

═══ INSTALL ═══

Linux (Debian/Ubuntu):

Command — copy this

sudo apt install nmap
sudo apt install python3

macOS:

Command — copy this

brew install nmap
brew install python3

Windows:

Command — copy this

choco install nmap  # or download https://nmap.org/download.html

Download https://python.org/downloads/

═══ LINUX / macOS ═══

Port scan localhost (safe — your own machine)

Command — copy this

nmap -sT 127.0.0.1 -p 22,80,443,8000,8080
nmap -sV 127.0.0.1 -p 1-1000

Optional command

Python socket scanner (educational)

Command — copy this

python3 -c "
import socket
for port in [22, 80, 443, 8000, 8080]:
    s = socket.socket()
    s.settimeout(0.5)
    r = s.connect_ex(('127.0.0.1', port))
    print(f'Port {port}: {"OPEN" if r == 0 else "CLOSED"}')
    s.close()
"

═══ WINDOWS ═══

Optional command

PowerShell

Command — copy this

1..1024 | ForEach-Object { $p=$_; try { $c=New-Object Net.Sockets.TcpClient; $c.Connect('127.0.0.1',$p); Write-Host "Port $p OPEN"; $c.Close() } catch {} }

Or use nmap (install from nmap.org)

Command — copy this

nmap -sT 127.0.0.1 -p 22,80,443,8000,8080

2. Optional OPEN you cause: http.server bound to 127.0.0.1:8000, then stop it

In a throwaway folder you created (not your whole home directory), Terminal A: python3 -m http.server 8000 --bind 127.0.0.1 (or python / py -m). Binding loopback keeps the café from accidentally becoming your student. Leave it running. Terminal B: run the scanner; confirm 8000 OPEN. Fill notes. Ctrl+C Terminal A. Scan again; 8000 should return closed_or_filtered. Timestamp both. If 8000 is busy, pick another high port you bind on loopback and write that port in the notes — still 127.0.0.1. If --bind is missing on ancient Python, keep the machine off untrusted networks and stop the server immediately after the scan.

Windows users: py -m http.server 8000 --bind 127.0.0.1 in PowerShell, then either the Python scanner or Test-NetConnection 127.0.0.1 -Port 8000. WSL and Git Bash can use the bash block as written. Record which OS and which client you used so the notes are reproducible on YOUR box. Do not point http.server at someone else’s files. Do not leave it on 0.0.0.0 overnight. Do not add directory brute lists or POST bodies. The lab is TCP connect inventory plus an optional door you started, not a web attack.

3. The artifact: ceh-scan.txt mode 600 — evidence, not a trophy of strangers

Required rows: legal line (original Cyberlium, not official CEH, not a cert, not dumps); HOST = 127.0.0.1; port list; timeout; each port’s state; optional server command; scan-while-running; scan-after-stop; ethics (no café, campus, neighbor, internet nmap); chmod reminder. Empty OPEN on pass one is allowed if you say so. Notes that list other people’s IPs fail ethics even if Python ran. World-writable 777 fails. If you already have Topic 7’s localhost-scan.txt, you may copy loopback rows in — still no LAN rows, still chmod 600 on ceh-scan.txt.

Failure modes that still pass if you tell the truth: forgot to start the server, 8000 closed, you start it and retry on loopback. Port 8000 in use by something else you own — identify YOUR process or choose 8001. Failure modes that fail the course: success against 10.x campus, nmap 192.168.1.0/24, HOST rewritten, notes chmod 644 on a shared PC, Metasploit because 8000 opened.

4. Wrong vs right: nmap of café/campus vs hardcoded 127.0.0.1 plus locked notes

Worked failure — same curiosity, opposite target. Right never needs a second host when loopback can answer or honestly stay closed.

  • Wrong

    HOST = café gateway, campus /24, neighbor, or sys.argv. nmap the internet because Python felt small. Leave http.server on 0.0.0.0. PORTS = range(1, 65536). Paste foreign IPs. Skip chmod. Call the lab incomplete without a stranger’s OPEN. This course is not official CEH training and does not grade that hunt.

  • Right

    HOST hardcoded "127.0.0.1", ports 22/80/443/8000, timeout 0.5, connect_ex. Optional: python -m http.server 8000 --bind 127.0.0.1, rescan, stop, recheck closed. Fill ceh-scan.txt (or localhost-scan-lab-notes.txt), chmod 600 under $HOME/cyberlium-lab. Next: Quiz — Network Scanning.

5. Hands-on: two terminals, scan, notes, chmod 600, stop, recheck

Follow the block. Do not merge “start server” and “scan” in a way that leaves the server running unattended on shared Wi-Fi. When notes are filled, Ctrl+C the server and rerun the closed check. Windows notes sit at the bottom of the script comments.

Mission: ceh-scan.txt — hardcoded 127.0.0.1 scan, chmod 600

1) Save localhost_scan_lab.py with HOST = "127.0.0.1" hardcoded, ports 22/80/443/8000, timeout 0.5, connect_ex. Run it. Closed-only is valid. 2) Optional: python -m http.server 8000 --bind 127.0.0.1, rescan, confirm 8000 OPEN, Ctrl+C, recheck closed. Fill $HOME/cyberlium-lab/ceh-scan.txt (or localhost-scan-lab-notes.txt). chmod 600. 3) Ethics: never nmap the internet, café, campus, or neighbor. Original Cyberlium teaching, not official CEH training, not a cert.

Stuck? Ask Cyberlium AI Mentor

If “the lab is incomplete without nmap of a /24” still feels true, ask for a hint — not a target range. Try: "Hint only: why HOST must stay hardcoded 127.0.0.1, how python -m http.server --bind 127.0.0.1:8000 creates one OPEN I caused, why notes need chmod 600, and why café/campus/internet nmap fail ethics?" You still fill ceh-scan.txt. No argv HOST. No Metasploit.

You ran a real connect scan without leaving loopback: hardcoded 127.0.0.1, four ports, timeout, optional local http.server, locked notes, server stopped. That is authorized scanning as Cyberlium teaches it — original, not an exam dump, not EC-Council lab text, not a cert. Next — Quiz — Network Scanning — ten APPLY items on the HOST lock, connect versus stealth without an evasion cookbook, OPEN versus closed, and why café and campus scans stay out. Then Module 4: enumeration vs scanning, still on a listener you started.

Knowledge Check

1

APPLY: You ran the lab script and 8000 is closed_or_filtered. What is the ethical completion, and what is not?

Multiple choice

Knowledge Check

2

APPLY: True or False: If loopback is boring, the ethical lab is nmap of campus and the internet because Module 3 is “scanning networks.”

True or False

Knowledge Check

3

APPLY: Which note file pairing matches this lab’s ethics and hygiene?

Multiple choice

Knowledge Check

4

APPLY: curl of http://192.168.0.1/ shows a home router login (TP-Link / Netgear / Huawei / "Router Admin"). Is that DEMO in scope as a hacking target?

Multiple choice

← Previous

Answer all 4 knowledge checks to continue. (0/4 answered)