Linux Kernel Backdoors And Their Detection Joanna Rutkowska ITUnderground Conference, October 12 th -13 th 2004, Warsaw.

Slides:



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

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
CS 4700 / CS 5700 Network Fundamentals
Computer Networks20-1 Chapter 20. Network Layer: Internet Protocol 20.1 Internetworking 20.2 IPv IPv6.
© 2004, Joanna Rutkowska, 1 Passive Covert Channels Implementation in Linux Kernel Chaos Communication Congress, December 27.
Covert Channels in TCP and IP Headers Drew Hintz
Hands-On Ethical Hacking and Network Defense Second Edition Chapter 5 Port Scanning.
Traffic Management - OpenFlow Switch on the NetFPGA platform Chun-Jen Chung( ) Sriram Gopinath( )
ITINERANT: TCP Socket Migration Titus Winters Dan Berger CS 202: Spring ‘03.
Internet Control Message Protocol (ICMP). Introduction The Internet Protocol (IP) is used for host-to-host datagram service in a system of interconnected.
The Basics of communication LectureII. Processing Techniques.
Review for Exam 4 School of Business Eastern Illinois University © Abdou Illia, Fall 2006.
Design and Implementation of a Server Director Project for the LCCN Lab at the Technion.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Internet Protocol Version4.
1 Netfilter in Linux Bing Qi Department of Computer Science and Engineering Auburn university.
Gursharan Singh Tatla Transport Layer 16-May
1 Review of Important Networking Concepts Introductory material. This slide uses the example from the previous module to review important networking concepts:
Embedding Covert Channels into TCP/IP
FIREWALL TECHNOLOGIES Tahani al jehani. Firewall benefits  A firewall functions as a choke point – all traffic in and out must pass through this single.
Small Form Computing A bump in the wire. The questions ● What can we do with an inexpensive small computer? ● Can we make it a part of a seamless wireless.
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.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
By Deepthi Reddy Ramya Balakumar Vandana Bhardwaj Simple Packet Filtering Firewall.
Port Scanning 0x470~0x480 Presenter SangDuk Seo 1.
LWIP TCP/IP Stack 김백규.
1 TCP/IP Perversion Rares Stefan, Third Brigade Inc. SecTor 2007.
CIS 450 – Network Security Chapter 16 – Covering the Tracks.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
1 The Internet and Networked Multimedia. 2 Layering  Internet protocols are designed to work in layers, with each layer building on the facilities provided.
Raw Sockets Vivek Ramachandran. A day in the life of Network Packet.
Network Protocols A network protocol defines the structure of messages sent over the network We will only talk about the Internet Network protocols need.
Covert Channels Thomas Arnold CSCI 5235/Summer /12/2010.
Network Programming Eddie Aronovich mail:
Page 1 Jan 5, 1998 CMPN 369 CPSC441 Sockets Module Sockets Application Programming Interface (API)
Network Programming Chapter 5: Raw Socket Programming.
An initial study on Multi Path Routing Over Multiple Devices in Linux 2.4.x kernel Towards CS522 term project By Syama Sundar Kosuri.
TCP/IP Protocol Suite 1 Chapter 8 Upon completion you will be able to: Internet Protocol Understand the format and fields of a datagram Understand the.
Decoding an IP Header (1)
FreeS/WAN & VPN Cory Petkovsek VPN: Virtual Private Network – a secure tunnel through untrusted networks. IP Security (IPSec): a standardized set of authentication.
TCP/IP Protocol Suite 1 Chapter 8 Upon completion you will be able to: Internet Protocol Understand the format and fields of a datagram Understand the.
Advanced Packet Analysis and Troubleshooting Using Wireshark 23AF
CSE 592 INTERNET CENSORSHIP (FALL 2015) LECTURE 22 PHILLIPA GILL - STONY BROOK U.
1 Lecture 13 IPsec Internet Protocol Security CIS CIS 5357 Network Security.
PLUS 내부 세미나 1/22 The Libnet Library 이병영 2004/05/06.
Firewalls A brief introduction to firewalls. What does a Firewall do? Firewalls are essential tools in managing and controlling network traffic Firewalls.
Role Of Network IDS in Network Perimeter Defense.
WLAN Security1 Security of WLAN Máté Szalay
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Covert Channels.
Lecture 21: Network Primer 7/9/2003 CSCE 590 Summer 2003.
Mike Switlick. Overview What is a covert channel? Storage / Timing Requirements Bunratty attack Covert_tcp Questions.
Network Layer Protocols COMP 3270 Computer Networks Computing Science Thompson Rivers University.
Firewalls. Overview of Firewalls As the name implies, a firewall acts to provide secured access between two networks A firewall may be implemented as.
20.1 Chapter 20 Network Layer: Internet Protocol Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Final Project: Advanced Security Blade IPS and DLP blades.
SAMET KARTAL No one wants to share own information with unknown person. Sometimes while sharing something with someone people wants to keep.
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.
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Jimit Mahadevia Nishit Shah This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Internet Protocol Version4
Introduction to Data Link Layer
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
New Solutions For Scaling The Internet Address Space
Internet Protocol Version4
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
UNIX Sockets Outline Homework #1 posted by end of day
FSU CIS 5930 Internet Protocols
Transport Protocols An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
CSE 313 Data Communication
Transport Layer 9/22/2019.
Presentation transcript:

Linux Kernel Backdoors And Their Detection Joanna Rutkowska ITUnderground Conference, October 12 th -13 th 2004, Warsaw

Linux kernel backdoors and their detection. © Joanna Rutkowska, Goals Provide some details about network kernel subsystem in modern Linux kernels, Show potential techniques for implementing hard to detect network backdoors and covert channels, Discuss possible approaches for detection of such malware.

Linux kernel backdoors and their detection. © Joanna Rutkowska, Network Packets Handling (1)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Network Packets Handling (2)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Network Packets Handling (3)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Network Packets Handling (4)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Two important techniques ptype_* handlers Add new protocol handler, which could simply recognize magic packets (SADoor-like) or modify packets’ contents on the fly (passive covert channels) Netfilter hooks Add new NF hook, which could basically do the same things as ptype handler. Also it could circumvent local firewall (since ipfilter is also implemented using NF hooks).

Linux kernel backdoors and their detection. © Joanna Rutkowska, protocol handlers

Linux kernel backdoors and their detection. © Joanna Rutkowska, Key structure: packet_type struct packet_type { unsigned short type;  htons(ether_type) struct net_device *dev;  NULL means all dev int (*func) (...);  handler address void*data;  private data struct list_head list; }; There are two exported kernel functions for adding and removing handlers: void dev_add_pack(struct packet_type *pt) void dev_remove_pack(struct packet_type *pt)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Addition of own handler struct packet_type myproto; myproto.type = htons(ETH_P_ALL); myproto.func = myfunc; myproto.dev = NULL; myproto.data = NULL; dev_add_pack (&myproto)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Passive Covert Channel Example

Linux kernel backdoors and their detection. © Joanna Rutkowska, IP Header and simple CC versionhdr len TOStotal length idfragment offset flags TTLprotocolchecksum source address destination address Simple CC (1 byte per packet)

Linux kernel backdoors and their detection. © Joanna Rutkowska, DEMO: simple passive CC in IPID > : [|tcp] (DF) [tos 0x10] (ttl 64, id 16640, len 100) a ac > : [|tcp] (DF) [tos 0x10] (ttl 64, id 16896, len 52) a0 0a ac > : [|tcp] (DF) [tos 0x10] (ttl 64, id 16640, len 52) a0 0a ac > : [|tcp] (DF) [tos 0x10] (ttl 64, id 16896, len 100) a ac > : [|tcp] (DF) [tos 0x10] (ttl 64, id 16640, len 52) a0 0a ac secret message: ABABA

Linux kernel backdoors and their detection. © Joanna Rutkowska, What is interesting in this simple CC? Kernel implementation (as ptype handler) There is no (easy) way to check what protocol handlers are registered in the kernel(!) Seems like it is hard to detect that we have something like this in our kernel. Of course you can detect this simple CC by network traffic analysis We can imagine more complex CC implemented this way…

