CSCD433/533 Advanced Networks Winter 2017 Lecture 13. Raw vs. Cooked Sockets

Similar documents
Packet Sniffing and Spoofing

Layer 4: UDP, TCP, and others. based on Chapter 9 of CompTIA Network+ Exam Guide, 4th ed., Mike Meyers

Introduction! Overview! Signal-driven I/O for Sockets! Two different UDP servers!

ELEC5616 COMPUTER & NETWORK SECURITY

Material for the Networking lab in EITF25 & EITF45

Computer Network Programming. The Transport Layer. Dr. Sam Hsu Computer Science & Engineering Florida Atlantic University

Packet Sniffing and Spoofing Lab

Detecting Sniffers on Your Network

Transport Over IP. CSCI 690 Michael Hutt New York Institute of Technology

The ACK and NACK of Programming

Open Access Design and Development of Network Application Layer Sniffer Analysis Software. Yujiao Wang and Haiyun Lin *

Switching & ARP Week 3

AN TOÀN LỚP 4: TCP/IP ATTACKS NGUYEN HONG SON PTITHCM

Computer Networks Security: intro. CS Computer Systems Security

ECE 650 Systems Programming & Engineering. Spring 2018

Network sniffing packet capture and analysis

Lecture 6. Internet Security: How the Internet works and some basic vulnerabilities. Thursday 19/11/2015

Configuring attack detection and prevention 1

Computer Networks A Simple Network Analyzer Decoding Ethernet and IP headers

Practical Exercises in Computer Networks

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

CSCD58 WINTER 2018 WEEK 6 - NETWORK LAYER PART 1. Brian Harrington. February 13, University of Toronto Scarborough

Randall Stewart, Cisco Systems Phill Conrad, University of Delaware

CSC 405 Introduction to Computer Security. Network Security

CIT 380: Securing Computer Systems. Network Security Concepts

network security s642 computer security adam everspaugh

19: Networking. Networking Hardware. Mark Handley

Hands-On Ethical Hacking and Network Defense Chapter 5 Port Scanning

Hands-On Ethical Hacking and Network Defense Chapter 5 Port Scanning

TCP. Networked Systems (H) Lecture 13

IP Network Troubleshooting Part 3. Wayne M. Pecena, CPBE, CBNE Texas A&M University Educational Broadcast Services - KAMU

IPv4 and ipv6 INTEROPERABILITY

NETWORK PROGRAMMING. Ipv4 and Ipv6 interoperability

Configuring attack detection and prevention 1

Muhammad Farooq-i-Azam CHASE-2006 Lahore

CONTENTS IN DETAIL ACKNOWLEDGMENTS INTRODUCTION 1 PACKET ANALYSIS AND NETWORK BASICS 1 2 TAPPING INTO THE WIRE 17 3 INTRODUCTION TO WIRESHARK 35

When does it work? Packet Sniffers. INFO Lecture 8. Content 24/03/2009

Network Forensic Analysis

DDoS Testing with XM-2G. Step by Step Guide

Brief Contents. Acknowledgments... xv. Introduction...xvii. Chapter 1: Packet Analysis and Network Basics Chapter 2: Tapping into the Wire...

Lab I: Using tcpdump and Wireshark

On Distributed Communications, Rand Report RM-3420-PR, Paul Baran, August 1964

Outline. What is TCP protocol? How the TCP Protocol Works SYN Flooding Attack TCP Reset Attack TCP Session Hijacking Attack

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?!

CSc 466/566. Computer Security. 18 : Network Security Introduction

Chapter 6. The Protocol TCP/IP. Introduction to Protocols

Preliminary Development of an Inexpensive and Portable Network Monitoring probe using an Internet Embedded Microprocessor

Vorlesung Kommunikationsnetze

SE 4C03 Winter Final Examination Answer Key. Instructor: William M. Farmer

So What is WireShark?

Packet Capturing with TCPDUMP command in Linux

Flowreplay Design Notes

ECE 435 Network Engineering Lecture 23

lab rip experiences with RIPv2 distance vector protocol

Introduction to Computer Networks. CS 166: Introduction to Computer Systems Security

