CSCD433/533 Advanced Networks Spring 2016 Lecture 15

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP Advanced Unix Programming Raw Sockets Datalink Access Chapters 25, 26.
Advertisements

Datalink Access.
Network Performance Measurement
Lecture Materials for the John Wiley & Sons book: Cyber Security: Managing Networks, Conducting Tests, and Investigating Intrusions April 14, 2015 DRAFT1.
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
21.1 Chapter 21 Network Layer: Address Mapping, Error Reporting, and Multicasting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Tactics to Discover “Passive” Monitoring Devices
1 Topic 2 – Lesson 4 Packet Filtering Part I. 2 Basic Questions What is packet filtering? What is packet filtering? What elements are inside an IP header?
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
SYSTEM ADMINISTRATION Chapter 19
Raw Sockets CS-480b Dick Steflik Raw Sockets Raw Sockets let you program at just above the network (IP) layer You could program at the IP level using.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
Sanjay Goel, School of Business/Center for Information Forensics and Assurance University at Albany Proprietary Information 1 Unit Outline Information.
ECE Department: University of Massachusetts, Amherst ECE 354 Spring 2009 Lab 3: Transmitting and Receiving Ethernet Packets.
Understanding Networks. Objectives Compare client and network operating systems Learn about local area network technologies, including Ethernet, Token.
Networking Components
(part 3).  Switches, also known as switching hubs, have become an increasingly important part of our networking today, because when working with hubs,
TCP/IP Tools Lesson 5. Objectives Skills/ConceptsObjective Domain Description Objective Domain Number Using basic TCP/IP commands Understanding TCP/IP3.6.
Introduction to InfoSec – Recitation 12 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Connecting LANs, Backbone Networks, and Virtual LANs
OSI Model Routing Connection-oriented/Connectionless Network Services.
Raw Sockets.
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
CSCD433 Advanced Networks Fall 2011 Raw vs. Cooked Sockets.
CPSC 441 Tutorial TA: Fang Wang The content of these slides are taken from CPSC 526 TUTORIAL by Nashd Safa (Extended and partially modified)
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
70-291: MCSE Guide to Managing a Microsoft Windows Server 2003 Network Chapter 3: TCP/IP Architecture.
LWIP TCP/IP Stack 김백규.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
IP Forwarding.
CMPT 471 Networking II Address Resolution IPv4 ARP RARP 1© Janice Regan, 2012.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Day 14 Introduction to Networking. Unix Networking Unix is very frequently used as a server. –Server is a machine which “serves” some function Web Server.
Transport Layer: TCP and UDP. Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation.
Raw Sockets Vivek Ramachandran. A day in the life of Network Packet.
Chapter 6-2 the TCP/IP Layers. The four layers of the TCP/IP model are listed in Table 6-2. The layers are The four layers of the TCP/IP model are listed.
Scanning & Enumeration Lab 3 Once attacker knows who to attack, and knows some of what is there (e.g. DNS servers, mail servers, etc.) the next step is.
CHAPTER 9 Sniffing.
DoS Suite and Raw Socket Programming Group 16 Thomas Losier Paul Obame Group 16 Thomas Losier Paul Obame.
CNIT 124: Advanced Ethical Hacking Ch 7: Capturing Traffic.
Sniffer, tcpdump, Ethereal, ntop
TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.
Network Sniffer Anuj Shah Advisor: Dr. Chung-E Wang Department of Computer Science.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Connecting Devices CORPORATE INSTITUTE OF SCIENCE & TECHNOLOGY, BHOPAL Department of Electronics and.
Monitoring Troubleshooting TCP/IP Chapter 3. Objectives for this Chapter Troubleshoot TCP/IP addressing Diagnose and resolve issues related to incorrect.
Individual Project 1 Sarah Pritchard. Fran, a customer of your company, would like to visit your company’s website from her home computer… How does your.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
Linux Operations and Administration Chapter Eight Network Communications.
0x440 Network Sniffing.
Slide #1 CIT 380: Securing Computer Systems TCP/IP.
Firewalls A brief introduction to firewalls. What does a Firewall do? Firewalls are essential tools in managing and controlling network traffic Firewalls.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
The OSI Model. Understanding the OSI Model In early 1980s, manufacturers began to standardize networking so that networks from different manufacturers.
Address Resolution Protocol Yasir Jan 20 th March 2008 Future Internet.
COMP2322 Lab 1 Introduction to Wireless LAN Weichao Li Apr. 8, 2016.
1 Network Communications A Brief Introduction. 2 Network Communications.
Mobile Packet Sniffer Ofer Borosh Vadim Lanzman Dr. Chen Avin
Lab 2: Packet Capture & Traffic Analysis with Wireshark
Sockets and Beginning Network Programming
or call for office visit,
LAN Vulnerabilities.
Chapter 6 Network Performance Measurement
Computer Networks 9/17/2018 Computer Networks.
CSCD433 Advanced Networks Spring 2016 Lecture 16a
Introduction to Packet Sniffing using Ethereal
CSCD433/533 Advanced Networks Winter 2019 Lecture 13
Exceptions and networking
Virtual Private Network
Presentation transcript:

CSCD433/533 Advanced Networks Spring 2016 Lecture 15 Raw vs. Cooked Sockets

Introduction Better Understand the Protocol Stack Use Raw Sockets So far, sockets in Java either TCP or UDP based In fact, Java does not have built-in support for Raw Sockets!!! Use Libraries C and Python have native support for Raw Sockets

Motivation for Raw Sockets Standard Java Sockets do not fit all our needs Normal sockets lack some functionality 1. We cannot read/write ICMP or IGMP protocols with normal sockets Ping tool cannot be written using normal sockets 2. Some Operating Systems do not process Ipv4 protocols other than ICMP, IGMP, TCP or UDP What if we have a proprietary protocol that we want to handle? How do we send/receive data using that protocol? Answer: Raw Sockets!!!

Raw Socket Defined Raw sockets can be used to construct a packet manually inside an application Allow an application to set its own headers Use for raw sockets These include: Implementation of transport-layer protocols that are not built in to the network stack, and Production of malformed or otherwise non- standard datagrams for testing purposes.

Normal Sockets - Cooked Normal sockets, use OS kernel and built-in network stack to add headers like IP header and TCP header So an application only needs to take care of what data it is sending and what reply it is expecting Headers are added and removed without your application having to worry about this

More Motivation for Raw Sockets Recall, CSCD330, can we send true ICMP packets in Java? Not exactly. There is this work-around InetAddress.getByName("192.168.1.1").isReachable(4000); What does this do?

What does this do? InetAddress.getByName("192.168.1.1").isReachable(4000); Does several things depending on OS and user permissions Linux/MacOS Linux/MacOS environment, no admin rights, JVM tries to establish TCP connection on port 7 Function returns true if TCP handshake is successful With Superuser rights, correct ICMP request is sent and function returns true if an ICMP reply is received Windows XP Windows XP environment, TCP handshake is used to test if machine is up, no matter if program has admin rights or not

Solution Using Raw Sockets There is a way in java, using various libraries Using an older library jpcap, it is possible to assemble and send ICMP Packets The library is here http://www.sf.net/projects/jpcap

Recall Network Packets Some slides courtesy of Vivek Ramachandran

The gory details …..

More Details Raw sockets All Headers i.e. Ethernet, IP, TCP etc are stripped by network stack and only data is shipped to application layer We cannot modify packet headers of packets when they are sent out from our host Is this a good thing? Application Data Network Stack Headers Data

Injecting Packets If we could receive frames for all computers connected to our broadcast domain Promiscuous Mode If we could get all the headers Ethernet , TCP, IP etc from the network and analyze them Then, we could inject packets with custom headers and data into the network directly

Promiscuous Mode of NIC Card It is the “See All, Hear All” mode Tells network driver to accept all packets irrespective Used for Network Monitoring – both legal and illegal monitoring We can do this by programmatically setting the IFF_PROMISC flag or Using the ifconfig utility (ifconfig eth0 promisc)

Getting All headers - Sniffing Caveat, the way it has worked in past Once we set interface to promiscuous mode we can get “full packets” with all the headers. We can process these packets and extract data from it Note, we are receiving packets meant for all hosts

More on Promiscuous Mode Questions Under what circumstances can we see all packets on a LAN segment? Is promiscuous mode truly magic?

More on Promiscuous Mode Under what circumstances can we see all packets on a LAN segment? Is promiscuous mode truly magic? Answer: NO Can see broadcast traffic Can see all traffic if hosts are on a hub Can see all traffic if one switch port is a mirror or spanning port Can see all traffic, if card is able to go into promiscuous mode and LAN is wireless Recall, data should be encrypted these days !!!

Sending arbitrary packets – Packet Injection We “manufacture” our own packets and send it out on the network. Absolute power!!! Total network stack bypass Most active network monitoring tools and hacking tools use this. Dos attacks ? Syn Floods ? IP Spoofs ? Plus, network tools like Wireshark

Raw Sockets – a closer look Application Raw Socket

Library Support for Raw Sockets In Java, no way to get to RAW interfaces in OS kernels with standard Java libraries Two C libraries support standard way of interfacing to network cards Libpcap – Linux/MAC/Unix Winpcap - Windows

