SlideShare a Scribd company logo
PACKET SNIFFER PROGRAM
By,
Prof. Vilas Gaikwad
INTRODUCTION
 Without some form of countermeasures, your data isn't
safe on public networks.
 There are people out there who are capable of stealing
your data.
 The best defense is to know what you can lose, how it
can get lost and how to defend against it.
5/19/2015
2
PacketSnifferProgram
WHAT IS PACKET SNIFFING?
 Packet sniffing, or packet analysis, is the process of
capturing any data passed over the local network and
looking for any information that may be useful.
 Most of the time, system administrators use packet
sniffing to troubleshoot network problems (like finding
out why traffic is so slow in one part of the network) or
to detect intrusions and that is what this type of analysis
originally was designed for.
 packet sniffers are considered security tools instead of
network tools now.
5/19/2015
3
PacketSnifferProgram
HOW DOES IT WORK?
 First, packet sniffing is a passive technique.
 No one actually is attacking your computer and
investigating through all those files that you don't want
anyone to access.
 It's a lot like eavesdropping (overhear something).
 My computer is just listening in on the conversation
that your computer is having with the gateway.
 Typically, when people think of network traffic, they
think that it goes directly from their computers to the
router or switch and up to the gateway and then out to
the Internet, where it routes similarly until it gets to the
specified destination.
5/19/2015
4
PacketSnifferProgram
HOW DOES IT WORK? (CONT.)
 This is mostly true except for one fundamental detail.
 Your computer isn't directly sending the data
anywhere.
 It broadcasts the data in packets that have the
destination in the header.
 Every node on your network (or switch) receives the
packet, determines whether it is the intended recipient
and then either accepts the packet or ignores it.
5/19/2015
5
PacketSnifferProgram
HOW DOES IT WORK? (CONT.)
 For example, let's say you're loading the Web page
http://example.com on your computer "PC".
 Your computer sends the request by basically shouting
"Hey! Somebody get me http://example.com!", which
most nodes simply will ignore.
 Your switch will pass it on to where it eventually will be
received by example.com,
 which will pass back its index page to the router, which
then shouts "Hey! I have http://example.com for PC!",
 which again will be ignored by everyone except you.
 If others were on your switch with a packet sniffer,
they'd receive all that traffic and be able to look at it.
5/19/2015
6
PacketSnifferProgram
WHAT KIND OF INFORMATION CAN BE GATHERED?
 Most of the Internet runs in plain text, which means that
most of the information you look at is viewable by
someone with a packet sniffer.
 You should take note that all of this data is vulnerable only
through an unencrypted connection, so if the site you are
using has some form of encryption like SSL, your data is
less vulnerable.
 The most destructive data, and the stuff most people
are concerned with, is user credentials.
 Your user name and password for any given site are passed
in the clear for anyone to gather.
 This can be especially crippling if you use the same
password for all your accounts on-line.
 It doesn't matter how secure your bank Web site is if you
use the same password for that account and for your Twitter
account.
5/19/2015
7
PacketSnifferProgram
 There is a technique in the security world called session
hijacking where an attacker uses a packet sniffer to gain
access to a victim's session on a particular Web site by
stealing the victim's session cookie for that site.
 For instance, say I was sniffing traffic on the network, and
you logged in to Facebook and left the Remember Me On
This Computer check box checked.
 That signals Facebook to send you a session cookie that
your browser stores.
 I potentially could collect that cookie through packet
sniffing, add it to my browser and then have access to your
Facebook account.
 This is such a trivial task that it can be scripted easily
 And still there aren't many Web sites that encrypt their
traffic to the end user, making it a significant problem when
using the public Internet.
WHAT KIND OF INFORMATION CAN BE GATHERED?
(CONT.)
5/19/2015
8
PacketSnifferProgram
WHICH ACTIVITIES CAN BE MONITORED:
 When you connect to the Internet, you are joining a network
maintained by your Internet service provider (ISP).
 The ISP's network communicates with networks maintained by
