Scapy. On-the-fly Packet Generation by codemonk@u-sys.org. Dienstag, 10. Januar 12



Similar documents
Python Scripting with Scapy

Ethernet. Ethernet. Network Devices

How do I get to

Network Security TCP/IP Refresher

Internet Architecture and Philosophy

Lecture Computer Networks

ACHILLES CERTIFICATION. SIS Module SLS 1508

Outline. CSc 466/566. Computer Security. 18 : Network Security Introduction. Network Topology. Network Topology. Christian Collberg

IP - The Internet Protocol

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

Overview. Securing TCP/IP. Introduction to TCP/IP (cont d) Introduction to TCP/IP

Overview of TCP/IP. TCP/IP and Internet

8.2 The Internet Protocol

Internet Protocols. Background CHAPTER

Chapter 9. IP Secure

Algorithms and Techniques Used for Auto-discovery of Network Topology, Assets and Services

20-CS X Network Security Spring, An Introduction To. Network Security. Week 1. January 7

TCP/IP Security Problems. History that still teaches

Introduction to Analyzer and the ARP protocol

CYBER ATTACKS EXPLAINED: PACKET CRAFTING

Networks: IP and TCP. Internet Protocol

CSE 127: Computer Security. Network Security. Kirill Levchenko

Stateful Firewalls. Hank and Foo

CSCE 465 Computer & Network Security

Transport Layer. Chapter 3.4. Think about

What is a DoS attack?

2. IP Networks, IP Hosts and IP Ports

TOE2-IP FTP Server Demo Reference Design Manual Rev1.0 9-Jan-15

Network Security. Chapter 3. Cornelius Diekmann. Version: October 21, Lehrstuhl für Netzarchitekturen und Netzdienste Institut für Informatik

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

Subnetting,Supernetting, VLSM & CIDR

Why use Scapy? Blue Team. Red Team. Test IDS/IPS Test Firewall Learn more about TCP/IP (down and dirty) Application response(fuzzing)

Transport Layer Protocols

Internetworking. Problem: There is more than one network (heterogeneity & scale)

Scanning Tools. Scan Types. Network sweeping - Basic technique used to determine which of a range of IP addresses map to live hosts.

Internet Working 5 th lecture. Chair of Communication Systems Department of Applied Sciences University of Freiburg 2004

Technical Support Information Belkin internal use only

NETWORK LAYER/INTERNET PROTOCOLS

Computer Networks/DV2 Lab

Internet Control Protocols Reading: Chapter 3

Interconnection of Heterogeneous Networks. Internetworking. Service model. Addressing Address mapping Automatic host configuration

2. What is the maximum value of each octet in an IP address? A. 28 B. 255 C. 256 D. None of the above

Packet Sniffing and Spoofing Lab

Компјутерски Мрежи NAT & ICMP

Network layer: Overview. Network layer functions IP Routing and forwarding

This tutorial will help you in understanding IPv4 and its associated terminologies along with appropriate references and examples.

Host Fingerprinting and Firewalking With hping

Unix System Administration

Computer Networks/DV2 Lab

Guide to TCP/IP, Third Edition. Chapter 3: Data Link and Network Layer TCP/IP Protocols

Layer Four Traceroute (and related tools) A modern, flexible path-discovery solution with advanced features for network (reverse) engineers

IP address format: Dotted decimal notation:

Procedure: You can find the problem sheet on Drive D: of the lab PCs. 1. IP address for this host computer 2. Subnet mask 3. Default gateway address

Sniffing in a Switched Network

>>> SOLUTIONS <<< c) The OSI Reference Model has two additional layers. Where are these layers in the stack and what services do they provide?

Post-Class Quiz: Telecommunication & Network Security Domain

TCP/IP Fundamentals. OSI Seven Layer Model & Seminar Outline

Introduction to IP networking

Indian Institute of Technology Kharagpur. TCP/IP Part I. Prof Indranil Sengupta Computer Science and Engineering Indian Institute of Technology

Data Communication Networks and Converged Networks

1. LAB SNIFFING LAB ID: 10

Network Packet Analysis and Scapy Introduction

Session Hijacking Exploiting TCP, UDP and HTTP Sessions

Networking Test 4 Study Guide

Safeguards Against Denial of Service Attacks for IP Phones

Zarząd (7 osób) F inanse (13 osób) M arketing (7 osób) S przedaż (16 osób) K adry (15 osób)

OLD VULNERABILITIES IN NEW PROTOCOLS? HEADACHES ABOUT IPV6 FRAGMENTS

Gary Hecht Computer Networking (IP Addressing, Subnet Masks, and Packets)