Link Layer Packet Capture Stevens in his classic book, makes a distinction between Raw Sockets and capturing packets at the link layer See, Unix Network Programming by R. Stevens, B. Fenner and A. Rudoff for details For our purposes, since Java doesn't have true RAW socket interface, only way we can capture raw traffic is through link layer packet capture Jpcap running on top of libpcap library is one example of Java special purpose library

Picture of this Libpcap uses BPF and PF_Packet in Linux App App Process IPv4 IPv6 Kernel Buffer Buffer Copy Received BPF DataLink Copy Transmitted BPF – Berkeley packet Filter Gets copy after received Gets copy before transmitted

Berkeley Packet Filter Berkeley Packet Filter (BPF) provides Raw interface to data link layers, permitting raw link-layer packets to be sent and received It is available on most Unix-like operating systems BPF provides pseudo-devices that can be bound to a network interface Reads from device reads buffers full of packets received on network interface, and Writes to device will inject packets on network interface https://en.wikipedia.org/wiki/Berkeley_Packet_Filter

Jpcap As an Example Jpcap Open source library for capturing and sending network packets from Java applications Has features similar to all libraries that do RAW sockets It provides facilities to: Capture raw packets live from wire. Save captured packets to an offline file, and read captured packets from an offline file Automatically identify packet types and generate corresponding Java objects (for Ethernet, IPv4, IPv6, ARP/RARP, TCP, UDP, and ICMPv4 packets). Filter packets according to user-specified rules before dispatching them to application and send raw packets to the network

Jpcap and Other Java Raw Libraries C Language allows native access to Raw Socket interface More details are left to you, the programmer Must build the headers for IP, TCP, UDP or any new protocol you might create More work, but gives you more control

Java Jpcap You must first create a class that implements the interface jpcap.JpcapHandler public class JpcapTip implements JpcapHandler { public void handlePacket(Packet packet){ System.out.println(packet); }

Java Jpcap You need to tell Jpcap which network device you want to listen to API provides jpcap.Jpcap.getDeviceList() method for this purpose String[] devices = Jpcap.getDeviceList(); Once you have a list of device names, you must choose one for listening: String deviceName = devices[0];

Java Jpcap After choosing a device, you open it for listening by using method Jpcap.openDevice()‏ The openDevice() method requires four arguments: Device name to be opened, Maximum number of bytes to read from the device at one time, Boolean value specifying whether to put device into promiscuous mode Timeout value that will be used if you later call processPacket() method Jpcap jpcap = Jpcap.openDevice(deviceName, 1028, false, 10000);

Java Jpcap Jpcap jpcap = Jpcap.openDevice(deviceName, 1028, false, 10000); OpenDevice() method returns reference to Jpcap object that will be used for capturing Now have Jpcap instance, you can start listening by calling either processPacket() or loopPacket()‏ Both methods take two arguments: Maximum number of packets to capture or -1 to indicate no limit Instance of a class that implements JpcapHandler.

Jpcap If you call processPacket(), Jpcap will capture packets until either timeout specified in openDevice is exceeded or maximum number of packets specified has been reached If you call loopPacket()‏ Will capture packets until maximum number of packets is reached or forever, if there is no maximum. The call looks like this: jpcap.loopPacket(-1, new JpcapTip());

Jpcap Example Program Next slide shows Jpcap program that captures packets using loopPacket and the first interface displayed in the device list Device list is printed It then prints out the packets captured

import jpcap.JpcapHandler; import jpcap.Packet; public class JpcapTip implements JpcapHandler { public void handlePacket(Packet packet){ System.out.println(packet); } public static void main(String[] args) throws java.io.IOException{ String[] devices = Jpcap.getDeviceList(); for (int i = 0; i < devices.length; i++) { System.out.println(devices[i]); String deviceName = devices[0]; Jpcap jpcap = Jpcap.openDevice(deviceName, 1028, false, 1); jpcap.loopPacket(-1, new JpcapTip());

JPCAP Example The packet output of executing the test class looks like this It's shortened for space: ARP REQUEST 00:06:5b:01:b2:4d(192.168.15.79) 00:00:00:00:00:00(192.168.15.34)‏ 1052251329:525479 192.168.15.103->255.255.255.255 protocol(17) priority(0) hop(offset(0) ident(59244) UDP 1211 1211

Summary Raw sockets through jpcap allows capability not built into Java Raw sockets are possible Can write programs that gain access lower level protocols Gives power to you, the programmer!!! Allows for fun in manipulating packets!

Class over !!! Midterm due today ….