Toasterkit - A NetBSD Rootkit. Anthony Martinez Thomas Bowen http://mrtheplague.net/toasterkit/



Similar documents
Virtual Private Systems for FreeBSD

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

File Management. Chapter 12

Safety measures in Linux

Survey of Filesystems for Embedded Linux. Presented by Gene Sally CELF

An Implementation Of Multiprocessor Linux

Analysis of the Linux Audit System 1

Capability-Based Access Control

Linux Kernel Architecture

Traditional Rootkits Lrk4 & KNARK

Automating Linux Malware Analysis Using Limon Sandbox Monnappa K A monnappa22@gmail.com

Linux Driver Devices. Why, When, Which, How?

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Contents III: Contents II: Contents: Rule Set Based Access Control (RSBAC) 4.2 Model Specifics 5.2 AUTH

FreeBSD Developer Summit TrustedBSD: Audit + priv(9)

Porting Lustre to Operating Systems other than Linux. Ken Hornstein US Naval Research Laboratory April 16, 2010

ADVANCED MAC OS X ROOTKITS

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Introduction. What is an Operating System?

Worms, Trojan Horses and Root Kits

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

NetSpective Logon Agent Guide for NetAuditor

Research and Design of Universal and Open Software Development Platform for Digital Home

Practical Mac OS X Insecurity. Security Concepts, Problems and Exploits on your Mac

An overwhelming majority of IaaS clouds leverage virtualization for their foundation.

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Operating Systems 4 th Class

Red Hat Linux Internals

VICE Catch the hookers! (Plus new rootkit techniques) Jamie Butler Greg Hoglund

Rule Set Based Access Control (RSBAC)

Operating Systems. Notice that, before you can run programs that you write in JavaScript, you need to jump through a few hoops first

1 Posix API vs Windows API

Comparing Virtualization Technologies

Linux Kernel Rootkit : Virtual Terminal Key Logger

Chapter 3 Operating-System Structures

To Java SE 8, and Beyond (Plan B)

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Linux Distributed Security Module 1

CS 416: Opera-ng Systems Design

Xcode Project Management Guide. (Legacy)

Features. The Samhain HIDS. Overview of available features. Rainer Wichmann

Unix/Linux Forensics 1

CS161: Operating Systems

HONEYD (OPEN SOURCE HONEYPOT SOFTWARE)

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

Dynamic VM Monitoring using Hypervisor Probes

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Hacking Database for Owning your Data

Advanced Mac OS X Rootkits. Dino Dai Zovi Chief Scientist Endgame Systems

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Chapter 12 File Management

The Case for SE Android. Stephen Smalley Trust Mechanisms (R2X) National Security Agency

Chapter 12 File Management. Roadmap

Performance Counter. Non-Uniform Memory Access Seminar Karsten Tausche

TELE 301 Lecture 7: Linux/Unix file

Example of Standard API

CPS221 Lecture: Operating System Structure; Virtual Machines

Audit Trail Administration

Operating System Structures

UNISOL SysAdmin. SysAdmin helps systems administrators manage their UNIX systems and networks more effectively.

Networking Operating Systems (CO32010)

GPFS and Remote Shell

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

etpu Host Interface by:

FAME Operating Systems

Using Chroot to Bring Linux Applications to Android

4D Plugin SDK v11. Another minor change, real values on 10 bytes is no longer supported.

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Lab 0 (Setting up your Development Environment) Week 1

Creating a More Secure Device with Windows Embedded Compact 7. Douglas Boling Boling Consulting Inc.

Pattern Insight Clone Detection

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

I/O. Input/Output. Types of devices. Interface. Computer hardware

accf_smtp: FreeBSD kernel protection measures against SMTP DDoS and DoS attacks

The Linux Device File-System

Lab 2 : Basic File Server. Introduction

Encryption Wrapper. on OSX

Development of complex KNX Devices

White Paper. Java Security. What You Need to Know, and How to Protect Yourself

Secure computing: SELinux

Operating System Components

CS222: Systems Programming

Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm

sys socketcall: Network systems calls on Linux

CSE331: Introduction to Networks and Security. Lecture 34 Fall 2006

INSTALL NOTES Elements Environments Windows 95 Users

Chapter 2 System Structures

The System Monitor Handbook. Chris Schlaeger John Tapsell Chris Schlaeger Tobias Koenig

White Paper BMC Remedy Action Request System Security

