Lecture 3: Stateless Packet Filtering. 2 Agenda 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4.

Slides:



Advertisements
Similar presentations
CS 4700 / CS 5700 Network Fundamentals
Advertisements

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
CSE 333 – SECTION 8 Networking and sockets. Overview Network Sockets IP addresses and IP address structures in C/C++ DNS – Resolving DNS names Demos.
Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
CCNA – Network Fundamentals
FIREWALLS. What is a Firewall? A firewall is hardware or software (or a combination of hardware and software) that monitors the transmission of packets.
CSCI 530 Lab Firewalls. Overview Firewalls Capabilities Limitations What are we limiting with a firewall? General Network Security Strategies Packet Filtering.
Firewalls and Intrusion Detection Systems
J. Wang. Computer Network Security Theory and Practice. Springer 2008 Chapter 7 Network Perimeter Security.
Page: 1 Director 1.0 TECHNION Department of Computer Science The Computer Communication Lab (236340) Summer 2002 Submitted by: David Schwartz Idan Zak.
Tutorial 8 Socket Programming
FIREWALLS & NETWORK SECURITY with Intrusion Detection and VPNs, 2 nd ed. 6 Packet Filtering By Whitman, Mattord, & Austin© 2008 Course Technology.
1 Version 3.0 Module 10 Routing Fundamentals and Subnetting.
Gursharan Singh Tatla Transport Layer 16-May
FIREWALL TECHNOLOGIES Tahani al jehani. Firewall benefits  A firewall functions as a choke point – all traffic in and out must pass through this single.
Introduction to Linux Network 劉德懿
TCP/IP Protocol Suite 1 Chapter 6 Upon completion you will be able to: Delivery, Forwarding, and Routing of IP Packets Understand the different types of.
Data Communications and Networks
Types of Addresses in IPv4 Network Range
IP Addressing Basics LAB 8.
More on the IP Internet Protocol. Internet Layer Process Transport layer process passes EACH TCP segment to the internet layer process for delivery Transport.
Packet Filtering. 2 Objectives Describe packets and packet filtering Explain the approaches to packet filtering Recommend specific filtering rules.
FIREWALL Mạng máy tính nâng cao-V1.
1 Networking (Stack and Sockets API). 2 Topic Overview Introduction –Protocol Models –Linux Kernel Support TCP/IP Sockets –Usage –Attributes –Example.
Operating Systems Chapter 9 Distributed Communication.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 6: Packet Filtering
By Deepthi Reddy Ramya Balakumar Vandana Bhardwaj Simple Packet Filtering Firewall.
I. Basic Network Concepts. I.1 Networks Network Node Address Packet Protocol.
1 The Internet and Networked Multimedia. 2 Layering  Internet protocols are designed to work in layers, with each layer building on the facilities provided.
TCP/IP Protocols Contains Five Layers
Network Programming Eddie Aronovich mail:
EECB 473 DATA NETWORK ARCHITECTURE AND ELECTRONICS PREPARED BY JEHANA ERMY JAMALUDDIN Basic Packet Processing: Algorithms and Data Structures.
Layer 3: Internet Protocol.  Content IP Address within the IP Header. IP Address Classes. Subnetting and Creating a Subnet. Network Layer and Path Determination.
Queues, Pipes and Sockets. QUEUE A structure with a series of data elements with the first element waiting for an operation Used when an element is not.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Introduction to Socket
IP addresses IPv4 and IPv6. IP addresses (IP=Internet Protocol) Each computer connected to the Internet must have a unique IP address.
Chapter 8 Network Security Thanks and enjoy! JFK/KWR All material copyright J.F Kurose and K.W. Ross, All Rights Reserved Computer Networking:
Linux Operations and Administration Chapter Eight Network Communications.
Network Router Security Packeting Filtering. OSI Model 1.It is the most commonly refrenced protocol model. It provides common ground when describing any.
Firewalls A brief introduction to firewalls. What does a Firewall do? Firewalls are essential tools in managing and controlling network traffic Firewalls.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 CNLab/University of Ulsan Chapter 19 Firewalls  Packet Filtering Firewall  Application Gateway Firewall  Firewall Architecture.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
SOCKET PROGRAMMING Presented By : Divya Sharma.
What is a Protocol A set of definitions and rules defining the method by which data is transferred between two or more entities or systems. The key elements.
Introduction to TCP/IP networking
Zero-copy Receive Path in Virtio
The OSI Model and the TCP/IP Protocol Suite
CIT 480: Securing Computer Systems
Introduction to Networking
Net 323: NETWORK Protocols
Chapter 5 Network and Transport Layers
Chapter 4: Access Control Lists (ACLs)
The OSI Model and the TCP/IP Protocol Suite
Transport layer API: Socket Programming
I. Basic Network Concepts
Delivery, Forwarding, and Routing of IP Packets
Chapter 8 Network Perimeter Security
دیواره ی آتش.
Lecture 2: Overview of TCP/IP protocol
Firewall.
Firewalls Chapter 8.
Internet Networking recitation #8
The OSI Model and the TCP/IP Protocol Suite
Session 20 INST 346 Technologies, Infrastructure and Architecture
Review of Internet Protocols Network Layer
Chapter 4: outline 4.1 Overview of Network layer data plane
Presentation transcript:

Lecture 3: Stateless Packet Filtering

2 Agenda 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4 4

3 Agenda 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4 4

4 Linux networking  “Berkeley Sockets” library implemented in 1983 in Unix  In time, become the standard networking interface in Unix and Windows (posix, winsock)  First, a little reminder about how it all works

5 File Descriptor  Abstract indicator for accessing a “file”  Three standard streams:  Every stream (fd) described as a file –Unified API (kobject,inode,fops) for handle different stream’s types  Defined in linux/file.h struct fd { struct file *file; unsigned int flags; };

6 file (pointed from fd)  The file structure holds all the information about a “file” in linux  Includes the f_op to handle operations on the file (read,write,etc)  Holds a pointer to the file’s index node struct file { … const struct file_operations *f_op; f_dentry f_path.dentry; } struct fd

7 Index node - inode  The inode structure used to represent a filesystem object, which can be file, a directory or a socket  We can use SOCKET_I function to get the socket fields from the inode: struct socket *SOCKET_I(struct inode *inode) struct fd

8 BSD socket interface and INET sock  The socket structure holds all the information about the socket –connection, type, state, flags, and most important: sock  sock is a huge struct ( variables). Hold the data of the connection, and a pointer the packet structure – sk_buff struct socket {... struct file *file; struct sock *sk;... }; struct sock {... struct sk_buff head; struct sk_buff next; struct sk_buff tail;... }; struct fd

9 Linux TCP/IP Networking

10 Agenda With Highlight 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4 4

11 Protocol Layer - sk_buff  Defined in include/linux/skbuff.h  The structure which de facto contains the packet (and its data)  We will use it to access the packet data and meta data (layers’ headers) to determine the verdict of the packet according to our stateless rules and/or stateful inspect  The netfilter give us, as an input to its hook functions, a pointer to the current packet’s sk_buff structure hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))

12 Protocol Layer - sk_buff

13 Protocol Layer - sk_buff struct sk_buff { /* These two members must be first. */ struct sk_buff *next; struct sk_buff *prev;... __u16 transport_header; __u16 network_header; __u16 mac_header; /* These elements must be at the end... */ sk_buff_data_t tail; sk_buff_data_t end; unsigned char *head, *data;... };

14 sk_buff – access the headers  How can we access directly to the ip/tcp header?  We can access directly from skb->data –For example:  We can also use preset functions and Linux structures to get directly to important fields protocol = *((__u8 *) (buffer->data + 9)); source_ip = *((unsigned int *)(buffer->data + 12)); dest_ip = *((unsigned int *)(buffer->data + 16)); source_port = ((__be16 *)((unsigned char*) (&(buffer->data[4 * ((((unsigned char*)(buffer->data))[0]) & 0b )]))))[0];