other ISPs to form the foundation of the Internet.
 A packet sniffer located at one of the servers of your ISP would
potentially be able to monitor all of your online activities, such as:
 Which Web sites you visit
 What you look at on the site
 Whom you send e-mail to
 What's in the e-mail you send
 What you download from a site
 What streaming events you use, such as audio, video and Internet
telephony
 From this information, employers can determine how much time a
worker is spending online and if that worker is viewing
inappropriate material.
5/19/2015
9
PacketSnifferProgram
SNIFFER PROGRAM
Basic Sniffer
 Sniffers are programs that can capture/sniff/detect
network traffic packet by packet and analyse them
for various reasons.
 Commonly used in the field of network security.
 Wire shark is a very common packet sniffer/protocol
analyzer.
 Packet sniffers can be written in python too.
 In this program we have written a few very simple
sniffers in python for the Linux platform.
5/19/2015
10
PacketSnifferProgram
SNIFFER PROGRAM
Basic Sniffer
 Linux because, although python is a portable, the
programs wont run or give similar results on windows
 This is due to difference in the implementation of the
socket api.
 Sniffers shown here don't use any extra libraries like
libpcap.
 They just use raw sockets.
 Following are the details of actual program…
5/19/2015
11
PacketSnifferProgram
PACKET SNIFFER PROGRAM STEPS
1. Create raw socket
2. Receive a packet and Get packet string from tuple
3. From received packet parse Ethernet header with
the help of unpack method
Then print Destination MAC address, Source
MAC address and Protocol
4. Now parse IP packet for retrieving IP header
Then print Version, IP Header Length, TTL,
Protocol, Source Address and Destination
Address
5/19/2015
12
PacketSnifferProgram
PACKET SNIFFER PROGRAM STEPS
5. Now check which is internal protocol used
 If TCP then, parse TCP packet for retrieving
TCP header and data
Then, print Source Port, Dest Port,
Sequence Number, Acknowledgement and
TCP header length
 If ICMP then, parse ICMP packet for retrieving
ICMP header and data
Then, print Type, Code and Checksum
 If UDP then, parse UDP packet for retrieving
UDP header and data
Then, print Source Port, Dest Port, Length
and Checksum
5/19/2015
13
PacketSnifferProgram
PACKET SNIFFER PROGRAM OUTPUT
OUTPUT:
5/19/2015
14
PacketSnifferProgram
PROGRAM STEPS IN DETAILS
1. Create raw socket
5/19/2015
15
PacketSnifferProgram
PROGRAM STEPS DETAILS:
2. Receive a packet and Get packet string from tuple
5/19/2015
16
PacketSnifferProgram
PROGRAM STEPS DETAILS:
3. From received packet parse Ethernet header with the help of
unpack method
Then print Destination MAC address, Source MAC address
and Protocol
Ethernet header looks like this :
5/19/2015
17
PacketSnifferProgram
 struct.unpack(fmt, string)
Unpack the string according to the given format.
The result is a tuple even if it contains exactly one item.
The string must contain exactly the amount of data
required by the format (len(string) must equal
calcsize(fmt)).
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
18
PacketSnifferProgram
 Format Strings
o Format strings are the mechanism used to specify the
expected layout when packing and unpacking data.
o They are built up from Format Characters, which specify
the type of data being packed/unpacked.
o In addition, there are special characters for controlling
the Byte Order, Size, and Alignment.
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
19
PacketSnifferProgram
 Byte Order, Size, and Alignment
 The form '!' is available for network byte order is big-
endian or little-endian.
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
20
PacketSnifferProgram
 Format Characters
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
21
PacketSnifferProgram
 Here is the meaning of, ‘6s6sH’
s is char[] of size 6
And H is unsigned short, integer of size 2
Hence total is,
6 char + 6 char + 2 integer = total 8
This format string will take out required fields of header
packet
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
22
PacketSnifferProgram
 This will retrieve protocol type field of the packet which is
followed by packet
 If Ethernet protocol type is 8
 Then it has followed IP Protocol
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
23
PacketSnifferProgram
 Output of this Ethernet header part of code will be as