System Structures. Services Interface Structure

Cloud Computing. Up until now

Incremental Backup Script. Jason Healy, Director of Networks and Systems

Operating system Dr. Shroouq J.

Transcription:

Toasterkit - A NetBSD Rootkit Anthony Martinez Thomas Bowen http://mrtheplague.net/toasterkit/

Toasterkit - A NetBSD Rootkit 1. Who we are 2. What is NetBSD? Why NetBSD? 3. Rootkits on NetBSD 4. Architectural Overview 5. Our contributions 6. Demo 7. Protection 8. Prevention

Who we are - Anthony Martinez Anthony is a system administrator for the New Mexico Institute of Mining and Technology s Computer Center, as well as an undergraduate Computer Science student at the university. He originally proposed the project that evolved into Toasterkit.

Who we are - Thomas Bowen Thomas is a system administrator for the New Mexico Institute of Mining and Technology s Computer Center. He is also enrolled in the Computer Science program with emphasis in Information Assurance.

Why NetBSD? NetBSD is a popular operating system for embedded systems. It is also extremely source-portable, meaning that when written properly, anything targeting the kernel is equally so. This way, the rootkit can work on any NetBSD port! Additionally, NetBSD is something of a research tool new ideas such as Veriexec and the kauth framework a are being worked on in NetBSD, and nobody (else) is targeting them. a Which originated in Mac OS X.

History of Rootkits on NetBSD Chkrootkit hasn t been updated since NetBSD 1.6. We re at 4.0, with 5 soon to be released. If there are any rootkits targeting recent versions of NetBSD, none of them appear to be public.

Overview of NetBSD Architecture Portable across hardware The slogan: Of course it runs NetBSD. Excellent support for cross-building. Architecture of code All of the architecture-dependent pieces are abstracted behind common functions; we don t have to worry about byte order, memory-manager specifics, etc. Loadable Kernel Modules (LKM) Not commonly used, but are enabled by default. It also allows code to infiltrate the kernel ex post facto; security-conscious administrators might disable this. Modules can add syscalls, sysctl nodes, executable formats, filesystem drivers, etc.

Overview of NetBSD Architecture Process security (kauth) The kauth framework acts as a gatekeeper between the kernel s own routines, and is designed to be more fine-grained than the previous UNIX superuser approach of all-or-nothing. The kauth system is used in the construction of other security models. Security models NetBSD supports custom security models. The default model, bsd44, is the standard BSD securelevel and superuser scheme. Also documented in the manual page for secmodel is a sample module allowing users with a uid below 1000 a to bind to the normally-reserved port range below 1024. a This range is generally used for system daemon accounts

What we ve done and how we ve done it Elevated privileges within the kauth framework. Made processes hidden via direct kernel object manipulation Portably removed write-protection from kernel memory areas; required for modifying some kernel tables. Hooked sysctl and ioctl functions in order to hide sockets and modules.

Code Skeleton NetBSD includes example code for kernel modules in /usr/src/sys/lkm/{misc,syscall}/example, and several fully-featured modules in /usr/src/sys/lkm. The sample modules do very little, but provide a skeleton to build other modules on. Specifically, the misc example, originally intended to show how a system call is inserted by hand, can be modified to hook a system call. A sample Makefile is also included, which is simply a call into the already-existing NetBSD build process.

multiprocessor safe. System Calls, hooking System calls are exposed, among other ways, via a global sysent array, though accessing this array is not the standard way of placing a system call. Each element of sysent[] is of type struct sysent, containing information for the userspace number of arguments, size of arguments, flags a, and the function to be called. We can modify existing behavior by changing the function pointer (sysent[n].sy_call) to one of our own design, if done carefully enough. All system calls have a uniform prototype for use in the kernel, and access any userspace arguments indirectly. a As of NetBSD 4.0, the only flag is whether or not the syscall is

Building, loading, using an LKM We use two types of loadable modules: 1. misc modules, which provide no automatic initialization 2. syscall modules, which automatically find the next unused system call number and insert themselves there. The NetBSD build system provides Make targets for loading, unloading, and building the module, no matter what its type. The module system is controlled by ioctl commands on /dev/lkm. This comes into play later, when we are hiding modules.

