packet capture and protocol analysis 1. content tcp/ip networking review packet capture protocol...

56
Packet capture and protocol analysis 1

Upload: kristina-watts

Post on 26-Dec-2015

242 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

1

Packet capture and protocol analysis

Page 2: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

2

Content

• TCP/IP Networking Review• Packet Capture • Protocol Analysis

Page 3: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

3

Page 4: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

4

Communications Architecture

• The complexity of the communication task is reduced by using multiple protocol layers:

• Each protocol is implemented independently• Each protocol is responsible for a specific subtask• Protocols are grouped in a hierarchy

• A structured set of protocols is called a communications architecture or protocol suite

Page 5: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

5

Page 6: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

6

TCP/IP Protocol Suite

• The TCP/IP protocol suite is the protocol architecture of the Internet

• The TCP/IP suite has four layers: Application, Transport, Network, and Data Link Layer

• End systems (hosts) implement all four layers. Gateways (Routers) only have the bottom two layers.

Application

Transport

Network Operating system

User-level programs

Data Link

Data Link

Media AccessControl (MAC)

Sublayer inLocal AreaNetworks

Page 7: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

7

HTTP

TCP

IP

Client128.143.137.144

Ethernet Ethernet Ethernet

IP

HTTP

TCP

IP

Server128.143.71.21

00:20:af:03:98:28

Ethernet

RouterInterface 1

128.143.137.100:e0:f9:23:a8:20

RouterInterface 2

128.143.71.1

Send HTTP Request to Server

Establish a connection to 128.143.71.21 at port 80Open TCP connection to

128.143.71.21 port 80

Send a datagram (which contains a connection request) to 128.143.71.21Send IP datagram to

128.143.71.21

Send the datagram to 128.143.137.1

Send Ethernet frame to 00:e0:f9:23:a8:20

Send Ethernet frame to 00:20:af:03:98:28

Send IP data-gram to 128.143.71.21

Send the datagram to 128.143.7.21

Frame is an IP datagram

Frame is an IP datagram

IP datagram is a TCP segment for port 80

HTTP service listening at port 80

Page 8: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

8

Layers and Services

• Service provided by TCP to HTTP:– reliable transmission of data over a logical connection

• Service provided by IP to TCP:– unreliable transmission of IP packets across an IP

network• Service provided by Ethernet to IP:

– transmission of a frame across an Ethernet segment• Other services:

– DNS: translation between domain names and IP addresses– ARP: Translation between IP addresses and MAC addresses

Page 9: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

9

Encapsulation and Demultiplexing• As data is moving down the protocol stack, each

protocol is adding layer-specific control information

HTTP

TCP

IP

Ethernet

User data

User dataHTTP Header

TCP Header

TCP HeaderIP Header

TCP HeaderIP HeaderEthernetHeader

EthernetTrailer

IP datagram

TCP segment

Ethernet frame

User dataHTTP Header

User dataHTTP Header

User dataHTTP Header

Page 10: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

10

Encapsulation and Demultiplexing

Application dataTCP HeaderIP HeaderEthernet Header Ethernet Trailer

Ethernet frame

destination address

source address

type

6 bytes

CRC

4 bytes

Page 11: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

11

Encapsulation and Demultiplexing: IP Header

Application dataTCP HeaderEthernet Header Ethernet Trailer

Ethernet frame

IP Header

DS ECNversion(4 bits)

headerlength

Total Length (in bytes)(16 bits)

Identification (16 bits)flags

(3 bits)Fragment Offset (13 bits)

Source IP address (32 bits)

Destination IP address (32 bits)

TTL Time-to-Live(8 bits)

Protocol(8 bits)

Header Checksum (16 bits)

32 bits

Page 12: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

12

Encapsulation and Demultiplexing: TCP Header

Application dataEthernet Header Ethernet Trailer

Ethernet frame

IP Header TCP Header

Sequence number (32 bits)

Source Port Number Destination Port Number

Acknowledgement number (32 bits)

window sizeheaderlength

0 Flags

TCP checksum urgent pointer

32 bits

length Max. segment sizeoptiontype Option:

maximum segment size

Page 13: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

13

Content

• TCP/IP Networking Review• Packet Capture • Protocol Analysis

Page 14: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

14

Packet capture/Sniffering

• Why do we need to capture packets?– troubleshoot network problems– examine security problems– debug protocol implementations– learn network protocol internals

Page 15: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

15

Packet capture tools/Sniffers

• Classic tools– WireShark (http://www.wireshark.org/)– TCPDump (http://www.tcpdump.org/)

• Other tools– Ettercap– Dsniff– Ntop– KISMET– WinDump– Tshark– …

Page 16: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

16

What is Wireshark?

• An open source packet analyzer • Decodes 1115 protocols (V1.4)• Supports command-line and GUI interfaces • Run on many platforms including Windows,

OS X, Linux, and UNIX• Many online resources• Wireshark User's Guide

(http://www.wireshark.org/download/docs/user-guide-a4.pdf)

Page 17: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

Wireshark

Wireshark

libpcapWinpcap

WindowsLinux

Page 18: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

18

Wireshark

• Y:\Win32\WiresharkPortable • Select interface• tcp• visit www.polyu.edu.hk• HTTP traffic

Page 19: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

19

TCPDump/WinDump/Tshark

• Tcpdump– Unix-based command-line tool used to analyze packets

• Including filtering to just capture the packets of interest– Capture packets from interface specified using -i option– Read packets from an existing trace file specified using -r

option– Save captured packets using -w option

• WinDump– The Windows version of tcpdump

• Tshark– Tcpdump-like capture program that comes with Wireshark– Very similar behavior & flags to tcpdump

Page 20: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

20

Commonly Used Tcpdump Options

• -n Don’t convert host addresses to names. Avoids DNS lookups. It can save you time.

• -w <filename> Write the raw packets to the specified file instead of parsing and printing them out. Useful for saving a packet capture session and running multiple filters against it later

• -r <filename> Read packets from the specified file instead of live capture. The file should have been created with –w option

• -q Quiet output. Prints less information per output line

Page 21: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

21

Commonly Used Options

• -s 0 tcpdump usually does not analyze and store the entire packet. This option ensures that the entire packet is stored and analyzed. NOTE: You must use this option while generating the traces for your assignments. (Default in tshark)

• -A (or –X in some versions) Print each packet in ASCII. Useful when capturing web pages. NOTE: The contents of the packet before the payload (for example, IP and TCP headers) often contain unprintable ASCII characters which will cause the initial part of each packet to look like rubbish

Page 22: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

22

Writing Filters

• Specifying ICMP packets– “icmp”

• Specifying UDP packets– “udp”

• Specifying TCP packets– “tcp”

Page 23: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

23

Writing Filters

• Combining filters– and (&&)– or (||)– not (!)

• Example:– All tcp packets which are from or to host

www.polyu.edu.hktcpdump “tcp and host www.polyu.edu.hk”

– Lots of examples in the EXAMPLES section of the man page• http://www.tcpdump.org/tcpdump_man.html

Page 24: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

24

WinDump

• y:\win32\windump• ping www.polyu.edu.hk

– Pinging www.polyu.edu.hk [158.132.19.132] with 32 bytes of data

• windump -D – Show the interface name and index

• windump -i 1 -n host 158.132.19.132 and tcp• 15:37:55.364847 IP 158.132.19.132.80 >

158.132.34.174.52085: P 77836:78946(1110) ack 17049 win 10103

Page 25: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

25

Content

• TCP/IP Networking Review• Packet Capture • Protocol Analysis

Page 26: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

26

ARP and RARP• Note:

– The Internet is based on IP addresses – Data link protocols (Ethernet, FDDI, ATM) may have different

(MAC) addresses

• The ARP and RARP protocols perform the translation between IP addresses and MAC layer addresses

• http://www.networksorcery.com/enp/protocol/arp.htm

RARP

Ethernet MACaddress(48 bit)

ARPIP address(32 bit)

Page 27: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

27

ARP Packet Format

Destinationaddress

6

ARP Request or ARP Reply

28

Sourceaddress

6 2

CRC

4

Type0x8060

Padding

10

Ethernet II header

Hardware type (2 bytes)

Hardware address length (1 byte)

Protocol address length (1 byte)

Operation code (2 bytes)

Target MAC address*

Protocol type (2 bytes)

Source MAC address*

Source protocol address*

Target protocol address*

* Note: The length of the address fields is determined by the corresponding address length fields

Page 28: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

ARP Request Message• Source contains initiating system’s MAC address and IP

address• Destination contains broadcast MAC address ff.ff.ff.ff.ff.ff

Page 29: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

ARP Reply Message• Source contains replying system’s MAC address and IP address• Destination contains requestor’s MAC address and IP address

Page 30: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

Domain names and IP addresses

• People prefer to use easy-to-remember names instead of IP addresses

• Domain names are alphanumeric names for IP addresses e.g., www.polyu.edu.hk, www.google.com, ietf.org

• The domain name system (DNS) is an Internet-wide distributed database that translates between domain names and IP addresses

Page 31: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

Domain name resolution1. User program issues a request for

the IP address of a hostname2. Local resolver formulates a DNS

query to the name server of the host3. Name server checks if it is

authorized to answer the query. a) If yes, it responds. b) Otherwise, it will query other