15 sk_buff – access the headers  For example  Choose your method wisely protocol = iphdr->protocol; source_ip = iphdr->saddr; dest_ip = iphdr->daddr; source_port = tcphdr->source; protocol = *((__u8 *) (buffer->data + 9)); source_ip = *((unsigned int *)(buffer->data + 12)); dest_ip = *((unsigned int *)(buffer->data + 16)); source_port = ((__be16 *)((unsigned char*) (&(buffer->data[4 * ((((unsigned char*)(buffer->data))[0]) & 0b )]))))[0];

16 Access the headers  So how do we set those headers?  Same for tcphdr  Each layer got the same macro with the same variable //from include/linux/ip.h static inline struct iphdr *ip_hdr(const struct sk_buff *skb) { return (struct iphdr *)skb_network_header(skb); } //from include/linux/skbuff.h static inline unsigned char *skb_network_header(const struct sk_buff *skb) { return skb->head + skb->network_header; } __u16 transport_header; __u16 network_header; __u16 mac_header;

17 IP address structure  IP address as we know it:  What does it means?  When we realize what it is, we can easily convert and compare it to whatever we want.

18 Subnet mask  IP address is logically divided to two parts: –Network prefix. –Host identifier.  All host in the same network have the same network prefix

19 Network prefix length

20 Network prefix length translation

21 IP address as integer  In our system, the IP is represented as an integer.  For example: ==  How to calculate? * 256³ + * 256² + * * = * 1 + * 256 +* 256² +* 256³ Host (LSB): = Network (MSB):

22 Endianness  In different architectures, there’s a different order between the LSB (least significant byte) and the MSB (most significant byte)  In particular, network structures use Big-Endian order, and x86 machines (like our VMs) use Little-Endian order.  In order to be able to transfer data between the network and the machine, we will use the following functions: –u_long htonl(u_long); // host to network long (32 bits) –u_short htons(u_short); // host to network short (16 bits) –u_long ntohl(u_long); // network to host long (32 bits) – u_short ntohs(u_short); // network to host short (16 bits )

23 Agenda With Highlight 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4 4

24 Stateless packet filtering  How packets are transferred in the web? Host A Router 3 Host B Router 2 Router 1 Application TCP/UDP IP MAC Application TCP/UDP IP MAC IP MAC IP MAC IP MAC

25 Stateless packet filtering  The idea behind stateless packet filtering Application TCP/UDP IP MAC Application TCP/UDP IP MAC TCP/UDP IP MAC Stateless packet filtering check for fields in the IP and TCP/UDP layers

26 Stateless packet filtering  Stateless packet filtering scans each packet which go through it –Decides if accept it or drop it. –The verdict is based on a static rule table.  The network administrator will write rules in accordance to the company policy.  Includes the fields: –Source and destination address –Protocol –Source and destination ports –Ack bit –Direction –verdict IP header TCP/UDP header TCP header

27 Stateless packet filtering  Rules for example RuleDiractionSource Addr Dest. Addr ProtocolSource Port Dest. Port AckAction Spoof1InInternalAny Drop Spoof2OutExternalAny Drop Telnet1OutInternalAnyTCP>102323AnyAccept Telnet2InAnyInternalTCP23>1023YesAccept DefaultAny Drop

28 The rule table  Stateless packet filtering check each packet against the rule table.  The packet’s internet and transport layers are being examined –Checking rules from top to bottom –Each packet is individual  The packet acts according to the first matching rule (accept or drop)  A default rule drops/accepts all packets

29 The ACK bit  Only relevant for TCP  In each TCP session, the first packet is the one who initiate the session and it has the ACK set to 0 –All the following packets in the session has the Ack bit set to 1  Therefore, a packet with ACK = 0 is trying to initiate connection.  A common policy is to drop incoming packets with ACK = 0 –Prevent outside computers from initiating connections to the private network

30 Agenda With Highlight 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4 4

31 About assignment 3  In this assignment you would start to create your true firewall  The first step would be to think how to enforce rules –Make sure you can access the data and have a way to reach the important fields –Check the Internet for examples.  You need to make sure you can work with an interface –For the Rules device: create and use Sysfs devices which would handle the rules table. –For the Log device: due to large amount of data, Sysfs can’t be used for this device. Therefore you should use fileop struct and implement the relevant functions (.open,.read/write etc.)  Start the assignment early, it could take some time to get use to handle packets  We’re here for everything you need