IP - The Internet Protocol. Based on the slides of Dr. Jorg Liebeherr, University of Virginia

Practical Exercises in Computer Networks

Computer Networks A Simple Network Analyzer PART A undergraduates and graduates PART B graduate students only

Experiment 2: Wireshark as a Network Protocol Analyzer

EEC-682/782 Computer Networks I

ICS 351: Networking Protocols

9. Security. Safeguard Engine. Safeguard Engine Settings

Secure Communications Over a Network

Chapter 2 - Part 1. The TCP/IP Protocol: The Language of the Internet

n Describe sniffing concepts, including active and passive sniffing n Describe sniffing countermeasures n Describe signature analysis within Snort

Chapter 8 roadmap. Network Security

COMPARATIVE ANALYSIS OF PACKET SNIFFERS : A STUDY

Address Resolution Protocol (ARP), RFC 826

Internet Layers. Physical Layer. Application. Application. Transport. Transport. Network. Network. Network. Network. Link. Link. Link.

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

ENEE 457: Computer Systems Security 11/07/16. Lecture 18 Computer Networking Basics

Objectives. Chapter 10. Upon completion you will be able to:

20-CS Cyber Defense Overview Fall, Network Basics

4. Basic IP Support Protocols

Packet Capture & Wireshark. Fakrul Alam

Firewalls. Firewall. means of protecting a local system or network of systems from network-based security threats creates a perimeter of defense

ETSF05/ETSF10 Internet Protocols Network Layer Protocols

COMPUTER NETWORKING LAB EXERCISES (TP) 4

Computer and Network Security

Network Security. Kitisak Jirawannakool Electronics Government Agency (public organisation)

Quiz. Segment structure and fields Flow control (rwnd) Timeout interval. Phases transition ssthresh setting Cwnd setting

Chapter 19 Network Layer: Logical Addressing

Computer Security Spring Firewalls. Aggelos Kiayias University of Connecticut

QUIZ: Longest Matching Prefix

AN INTRODUCTION TO ARP SPOOFING

Lecture 8. Network Layer (cont d) Network Layer 1-1

Fundamentals of Linux Platform Security

Fundamentals of Linux Platform Security. Hands-On Network Security. Roadmap. Security Training Course. Module 1 Reconnaissance Tools

Fundamental Questions to Answer About Computer Networking, Jan 2009 Prof. Ying-Dar Lin,

A Client-Server Exchange

Computer Forensics: Investigating Network Intrusions and Cybercrime, 2nd Edition. Chapter 2 Investigating Network Traffic

Lecture 3. The Network Layer (cont d) Network Layer 1-1

CSC 4900 Computer Networks: Security Protocols (2)

Applied IT Security. System Security. Dr. Stephan Spitz 6 Firewalls & IDS. Applied IT Security, Dr.

Chapter 4 Network Layer: The Data Plane

Network Control, Con t

CSC 574 Computer and Network Security. TCP/IP Security

Intro to OpenFlow Tutorial

! " Lecture 5: Networking for Games (cont d) Packet headers. Packet footers. IP address. Edge router (cable modem, DSL modem)

Transcription:

CSCD433/533 Advanced Networks Winter 2017 Lecture 13 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!!! To program Raw Sockets in Java - 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 allow a program or application to provide custom headers for a protocol which are otherwise provided by kernel/os network stack Raw sockets allow adding custom headers instead of headers provided by underlying operating system Bypasseses network stack and allows an application to also process packet headers

What can raw sockets do? Bypass TCP/UDP layers Read and write ICMP and IGMP packets ping, traceroute, multicast daemon Read and write IP datagrams with an IP protocol field not processed by the kernel OSPF sits directly on top of IP User process versus kernel Send and receive your own IP packets with your own IP header using the IP_HDRINCL socket option Can build and send TCP and UDP packets Testing, hacking Only superuser can create raw socket though You need to do all protocol processing at user-level 5

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 Superuser 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 Newer Library jnetpcap http://jnetpcap.org/

Recall Network Packets Where does the Socket sit? 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 in general? Application Data Network Stack Headers Data

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

Getting All headers - Sniffing Note: Way it has worked in past Once we set NIC 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

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)