name servers, starting at the root tree

4. When the name server has the answer it sends it to the resolver.

HTTP Resolver

Hostname (www.polyu.edu.hk)

IP address (158.132.19.132)

Name server

Hostnam

e (w

ww

.polyu.edu.hk)

IP address (158.132.19.132)

Page 32: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

32

DNS packet format

• Identification used to match request/reply packets; QR, Query/Response; Opcode: QUERY, Standard query.

• AA, Authoritative Answer; TC, Truncated; RD, Recursion Desired;RA, Recursion Available; Z, reserved bits

• AD, Authenticated data• CD, Checking Disabled; Rcode, Return code

Page 33: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

33

DNS Query

Page 34: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

34

DNS Response

Page 35: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

35

TCPTCP = Transmission Control Protocol• Connection-oriented protocol• Provides a reliable unicast end-to-end byte stream

over an unreliable internetwork.

TCP

IP Internetwork

Byt

e S

tream

Byt

e S

tream

TCP

Page 36: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

36

Connection-Oriented• Before any data transfer, TCP establishes a

connection:• One TCP entity is waiting for a connection (“server”)• The other TCP entity (“client”) contacts the server

• Each connection is full duplexCLIENT SERVER

waiting forconnection

request

Request a connection

Accept a connection

DisconnectData Transer

Page 37: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

37

Reliable

• Byte stream is broken up into chunks which are called segments

• Receiver sends acknowledgements (ACKs) for segments

• TCP maintains a timer. If an ACK is not received in time, the segment is retransmitted

• Detecting errors:• TCP has checksums for header and data. Segments

with invalid checksums are discarded

• Each byte that is transmitted has a sequence number

Page 38: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

38

TCP Format

IP header TCP header TCP data

Sequence number (32 bits)

DATA

20 bytes 20 bytes

0 15 16 31

Source Port Number Destination Port Number

Acknowledgement number (32 bits)

window sizeheaderlength

0 Flags

Options (if any)

TCP checksum urgent pointer

20 bytes

TCP segments have a 20 byte header with >= 0 bytes of data.

Page 39: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

39

Three-Way Handshake

Client Server

SYN (SeqNo = x)

SYN (SeqNo = y, AckNo = x + 1 )

(SeqNo = x+1, AckNo = y + 1 )

Page 40: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

40

TCP SYN

Page 41: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

41

TCP SYN/ACK

Page 42: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

42

TCP ACK

Page 43: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

43

HTTP

Hypertext Transfer Protocol is a network protocol used to deliver virtually all files and other data (collectively called resources) on the World Wide Web. This is a request and retrieve function of the server.

This includes: Text files, graphic images, sound, video, and other multi-media files.

Page 44: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

44

HTTP Request Methods

There are 3 open-ended methods that are frequently used to request information:

• GET – used to ask for specific document and is the simplest form of requesting information (URL access will not change the state of database)

• HEAD – used to ask for information about a document (very fast because less data is required)

• POST – used when the service associated with the processing of the form has side effects (URL access will cause change in database). Example: Ebay, Amazon

Page 45: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

45

HTTP Request

Page 46: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

46

HTTP Response

Page 47: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

47

Exercise: ARP

• ipconfig /all ; see local IP and gateway• route -print ; find gateway• arp -a ; list all MAC addresses learned• arp -d * ; delete all MAC address learned• ping www.polyu.edu.hk• What is the MAC address of the router/default

gateway?

Page 48: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

48

Hints

• If the default gateway/router’s MAC address is not in the cache, the host will send ARP to ask for it.

• The default gateway’s IP address is pre-configured or learnt through the DHCP protocol.

Page 49: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

49

Exercise: ICMP

• ping www.polyu.edu.hk– http://www.networksorcery.com/enp/protocol/icmp.h

tm– What is the value of ‘Type’ in the outgoing ICMP

packet?– What is the value of ‘Type’ in the incoming ICMP

packet?– Take a look at the data section in the incoming ICMP

packet.• tracert www.polyu.edu.hk

– What are the answers to the above two questions?

Page 50: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

50

Hints

• Ping– Send: ICMP Echo Request– Receive: ICMP Echo Reply

• Traceroute– Send: And kind of IP packet with special TTL

• It would be an ICMP packet if we need the reply from the destination

– Receive: ICMP Time Exceeded

Page 51: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

51

Exercise: DNS

• nslookup• www.polyu.edu.hk• Take a look at DNS query and response packets• nslookup• set type=PTR• 158.132.19.132• Take a look at DNS query and response packets

Page 52: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

52

Hints

• set type=A (default setting)– Normal DNS lookup: get the IP address from a

host name• set type=PTR

– Reverse DNS lookup: get the host name from its IP address

Page 53: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

53

Exercise: HTTP/TCP

• Use browser to visit www.polyu.edu.hk• Take a look at

– TCP’s three-way handshake– sequence numbers in packets from the server and

the acknowledgement number in packets from the client

– HTTP header in the packet from the client– HTTP header in the packets from the server

Page 54: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

54

Exercise: Trace analysis

• Real trace from a VoIP hacking demo– https://honeynet.org/files/Forensic_challenge_4_0.pcap

• Analyze the trace using Wireshark and answer the following questions– Which 4 protocols are involved in the pcap? – Which codec does the RTP stream use?– How did the attacker gain access to the server?– Where is the hacked server?

• Tips: look into the payload

Page 55: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

55

Hints

• 4 Protocols: HTTP, RTP, RTCP, SIP• RTP uses G.7111 PCMU coding • Default user name/password

– Authorization: Basic bWFpbnQ6cGFzc3dvcmQ=• The city is DISTRITO FEDERAL MEXICO

– Hear it• Telephony -> RTP -> Stream analysis

– Public IP: 132.248.255.82 in an HTTP response• Follow HTTP connections• Look into the HTTP responses• Use Geolocation websites to locate the city

Page 56: Packet capture and protocol analysis 1. Content TCP/IP Networking Review Packet Capture Protocol Analysis 2

56

Reference*• http://www.cs.virginia.edu/~cs458/• http://www.eecs.berkeley.edu/~jortiz/courses/ee122/presentations/

Wireshark.ppt• http://www.cis.udel.edu/~amer/856/wireshark.08f.ppt• http://www.blackhat.com/presentations/bh-usa-01/MikeBeekey/bh-usa-

01-Mike-Beekey.ppt• http://classes.bus.oregonstate.edu/winter-06/ba471/marshall/Special-

Topics/http.ppt• http://www.wildpackets.com/elements/misc/WP_encapsulation_chart.pdf• http://sectools.org/sniffers.html• Computer Networking: A Top-down Approach Featuring the Internet• https://honeynet.org/challenges/2010_4_voip_traditional_cn• * Some slides were taken from the above sources and the pcap file was

from Forensic Challenge 2010 - VoIP