Mobile IP Network Layer Lesson 02 TCP/IP Suite and IP Protocol

04 Internet Protocol (IP)

Chapter 8 Security Pt 2

Denial Of Service. Types of attacks

Guide to Network Defense and Countermeasures Third Edition. Chapter 2 TCP/IP

RARP: Reverse Address Resolution Protocol

Port Scanning and Vulnerability Assessment. ECE4893 Internetwork Security Georgia Institute of Technology

OSBRiDGE 5XLi. Configuration Manual. Firmware 3.10R

Understanding and Configuring NAT Tech Note PAN-OS 4.1

BASIC ANALYSIS OF TCP/IP NETWORKS

Packet Sniffing on Layer 2 Switched Local Area Networks

CHAPTER. Securing TCP/IP

Defending Computer Networks Lecture 6: TCP and Scanning. Stuart Staniford Adjunct Professor of Computer Science

Understanding Layer 2, 3, and 4 Protocols

Solution of Exercise Sheet 5

Information Security Training. Assignment 1 Networking

ICS 351: Today's plan

Mobile Routing. When a host moves, its point of attachment in the network changes. This is called a handoff.

Attack Lab: Attacks on TCP/IP Protocols

Ethernet and IP A slightly less introductory networking class. Drew Saunders Networking Systems Stanford University

Transport and Network Layer

Internet Firewall CSIS Internet Firewall. Spring 2012 CSIS net13 1. Firewalls. Stateless Packet Filtering

WLAN Attacks. Wireless LAN Attacks and Protection Tools. (Section 3 contd.) Traffic Analysis. Passive Attacks. War Driving. War Driving contd.

RTP / RTCP. Announcements. Today s Lecture. RTP Info RTP (RFC 3550) I. Final Exam study guide online. Signup for project demos

How Does Ping Really Work?

Course Overview: Learn the essential skills needed to set up, configure, support, and troubleshoot your TCP/IP-based network.

Transcription:

Scapy On-the-fly Packet Generation by codemonk@u-sys.org 1

Overview Repetition of network basics Python Basics Scapy Basics Example: SYN Scan Hands-on: Traceroute Promiscuous Scan ARP Spoofing 2

Layers OSI Model Abstraction layers (1) Physical Bit (2) Data link Frames with physical addressing (3) Network Packets and routing (4) Transport Connections (5)... (7) Application 3

Ethernet Layer 2 protocol Frames Uses hardware/mac addresses 4

Internet Protocol Layer 3 protocol Packets Sender and receiver identified by IP, e.g. 123.45.67.89 IP can have special meaning, like 255.255.255.255 - broadcast 5

Internet Protocol 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Version IHL Type of Service Total Length Identification Flags Fragment Offset Time to Live Protocol Header Checksum Source Address Destination Address Options Padding... Payload... rfc 791 6

Address Resolution Protocol Who-is-who for the local network Mapping between layer 2 and 3 addressing 7

Address Resolution Protocol 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Hardware Type Protocol Type HW Addr. Len. Proto. Adr. Len Operation Sender Hardware Address (Octets 0-3) Sender HW Address (Oct. 4-5) Sender IP Address (Oct. 0-1) Sender IP Address (Oct. 2-3) Target HW Address (Oct. 0-1) Target Hardware Address (Octets 2-5) Target IP Address rfc 826 8

Address Resolution Protocol Message examples: ARP Request or where is...? Own IP and MAC are used as sender IP and HW address Searched-for IP is target IP ARP Reply or I am at...? Own IP and MAC are used as sender IP and HW address 9

Transmission Control Protocol Layer 4 protocol Streams/Connections Ensures correct transmission or error 3-Way-Hand-Shake for connection establishment Ports 10

0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Source Port Destination Port Sequence Number Acknowledgment Number Data U A P R S F Offset Reserved R C S S Y I Window G K H T N N Checksum Urgent Pointer Options Padding... Payload... rfc 793 Transmission Control Protocol 11

IP + TCP 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Version IHL Type of Service Total Length Identification Flags Fragment Offset Time to Live Protocol Header Checksum IP Lay.3 Source Address Destination Address Options Padding --------- Source Port Destination Port Sequence Number Acknowledgment Number TCP Lay.4 Data U A P R S F Offset Reserved R C S S Y I Window G K H T N N Checksum Urgent Pointer Options Padding... Payload... 12

Transmission Control Protocol 3-way-hand-shake Ensures Client is actually talking to Server RST signals a closed port 13

Python Basics Indentation with white spaces (thus no {}) Dynamic typing Automatic memory management Interactive shell 14

