Lecture Overview

In this lecture, we will take a look at TCP session hijacking attacks. One challenging part when we launch this attack is figuring out the TCP sequence numbers. So we will cover this topic too.

Telnet Session Hijacking

Telnet is not secure

How the attack works

Consider the following scenario:
  1. Alice logs in the server using the Telnet service.

  2. Now, what will happen if an attacker does the following?

  3. If this is successful, the attacker can freely use Alice's account. This session has been hijacked!

In the Lab

In the lab, you will perform this session hijacking attack. How hard should it be to send a fake TCP packet?

How TCP Sequence and Acknowledgement Numbers Work

To see how these numbers work, we will create a simple packet sniffer using Scapy. This allows us to see the necessary information nicely without being overwhelmed by huge information from Wireshark.

The pieces of information that we want to see is

Packet sniffing code

Read the code (and comments) carefully and understand what the code does. You will need to do something similar in the lab.

#!/usr/bin/python3
# sniff.py

from scapy.all import *

def show_pkt(pkt):
  # if port number is not irrelevant, ignore pkt
  if 9000 not in (pkt[TCP].sport, pkt[TCP].dport):
    return

  # print src/dst IP/port
  print("\n"+pkt[IP].src + "(" + str(pkt[TCP].sport) + ") -> " +
    pkt[IP].dst + "(" + str(pkt[TCP].dport) + "):", end = "")

  # print flags (SYN/ACK/FIN) and seq/ack 
  print(pkt[TCP].flags, " seq=", pkt[TCP].seq, ", ack=", pkt[TCP].ack)

  # print the payload (Raw means data payload)
  if Raw in pkt:
      print(pkt[Raw])

sniff(filter="tcp", prn=show_pkt)

Netcat chats

From 192.168.172.4:
choi@it432a:~/Desktop$ nc -lnv 9000
Listening on 0.0.0.0 9000
Connection received on 192.168.172.6 49178
from c to a
from a to c
From 192.168.172.6:
choi@it432c:~/Desktop$ nc 192.168.172.4 9000
from c to a
from a to c

Sniffing data

choi@it432a:~/Desktop$ sudo ./sniff.py
192.168.172.6(49178) -> 192.168.172.4(9000):S  seq= 3463125348 , ack= 0

192.168.172.4(9000) -> 192.168.172.6(49178):SA  seq= 557292906 , ack= 3463125349

192.168.172.6(49178) -> 192.168.172.4(9000):A  seq= 3463125349 , ack= 557292907

192.168.172.6(49178) -> 192.168.172.4(9000):PA  seq= 3463125349 , ack= 557292907
b'from c to a\n'

192.168.172.4(9000) -> 192.168.172.6(49178):A  seq= 557292907 , ack= 3463125361

192.168.172.4(9000) -> 192.168.172.6(49178):PA  seq= 557292907 , ack= 3463125361
b'from a to c\n'

192.168.172.6(49178) -> 192.168.172.4(9000):A  seq= 3463125361 , ack= 557292919

Notes about how seq/ack numbers work

Quick check

Can you figure out what the numbers should be in the blanks? (You will see the answer by dragging the mouse over the blanks).