shown in following fig.:
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
24
PacketSnifferProgram
4. Now parse IP packet for retrieving IP header
Then print Version, IP Header Length, TTL, Protocol, Source
Address and Destination Address
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
25
PacketSnifferProgram
4. Now parse IP packet for retrieving IP header
Then print Version, IP Header Length, TTL, Protocol, Source
Address and Destination Address
PROGRAM STEPS DETAILS (CONT.):
IP header looks like this :
5/19/2015
26
PacketSnifferProgram
 Output of this IP header part of code will be as shown
in following fig.:
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
27
PacketSnifferProgram
Now check which is internal protocol used
 If TCP then, parse TCP packet for retrieving TCP header and data
Then, print Source Port, Dest Port, Sequence Number,
Acknowledgement and TCP header length
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
28
PacketSnifferProgram
To print Data of TCP packet
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
29
PacketSnifferProgram
PROGRAM STEPS DETAILS (CONT.):
TCP header looks like this :
Now check which is internal protocol used
 If TCP then, parse TCP packet for retrieving TCP header and data
Then, print Source Port, Dest Port, Sequence Number,
Acknowledgement and TCP header length
5/19/2015
30
PacketSnifferProgram
 Output of this TCP header part of code will be as
shown in following fig.:
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
31
PacketSnifferProgram
PROGRAM STEPS IN DETAILS:
6. Now check which is internal protocol used
 If ICMP then, parse ICMP packet for retrieving
ICMP header and data
Then, print Type, Code and Checksum
5/19/2015
32
PacketSnifferProgram
To print Data of ICMP packet
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
33
PacketSnifferProgram
PROGRAM STEPS IN DETAILS:
6. Now check which is internal protocol used
 If ICMP then, parse ICMP packet for retrieving
ICMP header and data
Then, print Type, Code and Checksum
ICMP Header
5/19/2015
34
PacketSnifferProgram
PROGRAM STEPS IN DETAILS:
 If UDP then, parse UDP packet for retrieving
UDP header and data
Then, print Source Port, Dest Port, Length and
Checksum
5/19/2015
35
PacketSnifferProgram
PROGRAM STEPS IN DETAILS:
UDP Header:
 If UDP then, parse UDP packet for retrieving
UDP header and data
Then, print Source Port, Dest Port, Length and
Checksum
5/19/2015
36
PacketSnifferProgram
To print Data of UDP packet
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
37
PacketSnifferProgram
If some other IP packet like IGMP is detected
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
38
PacketSnifferProgram
Final Overall packet output can be as shown in following fig:
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
39
PacketSnifferProgram
Final Overall packet output will be in continues execution mode:
PROGRAM STEPS DETAILS (CONT.):
5/19/2015
40
PacketSnifferProgram
THANK YOU!
5/19/2015
41
PacketSnifferProgram

More Related Content

PPTX
Packet sniffers
PPTX
Packet sniffers
PPTX
Packet sniffing
PPTX
PACKET Sniffer IMPLEMENTATION
PPTX
Network scanner
PDF
Network forensics
PDF
Packet sniffing & ARP Poisoning
PPTX
Wireshark
Packet sniffers
Packet sniffers
Packet sniffing
PACKET Sniffer IMPLEMENTATION
Network scanner
Network forensics
Packet sniffing & ARP Poisoning
Wireshark

What's hot (20)