Python Basics >>> def add(x,y):... return x+y >>> >>> a, b = 1234, 5678 >>> c = add(a, b) >>> >>> if c > 1000:... print 'Big', c... else:... print 'Small', x, y... Big 6912 >>> 15

Python Basics >>> li = ['a','b','c'] >>> # Iterate list... for c in li:... print c.upper()... A B C >>> # More complex boolean operation:... if False or len(li):... print li[2]... c >>> 16

Python Basics >>> list() [] >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> >>> # Getting information on available functions and >>> # objects: >>> help([]) [...] >>> help(str) [...] >>> help(var) [...] >>> 17

Scapy $ sudo scapy Welcome to Scapy (2.1.0) >>> <<<Interactive>>> 18

Workshop SYN Scan Traceroute ARP Spoofing Promiscuous Scan ICMP Chat 19

SYN Scan Simple port scanner 1. Initiate three-way-handshake by sending SYN to victim 2. Get responses (if any) 3. All SYN-ACKs are open ports All RSTs are closed ports No response means down or firewalled 20

SYN Scan ans, uans= sr(...) - Layer 3 packet send/receive ans is a list of send and answered packets uans are the unanswered packets SYN flag in IP is just S 21

SYN Scan p = IP(dst="130.83.177.129")/TCP(dport=[22,80], \ flags="s") ans, uans = sr(p, timeout=5) for s,r in ans: # response is SYN-ACK? if r.flags & 2: print "port",r.sport,"is open" else: print "port",r.sport,"is closed" 22

Traceroute How do my packets travel the world? 1. Send packets with varying time-to-live, usually pings, but TCP SYNs work better 2. Get responses (ICMP time-exceeded) 23

Traceroute ans, uans= sr(..., timeout=123) use timeout to restrict waiting for unanswered packets, in seconds attr=(0, 90) tells scapy to generate 90 packets with attributes 0 to 89 24

Traceroute p = IP(dst="www.google.com",ttl=(0,30))/TCP(flags="S") ans, uans = sr(p, timeout=5) for s,r in ans: print s.ttl, r.src 25

ARP Spoofing Clients use ARP packets to populate their own ARP table, even if they did not ask for it. 1. Get to-be-spoofed IP 2. Send ARP is-at packets to all (broadcast) with to-be-spoofed IP as source. 3. Route received packets (linux can do that for us) 26

ARP Spoofing sendp(...) - Layer 2 packet transmission attribute inter makes scapy wait between packets and loop sends continuesly Broadcast MAC: ff:ff:ff:ff:ff:ff Linux routing can be enabled with: echo 1 > /proc/sys/net/ipv4/ip_forwarding (so others can continue using the internet) 27

ARP Spoofing Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op="is-at", hwsrc=own-mac, psrc=to-be-spoofed-ip) sendp(p, loop=1, inter=1.5) 28

Promiscuous Scan Who is sniffing in my LAN? 1. Send packets with invalid destination MAC to a valid IP 2. Check if that IP answered 3. Other methods exists 29

Promiscuous Scan ans,uans = srp() - Layer 2 Send and Receive ans answered packet tuples uans unanswered packets Possible invalid MAC: f1:ff:ff:ff:ff:f1 30

Promiscuous Scan ans,uans = srp(ether(dst= "f1:ff:ff:ff:ff:f1")/ ARP(pdst=targetnet),timeout=5) if len(ans) > 0: print "The following clients are in promiscuous mode:" for snd,rcv in ans: print rcv.src if type(rcv.payload) == type(arp()): print rcv.payload.psrc else: print rcv.payload.src else: print "Found no promiscuous mode enabled clients" 31

ICMP Chat Use payload of ICMP packets to transport messages use sniff() to receive (see help(sniff) ) 32

ICMP Chat sniff(prn, lfilter) lfilter will be evaluated with each packet, if it returns True, prn will be called def foo(bar): return bar+23 foo would be the same as lambda x: x+23 33

ICMP Chat chatpartner = "192.168.214.123" while 1: line = sys.stdin.readline() send(ip(dst=chatpartner)/icmp(type="echo-request")/ (line.strip()),verbose=0) sniff(prn=lambda x: x.payload.payload.payload.load, lfilter=lambda x: x.haslayer(icmp) and x.payload.dst==chatpartner) 34

Food for Thought Wired networks are boring? Hack WLAN! WLAN is also too boring? Hack GSM! BBosmocom - GSM Stack for python Uses (cheap) mobile phones with custom firmware as radio Missing scapy feature: Connection tracking 35

Questions? Feedback? 36

Thank you! 37