Cyberlium

Ethical › Module 13 › Lesson 4

BeginnerModule 13Lesson 4/5

Lab — Harden a Local Static Server

python http.server notes: bind localhost, no directory listing homework on strangers.

25 min+40 XP4 quiz
Module progress4 of 5

Visual · harden_local_static_server

HOST hardcoded 127.0.0.1. Throwaway folder, index.html, listing disabled on YOUR handler. Notes ceh-webserver-lab.txt chmod 600. Stop the server. Never directory-brute strangers.

Opening

You hardcode loopback. You serve a throwaway folder. You refuse listing. You lock the notes. You stop the server. That is the whole web-server lab.

Lessons 1–3 named leftovers, the patch/modules/TLS/worker ticket, and logs as first responder — without a gobuster kit. This lab is the hands that match “audit a stack YOU run”: a short Python HTTP server bound to 127.0.0.1 that serves only a throwaway directory under cyberlium-lab, ships an index.html YOU wrote, and returns 403 instead of a file tree. You will write HOST = "127.0.0.1" hardcoded. You will refuse to run if HOST is anything else. You will fill $HOME/cyberlium-lab/ceh-webserver-lab.txt and chmod 600. Then you stop the server. You will not change HOST to argv, a café gateway, a classmate, a cloud IP, or “the internet for one GET.” You will not gobuster, dirb, or ffuf anyone. You will not start the clerk in $HOME. You will not bind 0.0.0.0 “so a friend can see my listing.” You will not leave the process running unattended. A tiny GET of YOUR index (and one GET of a directory path to see YOUR 403) is polite on purpose — this is a hardening demo, not a hunt. This is original Cyberlium teaching mapped to the CEH v13 web-servers domain — not official EC-Council training, not a cert, not exam dumps. Next is Quiz — Web Servers, then Module 14 talks the app as the attack surface (input, auth, session) — still no SQLi/XSS exploit pack; deep app bugs live in Topic 10.

1. Lab surface: HOST frozen, throwaway root, bind loopback, then stop

HOST must be the characters 127.0.0.1 inside the server file — not a variable you read from the command line, not a pasted LAN address, not “I will add a SAFETY flag later.” A flag you forget is how yesterday’s localhost clerk becomes today’s café listing. Print HOST on the first output line so the artifact is self-explaining. If HOST != "127.0.0.1", raise SystemExit. Bind 127.0.0.1 only (not 0.0.0.0). Pick a high port you own on this box (8000 in the template). Do not run as root. Do not serve $HOME, Documents, or a folder with secrets. Create $HOME/cyberlium-lab/webserver-root as the only tree. When notes are filled, Ctrl+C the server. Loopback binding is the control; stopping is the lockdown.

The client side of this lab is one or two GETs from the same machine: / should return 200 and your index; a directory path without an index should return 403 because YOU disabled listing. It is not a wordlist. It has no extra host. If 8000 is busy, pick another high port on loopback and write that port in the notes — still 127.0.0.1. Connection refused means start YOUR server first, still without aiming elsewhere. Seeing 200 plus 403 on loopback is the intended demo of a clerk YOU hardened.

2. The clerk YOU wrote: index present, listing off, secrets not in the tree

SimpleHTTPRequestHandler on loopback is enough. Override list_directory so a folder request sends 403 and a tiny body instead of an HTML tree. Put index.html in the root so GET / is a page you authored, not a leftover vendor splash (Lesson 1). Do not copy SSH keys, mail, or password-manager exports into webserver-root. That is the whole policy. You are the server author saying no to listing — the same disable Lesson 1 named. You are not writing gobuster. You are not copying a web shell. You are not enabling CGI. If Python’s http.server feels small, that is the point: the skill is the HOST lock, the throwaway root, the 403, and the stop — not a framework.

Windows users: py harden_webserver.py in one PowerShell, then Invoke-WebRequest or py -c against 127.0.0.1 only in another. WSL and Git Bash can use the bash block as written. Record which OS you used. Do not point http.server at someone else’s files. Do not bind 0.0.0.0 “so the café can help.” Their hit from shared Wi-Fi is traffic at you and it trains the wrong muscle. Loopback only. Stop the server when notes are filled.

3. The artifact: ceh-webserver-lab.txt mode 600 — YOUR 403, not a stranger’s tree

Required rows: legal line (original Cyberlium teaching mapped to the CEH v13 web-servers domain — not official EC-Council training, not a cert, not exam dumps); HOST = 127.0.0.1; bind 127.0.0.1; port; document root = cyberlium-lab/webserver-root; index.html present; listing disabled (403); Server token you actually saw; one access-style line you copied; lockdown Ctrl+C; ethics (no café, classmate, gobuster, dirb, ffuf, other IPs, no directory-listing homework on strangers); chmod reminder. Notes that list other people’s URLs fail ethics even if Python ran. World-writable 777 fails. If the server refused because you edited HOST, that refusal is a passing ethics check — put HOST back to 127.0.0.1 and rerun.