PPT
Packet Sniffing
PPT
Network Intrusion Detection System Using Snort
PPTX
Introduction to Snort
PPTX
Social engineering
PPTX
Packet analysis using wireshark
PPTX
Intrusion detection and prevention system
PPTX
Network security
PPTX
Firewall presentation
PPTX
NMAP - The Network Scanner
PDF
Intrusion Detection System Project Report
PPTX
Ethical hacking - Footprinting.pptx
PDF
Final Project Report-SIEM
PPTX
Network scanning
PPT
Wireshark - presentation
PPTX
Wireshark
PPTX
Introduction to Malware Analysis
PPTX
PHISHING DETECTION
PPTX
Intrusion detection
PDF
Module 19 (evading ids, firewalls and honeypots)
Packet Sniffing
Network Intrusion Detection System Using Snort
Introduction to Snort
Social engineering
Packet analysis using wireshark
Intrusion detection and prevention system
Network security
Firewall presentation
NMAP - The Network Scanner
Intrusion Detection System Project Report
Ethical hacking - Footprinting.pptx
Final Project Report-SIEM
Network scanning
Wireshark - presentation
Wireshark
Introduction to Malware Analysis
PHISHING DETECTION
Intrusion detection
Module 19 (evading ids, firewalls and honeypots)
Ad

Viewers also liked (20)

DOCX
Packet sniffer repot
ODP
Sniffer
PPTX
Sniffer ppt
PPTX
Sniffer for detecting lost mobile ppt
PPTX
Sniffer for the mobile phones
PPTX
Sniffer for Detecting Lost Mobile
PDF
Sniffing via dsniff
PPTX
Sniffer for detecting lost mobiles
PPTX
Sniffer for detecting lost mobiles
PPT
Networking Chapter 16
PDF
How to use packet sniffers
PPT
Chapter2
PPTX
Spoofing
PPTX
Packet sniffing in LAN
PPT
Module 5 Sniffers
PPTX
Cain
PPTX
Ethical hacking Chapter 2 - TCP/IP - Eric Vanderburg
PDF
Network Packet Analysis
PPT
ip spoofing
Packet sniffer repot
Sniffer
Sniffer ppt
Sniffer for detecting lost mobile ppt
Sniffer for the mobile phones
Sniffer for Detecting Lost Mobile
Sniffing via dsniff
Sniffer for detecting lost mobiles
Sniffer for detecting lost mobiles
Networking Chapter 16
How to use packet sniffers
Chapter2
Spoofing
Packet sniffing in LAN
Module 5 Sniffers
Cain
Ethical hacking Chapter 2 - TCP/IP - Eric Vanderburg
Network Packet Analysis
ip spoofing
Ad

Similar to Packet Sniffer (20)

PPT
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
DOC
Sudheer tech seminor
DOCX
Pears
PPTX
Forensic Analysis - Empower Tech Days 2013
PDF
Analysis of network traffic by using packet sniffing tool wireshark
PDF
Network_Forenic_Training_for_beginner.pdf
PDF
How does the internet work converted General (Your) Affiliate Link: https://w...
PDF
ODP
Routers Firewalls And Proxies - OH MY!
DOCX
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docx
PDF
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
DOCX
HS1011 Data Communication and Networks 13 August 2015 HS101.docx
PDF
COMP8045 - Project Report v.1.3
PDF
Chapter 7 security tools i
PDF
How Does the Internet Work? : Notes
PDF
Chapter 8 security tools ii
PPT
Module 3 Scanning
PDF
WebRTC: A front-end perspective
PDF
The Kyoto Protocol ( Kp )
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
Sudheer tech seminor
Pears
Forensic Analysis - Empower Tech Days 2013
Analysis of network traffic by using packet sniffing tool wireshark
Network_Forenic_Training_for_beginner.pdf
How does the internet work converted General (Your) Affiliate Link: https://w...
Routers Firewalls And Proxies - OH MY!
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docx
IRJET- Assessment of Network Protocol Packet Analysis in IPV4 and IPV6 on Loc...
HS1011 Data Communication and Networks 13 August 2015 HS101.docx
COMP8045 - Project Report v.1.3
Chapter 7 security tools i
How Does the Internet Work? : Notes
Chapter 8 security tools ii
Module 3 Scanning
WebRTC: A front-end perspective
The Kyoto Protocol ( Kp )

Recently uploaded (20)

PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPT
Project quality management in manufacturing
PPTX
additive manufacturing of ss316l using mig welding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Well-logging-methods_new................
PDF
Digital Logic Computer Design lecture notes
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Arduino robotics embedded978-1-4302-3184-4.pdf
Project quality management in manufacturing
additive manufacturing of ss316l using mig welding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
bas. eng. economics group 4 presentation 1.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mechanical Engineering MATERIALS Selection
Model Code of Practice - Construction Work - 21102022 .pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Well-logging-methods_new................
Digital Logic Computer Design lecture notes
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...