Privilege Escalation with Kauth The first module is relatively simple. It adds a system call that gives the user escalated privileges. Since NetBSD uses kauth, however, we can t just set the process s User ID to 0 (root) and call it done. Instead, we need to operate within kauth s bounds. The interface is documented in the manual pages, and we use the kauth_cred_dup function on the credentials of process #1 init. Since init shouldn t be running under any restrictions, considering its responsibilities, we considered it a fair process from whom to steal credentials.

Memory protection woes NetBSD requires that a CPU support memory management. Some parts of kernel space are protected against memory writes. This frustrated our immediate efforts to hook functions that weren t designed to be hooked. In general, memory pages can be marked as any combination of readable, writable, and executable. Low-level details are machine-dependent Thankfully, NetBSD provides us with uvm, a virtual-memory system designed at WUSTL, which abstracts memory management. Documented in the manual page for uvm is a function called uvm_map_protect, but calling it has no effect on kernel pages.

Memory Unprotection Removal of write-protection is required to modify certain parts of kernel memory: Character device tables, specifically lkm_cdevsw, are protected against writes. The sysctl tree is similarly marked read-only. Removing this type of write-protection should be done generically so as to maintain cross-platform compatibility: we can t go mucking around in the page tables ourselves. It also turns out that this work has already been done for us: Hidden underneath a #ifdef KGDB in uvm_glue.c, there is a function called uvm_chgkprot. It does what we need, so we copied it.

Hiding modules Modules are easily visible by means of modstat without some way to hide this list, a rootkit is very obvious. modstat and friends operate by way of /dev/lkm, making ioctl calls to load, unload, and request the status of modules. Some way is needed to hook only these ioctl operations, since hooking the actual system call would be far too broad. The functions for device nodes are stored in struct cdevsw variables corresponding to each device: the one for /dev/lkm is named lkm_cdevsw. One of the slots in the structure is the responsible function for ioctl. Inserting a hook function, which returns does not exist whenever the module s name begins with rootkit, only requires unprotecting the memory.

Sysctl sysctl is a tree structure originally from BSD, which was designed to allow an administrator to modify system parameters on-the-fly (without rebuilding the kernel), and is still used for that, but is now also used to report system information. Each node in the tree can either contain a value for the corresponding key or a pointer to a helper function that is to handle processing of that particular branch of the sysctl tree. Node entries are write protected and modification of helper functions is difficult using the documented (sysctl(9)) API.

Sysctl - Hiding network sockets Our solution is to: 1. Scan the sysctl tree, getting to the level above where the function is to be found (using sysctl_locate). 2. Once the helper function node we want to modify is found, unprotect the memory 3. Insert our own hook function, based on the original The user utility netstat accesses open port data via a sysctl helper function. Overriding this function allows us to hide open network ports.

Process hiding Hiding processes is accomplished by way of module implementing a system call that takes the name of a process to hide, and directly removes it from the allproc global kernel list, as well as a few other lists. This doesn t prevent it from getting scheduled and running, since the NetBSD scheduler doesn t operate on processes, instead working at thread granularity. This type of attack is referred to as direct kernel object manipulation.

Demo

Protection - Detecting hooks Using a friendly loadable module, compare function pointer in tables with address of actual function. System call hooks Check sysent table against the addresses of the expected functions; see /usr/src/sys/kern/init_sysent.c. sysctl and ioctl hooks Check specific helper function nodes. A full sweep is a bit more difficult because there is no single source for the correct functions.

Detecting other stuff Detecting kauth We don t think there s a viable solution to this. There are many occasions where kauth_cred_dup is appropriate and correct, so emitting a warning each time it s used would just be noise. Detecting unprotection Again, no easy detection. There isn t a standard utility to display the kernel s memory mapping, but perhaps pmap(1) can be extended to do so.

Prevention The easiest way to prevent against attacks via loadable modules is to rebuild your kernel without options LKM enabled. Loadable modules are not frequently used in NetBSD, but if your system does require one, this might not be a usable solution. Another, though more intrusive, suggestion is to use security levels. Once the system has gone multi-user, kernels compiled without options INSECURE apply a variety of restrictions, including that kernel modules cannot be loaded. Unfortunately, common architectures such as i386/amd64, and mac68k/macppc, default to INSECURE. This also doesn t prevent someone sufficiently clever from loading modules before the securelevel gets raised.

Questions?

References Our primary reference text for this project was Designing BSD Rootkits, by Joseph Kong. Other than that, the NetBSD source code was an excellent asset, as well as being well-documented and clear.