Failure modes that still pass if you tell the truth: forgot to start the server, connection refused, you start it and retry on loopback. Port in use — choose 8001 still on 127.0.0.1. Failure modes that fail the course: success against 10.x campus, HOST rewritten, listing homework on a classmate, notes chmod 644 on a shared PC, gobuster because 403 on loopback looked “too small.”

Command guide

Index on, listing off, no secrets — WHAT/WHY

═══ COMMANDS ═══

Command — copy this

test -f "$HOME/cyberlium-lab/harden-www/index.html" && echo "index present"
test ! -f "$HOME/cyberlium-lab/harden-www/secret.txt" && echo "no secret.txt in web root (good)"

4. Wrong vs right: gobuster-the-LAN vs hardcoded 127.0.0.1 plus a clerk YOU stop

Worked failure — same word “directory listing,” opposite target. Right never needs a second host when loopback can answer 200 and 403.

  • Wrong

    HOST = café, campus, classmate, cloud, or sys.argv. Bind 0.0.0.0. Serve $HOME. Gobuster/dirb/ffuf anyone. Leave the server running. Skip chmod. Call the lab incomplete without a stranger’s file tree. This course is not official CEH training and does not grade that hunt.

  • Right

    HOST hardcoded "127.0.0.1"; refuse otherwise. Bind loopback. Throwaway root, index.html, listing 403. Fill ceh-webserver-lab.txt, chmod 600 under $HOME/cyberlium-lab. Ctrl+C the server. Next: Quiz — Web Servers.

5. Hands-on: throwaway root, loopback clerk, notes, chmod 600, stop

Follow the block. Terminal A: server. Terminal B: GETs to 127.0.0.1 only. Do not leave the server running unattended. When notes are filled, Ctrl+C. Windows notes sit at the bottom of the script comments.

6. Ethics line: localhost python http.server — never directory brute of strangers

Authorized lab only: YOUR process, YOUR folder, YOUR notes. Do not attack random hosts. Do not treat this file as permission to scan a shop’s hidden paths. Do not title it “Official CEH v13 web-server pwn.” If you already pointed a wordlist at a classmate, this lab does not launder that. Stop. Delete campaign drafts. This file is forward-looking hardening, not an indulgence.

Command guide

YOUR 403/lock artifact — WHAT/WHY then lock

═══ INSTALL ═══

Linux (Debian/Ubuntu):

Command — copy this

sudo apt install curl

macOS: Built-in

Windows: Built-in (PowerShell: Invoke-WebRequest)

═══ COMMANDS ═══

Command — copy this

curl -sS -m 2 -o /dev/null -w "status=%{http_code}
" "http://127.0.0.1:8000/"
cat > "$NOTES" << 'EOF'
HOST: 127.0.0.1
INDEX: present
SECRET_IN_TREE: N
STOPPED: (Y)
ETHICS: not a stranger tree
EOF

Mission: ceh-webserver-lab.txt — hardcoded 127.0.0.1 clerk, chmod 600, stop

1) Save harden_webserver.py with HOST = "127.0.0.1" hardcoded, throwaway root, index.html, listing 403, refuse if HOST is anything else. Bind loopback. 2) Start the server, GET YOUR index and a directory path on 127.0.0.1 only, fill $HOME/cyberlium-lab/ceh-webserver-lab.txt, chmod 600, Ctrl+C the server. 3) Ethics: never directory-brute strangers. No café, classmate, gobuster, dirb, or ffuf. Original Cyberlium teaching, not official CEH training, not a cert.

Stuck? Ask Cyberlium AI Mentor

If “the lab is incomplete without a real site’s file tree” still feels true, ask for a hint — not a target. Try: "Hint only: why HOST must stay hardcoded 127.0.0.1, how MY handler returns 403 instead of listing, why index.html belongs in a throwaway root, and why gobuster/café/classmate fail ethics?" You still fill ceh-webserver-lab.txt and stop the server. No argv HOST. No other IP.

You ran a real web-server hygiene demo without leaving loopback: hardcoded 127.0.0.1, a throwaway root, listing off, locked notes, server stopped. That is authorized server practice as Cyberlium teaches it — original, not an exam dump, not EC-Council lab text, not a cert. Next — Quiz — Web Servers — ten APPLY items on leftovers, patch/modules/TLS/worker, logs on YOUR clerk, the HOST lock, and legal scope. Then Module 14: The App Is the Attack Surface — input, auth, session as a map, still no exploit pack.

Knowledge Check

1

APPLY: You started nothing and the client reports connection refused. 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 python -m http.server on 0.0.0.0 plus gobuster against campus.

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)