Packet Sniffer

  • 2. INTRODUCTION  Without some form of countermeasures, your data isn't safe on public networks.  There are people out there who are capable of stealing your data.  The best defense is to know what you can lose, how it can get lost and how to defend against it. 5/19/2015 2 PacketSnifferProgram
  • 3. WHAT IS PACKET SNIFFING?  Packet sniffing, or packet analysis, is the process of capturing any data passed over the local network and looking for any information that may be useful.  Most of the time, system administrators use packet sniffing to troubleshoot network problems (like finding out why traffic is so slow in one part of the network) or to detect intrusions and that is what this type of analysis originally was designed for.  packet sniffers are considered security tools instead of network tools now. 5/19/2015 3 PacketSnifferProgram
  • 4. HOW DOES IT WORK?  First, packet sniffing is a passive technique.  No one actually is attacking your computer and investigating through all those files that you don't want anyone to access.  It's a lot like eavesdropping (overhear something).  My computer is just listening in on the conversation that your computer is having with the gateway.  Typically, when people think of network traffic, they think that it goes directly from their computers to the router or switch and up to the gateway and then out to the Internet, where it routes similarly until it gets to the specified destination. 5/19/2015 4 PacketSnifferProgram
  • 5. HOW DOES IT WORK? (CONT.)  This is mostly true except for one fundamental detail.  Your computer isn't directly sending the data anywhere.  It broadcasts the data in packets that have the destination in the header.  Every node on your network (or switch) receives the packet, determines whether it is the intended recipient and then either accepts the packet or ignores it. 5/19/2015 5 PacketSnifferProgram
  • 6. HOW DOES IT WORK? (CONT.)  For example, let's say you're loading the Web page http://example.com on your computer "PC".  Your computer sends the request by basically shouting "Hey! Somebody get me http://example.com!", which most nodes simply will ignore.  Your switch will pass it on to where it eventually will be received by example.com,  which will pass back its index page to the router, which then shouts "Hey! I have http://example.com for PC!",  which again will be ignored by everyone except you.  If others were on your switch with a packet sniffer, they'd receive all that traffic and be able to look at it. 5/19/2015 6 PacketSnifferProgram
  • 7. WHAT KIND OF INFORMATION CAN BE GATHERED?  Most of the Internet runs in plain text, which means that most of the information you look at is viewable by someone with a packet sniffer.  You should take note that all of this data is vulnerable only through an unencrypted connection, so if the site you are using has some form of encryption like SSL, your data is less vulnerable.  The most destructive data, and the stuff most people are concerned with, is user credentials.  Your user name and password for any given site are passed in the clear for anyone to gather.  This can be especially crippling if you use the same password for all your accounts on-line.  It doesn't matter how secure your bank Web site is if you use the same password for that account and for your Twitter account. 5/19/2015 7 PacketSnifferProgram
  • 8.  There is a technique in the security world called session hijacking where an attacker uses a packet sniffer to gain access to a victim's session on a particular Web site by stealing the victim's session cookie for that site.  For instance, say I was sniffing traffic on the network, and you logged in to Facebook and left the Remember Me On This Computer check box checked.  That signals Facebook to send you a session cookie that your browser stores.  I potentially could collect that cookie through packet sniffing, add it to my browser and then have access to your Facebook account.  This is such a trivial task that it can be scripted easily  And still there aren't many Web sites that encrypt their traffic to the end user, making it a significant problem when using the public Internet. WHAT KIND OF INFORMATION CAN BE GATHERED? (CONT.) 5/19/2015 8 PacketSnifferProgram
  • 9. WHICH ACTIVITIES CAN BE MONITORED:  When you connect to the Internet, you are joining a network maintained by your Internet service provider (ISP).  The ISP's network communicates with networks maintained by other ISPs to form the foundation of the Internet.  A packet sniffer located at one of the servers of your ISP would potentially be able to monitor all of your online activities, such as:  Which Web sites you visit  What you look at on the site  Whom you send e-mail to  What's in the e-mail you send  What you download from a site  What streaming events you use, such as audio, video and Internet telephony  From this information, employers can determine how much time a worker is spending online and if that worker is viewing inappropriate material. 5/19/2015 9 PacketSnifferProgram
  • 10. SNIFFER PROGRAM Basic Sniffer  Sniffers are programs that can capture/sniff/detect network traffic packet by packet and analyse them for various reasons.  Commonly used in the field of network security.  Wire shark is a very common packet sniffer/protocol analyzer.  Packet sniffers can be written in python too.  In this program we have written a few very simple sniffers in python for the Linux platform. 5/19/2015 10 PacketSnifferProgram
  • 11. SNIFFER PROGRAM Basic Sniffer  Linux because, although python is a portable, the programs wont run or give similar results on windows  This is due to difference in the implementation of the socket api.  Sniffers shown here don't use any extra libraries like libpcap.  They just use raw sockets.  Following are the details of actual program… 5/19/2015 11 PacketSnifferProgram
  • 12. PACKET SNIFFER PROGRAM STEPS 1. Create raw socket 2. Receive a packet and Get packet string from tuple 3. From received packet parse Ethernet header with the help of unpack method Then print Destination MAC address, Source MAC address and Protocol 4. Now parse IP packet for retrieving IP header Then print Version, IP Header Length, TTL, Protocol, Source Address and Destination Address 5/19/2015 12 PacketSnifferProgram
  • 13. PACKET SNIFFER PROGRAM STEPS 5. Now check which is internal protocol used  If TCP then, parse TCP packet for retrieving TCP header and data Then, print Source Port, Dest Port, Sequence Number, Acknowledgement and TCP header length  If ICMP then, parse ICMP packet for retrieving ICMP header and data Then, print Type, Code and Checksum  If UDP then, parse UDP packet for retrieving UDP header and data Then, print Source Port, Dest Port, Length and Checksum 5/19/2015 13 PacketSnifferProgram
  • 14. PACKET SNIFFER PROGRAM OUTPUT OUTPUT: 5/19/2015 14 PacketSnifferProgram
  • 15. PROGRAM STEPS IN DETAILS 1. Create raw socket 5/19/2015 15 PacketSnifferProgram
  • 16. PROGRAM STEPS DETAILS: 2. Receive a packet and Get packet string from tuple 5/19/2015 16 PacketSnifferProgram
  • 17. PROGRAM STEPS DETAILS: 3. From received packet parse Ethernet header with the help of unpack method Then print Destination MAC address, Source MAC address and Protocol Ethernet header looks like this : 5/19/2015 17 PacketSnifferProgram
  • 18.  struct.unpack(fmt, string) Unpack the string according to the given format. The result is a tuple even if it contains exactly one item. The string must contain exactly the amount of data required by the format (len(string) must equal calcsize(fmt)). PROGRAM STEPS DETAILS (CONT.): 5/19/2015 18 PacketSnifferProgram
  • 19.  Format Strings o Format strings are the mechanism used to specify the expected layout when packing and unpacking data. o They are built up from Format Characters, which specify the type of data being packed/unpacked. o In addition, there are special characters for controlling the Byte Order, Size, and Alignment. PROGRAM STEPS DETAILS (CONT.): 5/19/2015 19 PacketSnifferProgram
  • 20.  Byte Order, Size, and Alignment  The form '!' is available for network byte order is big- endian or little-endian. PROGRAM STEPS DETAILS (CONT.): 5/19/2015 20 PacketSnifferProgram
  • 21.  Format Characters PROGRAM STEPS DETAILS (CONT.): 5/19/2015 21 PacketSnifferProgram
  • 22.  Here is the meaning of, ‘6s6sH’ s is char[] of size 6 And H is unsigned short, integer of size 2 Hence total is, 6 char + 6 char + 2 integer = total 8 This format string will take out required fields of header packet PROGRAM STEPS DETAILS (CONT.): 5/19/2015 22 PacketSnifferProgram
  • 23.  This will retrieve protocol type field of the packet which is followed by packet  If Ethernet protocol type is 8  Then it has followed IP Protocol PROGRAM STEPS DETAILS (CONT.): 5/19/2015 23 PacketSnifferProgram
  • 24.  Output of this Ethernet header part of code will be as shown in following fig.: PROGRAM STEPS DETAILS (CONT.): 5/19/2015 24 PacketSnifferProgram
  • 25. 4. Now parse IP packet for retrieving IP header Then print Version, IP Header Length, TTL, Protocol, Source Address and Destination Address PROGRAM STEPS DETAILS (CONT.): 5/19/2015 25 PacketSnifferProgram
  • 26. 4. Now parse IP packet for retrieving IP header Then print Version, IP Header Length, TTL, Protocol, Source Address and Destination Address PROGRAM STEPS DETAILS (CONT.): IP header looks like this : 5/19/2015 26 PacketSnifferProgram
  • 27.  Output of this IP header part of code will be as shown in following fig.: PROGRAM STEPS DETAILS (CONT.): 5/19/2015 27 PacketSnifferProgram
  • 28. Now check which is internal protocol used  If TCP then, parse TCP packet for retrieving TCP header and data Then, print Source Port, Dest Port, Sequence Number, Acknowledgement and TCP header length PROGRAM STEPS DETAILS (CONT.): 5/19/2015 28 PacketSnifferProgram
  • 29. To print Data of TCP packet PROGRAM STEPS DETAILS (CONT.): 5/19/2015 29 PacketSnifferProgram
  • 30. PROGRAM STEPS DETAILS (CONT.): TCP header looks like this : Now check which is internal protocol used  If TCP then, parse TCP packet for retrieving TCP header and data Then, print Source Port, Dest Port, Sequence Number, Acknowledgement and TCP header length 5/19/2015 30 PacketSnifferProgram
  • 31.  Output of this TCP header part of code will be as shown in following fig.: PROGRAM STEPS DETAILS (CONT.): 5/19/2015 31 PacketSnifferProgram
  • 32. PROGRAM STEPS IN DETAILS: 6. Now check which is internal protocol used  If ICMP then, parse ICMP packet for retrieving ICMP header and data Then, print Type, Code and Checksum 5/19/2015 32 PacketSnifferProgram
  • 33. To print Data of ICMP packet PROGRAM STEPS DETAILS (CONT.): 5/19/2015 33 PacketSnifferProgram
  • 34. PROGRAM STEPS IN DETAILS: 6. Now check which is internal protocol used  If ICMP then, parse ICMP packet for retrieving ICMP header and data Then, print Type, Code and Checksum ICMP Header 5/19/2015 34 PacketSnifferProgram
  • 35. PROGRAM STEPS IN DETAILS:  If UDP then, parse UDP packet for retrieving UDP header and data Then, print Source Port, Dest Port, Length and Checksum 5/19/2015 35 PacketSnifferProgram
  • 36. PROGRAM STEPS IN DETAILS: UDP Header:  If UDP then, parse UDP packet for retrieving UDP header and data Then, print Source Port, Dest Port, Length and Checksum 5/19/2015 36 PacketSnifferProgram
  • 37. To print Data of UDP packet PROGRAM STEPS DETAILS (CONT.): 5/19/2015 37 PacketSnifferProgram
  • 38. If some other IP packet like IGMP is detected PROGRAM STEPS DETAILS (CONT.): 5/19/2015 38 PacketSnifferProgram
  • 39. Final Overall packet output can be as shown in following fig: PROGRAM STEPS DETAILS (CONT.): 5/19/2015 39 PacketSnifferProgram
  • 40. Final Overall packet output will be in continues execution mode: PROGRAM STEPS DETAILS (CONT.): 5/19/2015 40 PacketSnifferProgram