Linux kernel backdoors and their detection. © Joanna Rutkowska, Simple places to hide information in HTTP protocol GET bin/board.cgi?view= / HTTP/1.0 Host: User-Agent: Mozilla/5.0 ( ) Accept: text/html Accept-Language: en,fr,en,fr,en,en,en,en Accept-Encoding: gzip,deflate,compress Accept-Charset: ISO ,utf-8,ISO CONNECTION: close Proxy-Connection: close X-Microsoft-Plugin: unexpected error # source:

Linux kernel backdoors and their detection. © Joanna Rutkowska, Digression about more interesting covert channels TCP Timestamps: information hidden in least significant bit of TCP timestamp(!) TCP ISN modulation. Note: unlike most current implementations, when considering passive ISN CC, the handler routine must track the whole TCP connection and change all the sequential numbers in all packets of that connection. It is necessary so that the user will not notice anything suspicious in her connection. ??? All of the above ideas could be implemented as a passive channels using ptype handlers.

Linux kernel backdoors and their detection. © Joanna Rutkowska, TCP Timestamp Covert Channel Idea and the simple implementation: John Giffin i inni, Covert Messaging Through TCP Timestamps, Massachusetts Institute of Technology, Information hidden in LSB of TCP timestamp. Not as easy as it may sound – watch out for turning back in time! Secret shared by the two peers – without the secret it should be impossible to even find out that the communication occur (although the algorithm is known) – seems like real CC, based on theory and not on a “secret concept”.

Linux kernel backdoors and their detection. © Joanna Rutkowska, How to detect? How to get a list of registered protocol handlers? Author does not know any tool (or even kernel API) for doing that! We need to “manually” check the following lists: ptype_all ptype_base But their addresses are not exported!

Linux kernel backdoors and their detection. © Joanna Rutkowska, Where are the protocol lists? Two kernel global variables ( net/core/dev.c ): static struct packet_type *ptype_base[16]; static struct packet_type *ptype_all = NULL; Only the following functions are referencing those variables (i.e. “know” their addresses): Kernel Kernel dev_add_pack() 2.dev_remove_pack() 3.dev_queue_xmit_nit() 4.netif_receive_skb() 1.dev_add_pack() 2.__dev_remove_pack() 3.dev_queue_xmit_nit() 4.netif_receive_skb() 5.net_dev_init() The functions in green are exported.

Linux kernel backdoors and their detection. © Joanna Rutkowska, Approaches for finding the lists System.map file problem: the file is not always up to date or sometimes it does not even exist (for security reasons;)) “heuristic” method We know the addresses of several functions which are using the addresses we are looking for. We can look at their body to find all the 32 bit words which looks like kernel pointers. Then we need to find the common set of those pointer- like words from all functions we consider. At last we need to check every potential value from the common subset to see if it looks like (or could be) ptype_all or ptype_base list head.

Linux kernel backdoors and their detection. © Joanna Rutkowska, Illustration for heuristic method

Linux kernel backdoors and their detection. © Joanna Rutkowska, Live DEMO: detecting additional protocol handlers PTYPE_ALL: hook type ETH_P_ALL (0x3) hook at: 0xc487e060 [module: unknown module] PTYPE_BASE[]: hook type ETH_P_IP (0x800) hook at: 0xc > ip_rcv() [k_core] hook type ETH_P_802_2 (0x4) hook at: 0xc01f8050 [k_core] hook type ETH_P_ARP (0x806) hook at: 0xc > arp_rcv() [k_core]

Linux kernel backdoors and their detection. © Joanna Rutkowska, Lets now talk about Netfilter hooks… Another way of implementing smart backdoors or CCs in kernel is to register NF hook. We’ve seen already some NF hooks on the network map. What is Netfilter exactly?

Linux kernel backdoors and their detection. © Joanna Rutkowska, NF HOOKS

Linux kernel backdoors and their detection. © Joanna Rutkowska, NF HOOKS: ipfilters implementation