Possible to Inject Packets If we could receive frames for all computers connected to our broadcast domain. And, 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

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!!!

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 Both use something called the Berkeley Packet Filter - BPF

Link Layer Packet Capture Stevens in his classic book, makes a distinction between Raw Sockets and capturing packets at the link layer with a packet filter 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 or jnetpcap running on top of libpcap library is one example of Java special purpose library

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

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

jnetpcap As an Example jnetpcap Open source library for capturing and sending network packets from Java applications Runs on both Linux and Windows It contains: * A Java wrapper for nearly all libpcap library native calls * Decodes captured packets in real-time * Provides library of network protocols (core protocols) * Users can add own protocol definitions using java SDK * jnetpcap uses mixture of native and java implementation for optimum packet decoding performance http://jnetpcap.org/

jnetpcap 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 Look at C example next time.

Java jnetpcap For Most Programs written Using jnetpcap First, you need to acquire a list of available network interfaces for working with the live network Pcap.findAllDevs() Second, you need to use one of static open calls found in Pcap class, Pcap.openXXXX() Third, after open call succeeds, do something through return Pcap class instance such as read packets, write packets or acquire some information about network interface Pcap.sendPacket(), Pcap.loop(), Pcap.dispatch()

Java jnetpcap Example program Classic Example Provide a list of devices Presents a simple menu We will select one for the user Using a packet handler, it loops to catch few packets, say 10. Prints some simple info about the packets Closes the pcap handle and exits

Java jnetpcap - Example You need to indicate in jnetpcap which network device you want to listen to API provides Pcap.findAllDevs() class // First get a list of devices on this system int r = Pcap.findAllDevs(alldevs, errbuf); if (r == Pcap.NOT_OK alldevs.isempty()) { } System.err.printf("Can't read list of devices, error is %s", return; errbuf.tostring()); System.out.println ("Network devices found:");

Java jnetpcap // Print the list of devices on this system int i = 0; for (PcapIf device : alldevs) { } String description = (device.getdescription()!= null)? device.getdescription() : "No description available"; System.out.printf("#%d: %s [%s]\n", i++, device.getname(), description); PcapIf device = alldevs.get(0); // We know we have 1 or more device System.out.printf("\nChoosing '%s' on your behalf:\n", (device.getdescription()!= null)? device.getdescription() : device.getname());

Java jnetpcap //Second we open up the selected device int snaplen = 64 * 1024; // Capture all packets, no truncation int flags = Pcap.MODE_PROMISCUOUS; // capture all int timeout = 10 * 1000; // 10 seconds in millis Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf); if (pcap == null) { System.err.printf("Error while opening device for capture: " + errbuf.tostring()); return; }

Java jnetpcap // Third we create a packet handler which will receive packets from the libpcap loop. PcapPacketHandler<String> jpackethandler = new PcapPacketHandler<String>() { public void nextpacket(pcappacket packet, String user) { }; } System.out.printf("Received packet at %s caplen=%-4d len=%-4d %s\n", new Date(packet.getCaptureHeader().timestampInMillis()), packet.getcaptureheader().caplen(), // Length actually captured packet.getcaptureheader().wirelen(), // Original length user ); // Fourth we enter the loop and tell it to capture 10 packets. pcap.loop(10, jpackethandler, "jnetpcap rocks!"); // User supplied object

JPCAP Example The packet output of executing the test class looks like this Network devices found: #0: lo [No description available] #1: any [Pseudo-device that captures on all interfaces] #2: wlan0 [No description available] #3: eth0 [No description available] Choosing 'wlan0' on your behalf: Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=66 len=66 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:19 PST 2017 caplen=1486 len=1486 jnetpcap rocks! Received packet at Sun Feb 26 20:48:20 PST 2017 caplen=1486 len=1486 jnetpcap rocks!

Summary Raw sockets through jnetpcap 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!

References jnetpcap - Examples http://jnetpcap.org/examples/ jnetpcap Tutorial http://jnetpcap.org/tutorial Capturing network packets Blog Windows Example https://compscipleslab.wordpress.com/2013/02/17/capturin g-network-packets-through-java/

Midterm due today.