Linux kernel backdoors and their detection. © Joanna Rutkowska, Key structure: nf_hook_ops struct nf_hook_ops { struct list_head list; nf_hookfn *hook;  handler address int pf;  family (AF_INET, AF_INET6, AF_IPX,...) int hooknum;  (NF_IP_*, NF_IP6_*, NF_IPX_*,...) int priority; }; There are two exported kernel functions for adding and removing handlers: int nf_register_hook(struct nf_hook_ops *reg); void nf_unregister_hook(struct nf_hook_ops *reg);

Linux kernel backdoors and their detection. © Joanna Rutkowska, Adding new NF hook myhook.hook = myhandler; myhook.pf = PF_INET; myhook.priority = NF_IP_PRI_FIRST; myhook.hooknum = NF_IP_POST_ROUTING; nf_register_hook(&myhook);

Linux kernel backdoors and their detection. © Joanna Rutkowska, Registered NF hooks lists struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS]; AF_UNSPEC(0) AF_UNIX(1) AF_INET(2) AF_AX25(3) AF_IPX(4) AF_APPLETALK(5) NF_IP_PRE_ROUTING (0) NF_IP_LOCAL_IN (1) NF_IP_FORWARD (2) NF_IP_LOCAL_OUT (3) NF_IP_POST_ROUTING(4)

Linux kernel backdoors and their detection. © Joanna Rutkowska, Simple example implementation: bioforge, Hacking the Linux Kernel Network Stack, Phrack Magazine, Issue 61.

Linux kernel backdoors and their detection. © Joanna Rutkowska, How to detect? Fortunately nf_hooks address is exported by all kernels (known to the author) :) Knowing the address of nf_hooks we just need to scan all the hook lists and find the suspicious hooks. Suspicious are for example the ones, which do not belong to any modules address space (since the modules have been hidden or removed by the attacker or the code has been injected through /dev/(k)mem )

Linux kernel backdoors and their detection. © Joanna Rutkowska, Live DEMO: Enumerating Netfilter hooks -- NETFILTER hooks --- INET NF_IP_PRE_ROUTING hooks: hook at: 0xc48583ca [module: unknown module] INET NF_IP_LOCAL_IN hooks: hook at: 0xc [module: iptable_filter] INET NF_IP_FORWARD hooks: hook at: 0xc [module: iptable_filter] INET NF_IP_LOCAL_OUT hooks: hook at: 0xc485409c [module: iptable_filter] INET NF_IP_POST_ROUTING hooks: hook at: 0xc485834a [module: unknown module]

Linux kernel backdoors and their detection. © Joanna Rutkowska, NF Hooks vs. ptype handlers Both techniques allows attacker to implement kernel backdoors quite easily It is much harder to detect backdoors implemented as ptype handlers then NF hooks – we need heuristics to find ptype lists (as it was showed) NF Hooks on the other hand have got some potential advantages of bypassing local IP filters.

Linux kernel backdoors and their detection. © Joanna Rutkowska, Other techniques for implementing backdoors Raw sockets AF_PACKET (used also by tcpdump) AF_INET RAWIP (used also by ping) (Raw) socket can be created by usermode process  we need to hide process & socket kernel code  we need to hide socket Socket hiding against: proc/net/raw, /proc/net/packet Passive CC cannot be implemented using (raw) sockets.

Linux kernel backdoors and their detection. © Joanna Rutkowska, References Linux Kernel Sources, Netfilter Official Documentation, kossak, Building Into The Linux Network Layer, Phrack Magazine, Issue 55, bioforge, Hacking the Linux Kernel Network Stack, Phrack Magazine, Issue 61, Craig H. Rowland, Covert Channels in the TCP/IP Protocol Suite, First Monday, 1996, John Giffin i inni, Covert Messaging Through TCP Timestamps, Massachusetts Institute of Technology, John Giffin, prosty program implementujący ukryty kanał w znacznikach czasowych TCP, Andrew Hintz, Covert Channels in TCP and IP Headers, 2003,

Linux kernel backdoors and their detection. © Joanna Rutkowska, The End