Module 2
Module 2
Pramod Subramanyan
1
Acknowledgements
• Sandeep Shukla (IIT Kanpur)
• Dan Boneh (Stanford University)
• John C. Mitchell (Stanford University)
• Nicolai Zeldovich (MIT)
• Jungmin Park (Virginia Tech)
• Patrick Schaumont (Virginia Tech)
• C. Edward Chow
• Arun Hodigere
• Web Resources
2
Three Types of Security Policies
• Confidentiality
Information flow policies
• Integrity
• Availability
Sometimes called the CIA triad
[Anderson, 1972] [Saltzer and Schroeder, 1975]
3
Goals of Confidentiality Policies
4
How does access control work?
int *ptr = 0x12345678;
*ptr = 12345678;
6
Discretionary Access Control (DAC)
8
Problems with DAC (2/3)
9
Problems with DAC (3/3)
10
Mandatory Access Control (MAC)
• Mechanism where system control access to an object
and a user cannot alter that access.
• Defined by three major properties:
– Administratively-defined security policy
– Control over all subjects (process) and objects (files,
sockets, network interfaces)
– Decisions based on all security-relevant info
• MAC access decisions are based on labels that
contains security-relevant info
Example: SELinux
11
What Can MAC Offer?
12
ISOLATION
THE CONFINEMENT PRINCIPLE
13
Running untrusted code
– honeypots
14
Approach: confinement
Confinement: Ensure misbehaving app cannot harm rest of system
app 1 app 2
⇒
Network 2 air gap network 1
Resource Expensive
15
Approach: confinement
Confinement: ensure misbehaving app cannot harm rest of system
app1 app2
OS1 OS2
process 2
container
Operating System
process 1
process 2
Operating System
19
Implementing confinement
Key component: reference monitor
– Mediates requests from applications
• Implements protection policy
• Enforces isolation and confinement
– Tamperproof:
• Reference monitor cannot be killed
• … or if killed, then monitored process is killed too
Reference
Subject Object
Monitor
Op response Op response
Principles:
1. Complete Mediation: monitor must always be invoked
2. Tamper-proof: monitor cannot be changed by adversary
3. Verifiable: reference monitor is small enough to
thoroughly understand, test, and ultimately, verify.
21
Reference Monitors in Practice
• Who is mediating what?
– For isolation through VMs
– For isolation through containers
– For isolation through system call interposition
• How do we ensure complete mediation?
• How do we ensure tamper proofing?
22
A Detour
• A few words about Unix User IDs and IDs
associated with Unix Processes
23
Principals and Subjects
• A subject is a program
(application) executing on
behalf of some principal(s)
• A principal may at any time be
idle, or have one or more
subjects executing on its behalf
What are subjects in UNIX?
What are principals in UNIX?
24
Objects
• An object is anything on which a subject can perform
operations (mediated by rights)
• Usually objects are passive, for example:
• File
• Directory (or Folder)
• Memory segment
• But, subjects can also be objects, with operations
• kill
• suspend
• resume
25
Basic Concepts of UNIX Access Control: Users,
Groups, Files, Processes
• Each user account has a unique UID
– The UID 0 means the super user (system admin)
• A user account belongs to multiple groups
• Subjects are processes
– associated with uid/gid pairs, e.g., (euid, egid),
(ruid, rgid), (suid, sgid)
• Objects are files
26
Users and Principals
USERS PRINCIPALS
27
Users and Principals
• There should be a one-to-many
mapping from users to principals
• a user may have many principals, but
• each principal is associated with an
unique user
• This ensures accountability of a user's
actions
What does the above imply in UNIX?
28
Organization of Objects
• Almost all objects are modeled as files
– Files are arranged in a hierarchy
– Files exist in directories
– Directories are also one kind of files
• Each object has
– owner
– group
– 12 permission bits
• rwx for owner, rwx for group, and rwx for others
• suid, sgid, sticky
29
UNIX
inodes:
Each file
corresponds
to an inode
30
Basic Permissions Bits on Files
• Read controls reading the content of a file
– i.e., the read system call
• Write controls changing the content of a file
– i.e., the write system call
• Execute controls loading the file in memory
and execute
– i.e., the execve system call
31
Execution of a file
• Binary file vs. script file
• Having execute but not read, can one run a
binary file?
• Having execute but not read, can one run a
script file?
• Having read but not execute, can one run a
script file?
32
Permission Bits on Directories
33
The suid, sgid, sticky bits
suid sgid sticky bit
35
The Three sets of permission bits
• Intuition:
– if the user is the owner of a file, then the r/w/x
bits for owner apply
– otherwise, if the user belongs to the group the file
belongs to, then the r/w/x bits for group apply
– otherwise, the r/w/x bits for others apply
36
Other Issues On Objects in UNIX
• Accesses other than read/write/execute
– Who can change the permission bits?
• The owner can
– Who can change the owner?
• Only the superuser (why?)
• Rights not related to a file
– Affecting another process
– Operations such as shutting down the system,
mounting a new file system, listening on a low port
• traditionally reserved for the root user
37
Subjects vs. Principals
38
Process User ID Model in Modern UNIX
Systems
• Each process has three user IDs
– real user ID (ruid) owner of the process
– effective user ID (euid) used in most access
control decisions
– saved user ID (suid)
• and three group IDs
– real group ID
– effective group ID
– saved group ID
39
Process User ID Model in Modern UNIX
Systems
40
The Need for suid/sgid Bits
41
What’s the deal with passwords?
42
What does sudo do?
45
Changing effective user IDs
• A process that executes a set-uid program can
drop its privilege; it can
– drop privilege permanently
• removes the privileged user id from all three user IDs
– drop privilege temporarily
• removes the privileged user ID from its effective uid but
stores it in its saved uid, later the process may restore
privilege by restoring privileged user ID in its effective
uid
46
Access Control in Early UNIX
• A process has two user IDs: real uid and
effective uid and one system call setuid
• The system call setuid(id)
– when euid is 0, setuid set both the ruid and the
euid to the parameter
– otherwise, the setuid could only set effective uid
to real uid
• Permanently drops privileges
• A process cannot temporarily drop privilege
Setuid Demystified, In USENIX Security ‘ 02
47
System V
• Added saved uid & a new system call
• The system call seteuid
– if euid is 0, seteuid could set euid to any user ID
– otherwise, could set euid to ruid or suid
• Setting to ruid temporarily drops privilege
• The system call setuid is also changed
– if euid is 0, setuid functions as seteuid
– otherwise, setuid sets all three user IDs to real uid
48
BSD
• Uses ruid & euid, change the system call from
setuid to setreuid
– if euid is 0, then the ruid and euid could be set to
any user ID
– otherwise, either the ruid or the euid could be set
to value of the other one
• enables a process to swap ruid & euid
49
Modern UNIX
• System V & BSD affect each other, both
implemented setuid, seteuid, setreuid, with
different semantics
– some modern UNIX introduced setresuid
• Messy, complicated, inconsistent, and buggy
– POSIX standard, Solaris, FreeBSD, Linux
– Linux introduced an fsuid as well
– Bug in Linux led to fsuid = 0 even after dropping
other privileges
50
Readings for This Lecture
• Wiki
• Filesystem Permissions
• Other readings
• Chapter 4 of Advanced
Programming in the Unix
Environment
• Unix file permissions
• http://www.unix.com/tips-
tutorials/19060-unix-file-
permissions.html
52
PRIVILEGE SEPARATION
53
Principle of Least Privilege (PoLP)
• Restrict privileges to only those required for
the operation being performed
• Enforcing PoLP requires privilege separation
• Example in logmsg:
– We only need to have euid privileges for open
– Can (and must) give them up after opening file
• Syscall: setreuid(ruid, euid)
– ruid and euid can be set to either real/eff uid
54
An old example: chroot
Often used for “guest” accounts on ftp sites
To use do: (must be root)
58
Jailkit
Problem: all utility progs (ls, ps, vi) must live inside jail
• jailkit project: auto builds files, libs, and dirs needed in jail env
• jk_init: creates jail environment
• jk_check: checks jail env for security problems
• checks for any modified programs,
• checks for world writable directories, etc.
https://olivier.sessink.nl/jailkit/
59
Escaping from jails
Early escapes: relative paths
open( “../../etc/passwd”, “r”)
open(“/tmp/guest/../../etc/passwd”, “r”)
62
Freebsd Jail
Stronger mechanism than simple chroot
63
Problems with chroot and jail
Coarse policies:
– All or nothing access to parts of file system
– Inappropriate for apps like a web browser
• Needs read access to files outside jail
(e.g. for sending attachments in Gmail)
64
What have we learned so far? (1/2)
65
What have we learned so far? (2/2)
• Traditional way of implementing isolation
– Process isolation provided by Unix/Linux
• Relies on four links in the chain
– Many operations restricted to superuser/root
– Users are identified by UID (UID=0 means root)
– Kernel tracks current process UID and enforces
permissions for various objects (files, sockets, etc.)
– Change of uid can happen in only a few ways
66
Ways to Change UID
67
A lot of this is ancient technology
• Unix its permissions, uids, etc. date to the 70s
• It has obvious problems
– Coarse grained user differentiation
(only two levels: root/not root)
– Unbounded privilege escalation
(once you are root, you have won)
– Coarse grained permissions
(can either read or not read, write or not write)
– Coarse grained system control
(can’t precisely control what syscalls are allowed)
68
In the rest of this module
69
CONTAINERS
70
Approach: confinement
Confinement: Create a lightweight container for each application
– Container: Has process + all libraries needed for it
– Users inside container may have more rights than outside
process 2
container
Operating System
72
Three system calls
• clone
– Create a new process in a new namespace
• unshare
– Take an old process into a new namespace
• setns
– Put an old process inside an existing namespace
73
Where do the namespaces live?
/proc/PID/ns directory
$ ls –l /proc/self/ns
total 0
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 cgroup -> cgroup:[4026531835]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 mnt -> mnt:[4026531840]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 net -> net:[4026531993]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 pid -> pid:[4026531836]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 pid_for_children -> pid:[4026531836]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 user -> user:[4026531837]
lrwxrwxrwx 1 spramod spramod 0 Sep 9 10:19 uts -> uts:[4026531838]
74
So how to use namespaces
• Use system calls to create new namespaces
• This can isolate:
– Mounted drives
– Hostname
– Network
– Users and groups
– Etc.
• Even if program is compromised, it doesn’t
have access to the entire system
75
Isolation via namespaces
p1 p2
uid=0 uid=1000
uid=1000 uid=2000
Namespace
Actual System
76
NAMESPACE API DEMO
77
What do Docker etc. do?
• Provide nice command interface and API
• Internally call Linux namespace/cgroups API
• Provide features for packaging applications
– This is mainly a business feature
– Claim is that docker makes it easier to deploy apps
System Call
Interposition
81
System call interposition
Observation: to damage host system (e.g. persistent changes)
app must make system calls:
– To delete/overwrite files: unlink, open, write
– To do network attacks: socket, bind, connect, send
Implementation options:
– Completely kernel space (e.g. GSWTK) -- security extension
architecture
– Completely user space (e.g. program shepherding)
– Hybrid (e.g. Systrace, seccomp)
82
Initial implementation (Janus)
[GWTB’96]
user space
monitored
application monitor
(browser)
open(“/etc/passwd”, “r”)
Monitor kills application if request is disallowed
OS Kernel
83
Complications cd(“/tmp”)
open(“passwd”, “r”)
84
Problems with ptrace
Ptrace is not well suited for this application:
– Trace all system calls or none
inefficient: no need to trace “close” system call
– Monitor cannot abort sys-call without killing app
proc 2: me ⟶ /etc/passwd
not atomic
OS executes open(“me”)
Interception in
Interception
kernel or userland
syscall response
Policy decision in
Kernel kernel or userland?
86
Syscall Interposition: Ptrace
Do we trace all
Untrusted Process syscalls or only
some? ALL
syscall response
Interception in
Interception
kernel or userland?
syscall response Kernel
Policy decision in
Kernel kernel or userland?
Userland
87
Alternate design: systrace [P’02]
user space
monitored
application monitor policy file
(browser) for app
open(“etc/passwd”, “r”)
sys-call systrace
gateway
permit/deny
OS Kernel
• systrace only forwards monitored sys-calls to monitor (efficiency)
Interception in
Interception
kernel or userland?
syscall response Kernel
Policy decision in
Kernel kernel or userland?
Userland
89
Systrace Policies
A simple policy for the ls binary. If ls attempts to list files in /etc,
Systrace disallows the access and /etc does not seem to exist. Listing
the contents of /tmp works normally, but trying to ls /var generates a
warning.
Policy: /bin/ls, Emulation: native native-munmap: permit
[...] native-stat: permit
native-fsread: filename match "/usr/*" then permit
native-fsread: filename eq "/tmp" then permit
native-fsread: filename eq "/etc" then deny[enotdir]
native-fchdir: permit
native-fstat: permit native-fcntl: permit
[...] native-close: permit
native-write: permit
native-exit: permit
90
Policy
Sample policy file:
path allow /tmp/*
path deny /etc/passwd
network deny all
92
Ostia: a delegation architecture
[GPR’04]
user space
monitored
agent
application policy file
for app
open(“etc/passwd”, “r”)
OS Kernel93
Syscall Interposition: Ostia
Do we trace all
Untrusted Process syscalls or only
some? Some
syscall response
Interception in
Interception
kernel or userland?
syscall response Userland
Policy decision in
Kernel kernel or userland?
Userland
94
Ostia: a delegation architecture
[GPR’04]
95
Syscall Interposition: Problems
• Problems with systrace
– Many subtle race conditions between processing
being monitored and monitor process
– This is despite the great pains systrace et al. go to
prevent race conditions
– e.g., “Exploiting concurrency vulnerabilities in
system call wrappers” by R. N. M. Watson
• Problems with Ostia
– Delegation is inherently slow and wasteful
96
Syscall Interposition: Problems (contd)
• Interposition frameworks are C programs
• They themselves had buffer overflow vulns
– Disastrous consequences
– Security is worse than no syscall interposition!
• Spurt of papers from 2004 onwards, but sort
of died down around 2010 due to the above
problems
97
But then comes 2014
98
seccomp
• Yet another syscall filtering platform
• Filtering is done using BPF
• What is BPF?
– A small programming language
– Programs come from userspace
– But executed in kernel (what are the dangers?)
– Verifier ensures programs do only allowed things
– No loops (why?), no uninitialized reads (why?)
99
Seccomp Example Code
• https://gist.github.com/fntlnz/08ae20befb91b
efd9a53cd91cdc6d507
100
Software Fault
Isolation
Isolating components
within a single program
101
Component Isolation
Browser
• Want game to not
Game Website
able to read/write
Restricted interface bank data
Bank Website • Shouldn’t modify or
invoke browser
Browser Data internal functions or
and Code
make syscalls directly
102
Component Isolation using SFI
Ensure compiled
module has no Rewrite binary at
syscalls, unchecked execute time
load/stores, etc.
105
At a high-level SFI means
106
I got x86 Problems
• mov edx, 0xC23BCB50 ; ba 50 cb 3b c2
• But 50 cb 3b c2 is:
– push eax
– return
– cmp ...
• X86 opcodes range in length from 1 to 15 bytes
• There are a lot of prefixes
– They modify the meaning of the next opcode
– Examples: REP, REPNE, LOCK etc.
107
Things to worry about
108
NativeClient
Native Client: A Sandbox for Portable, Untrusted
x86 Native Code, IEEE SP 2009
109
NaCl: a modern day example
Browser game
PPAPI
HTML
JavaScript
NaCl runtime
• Two sandboxes:
– outer sandbox: restricts capabilities using system call
interposition
Runtime
Runtime
112
Segment Registers on x86
• A relic of the days when paging was too
expensive
• X86 has 6 segment registers: CS, DS, SS, ES, FS, GS
• In the old days:
– mov [bx], 0xffff
– Effective address = ds*16 + bx
– Store 0xffff at effective address
• In the new days (i.e., post 1985 or so):
– A bit more complex, see next slide
113
X86 Protected Mode Segmentation
http://ece-research.unm.edu/jimp/310/slides/micro_arch2.html
114
OK, what is the point of all this?
• Can set segment register values in user mode
115
NaCl Compilation
116
nacljmp Pseudoinstruction
nacljmp eax is transformed to
and eax, 0xFFFFFFE0
jmp [eax]
117
NaCl Validator
• Disassembles NEXE to make sure no bad instrs in it
• Starts are 32b aligned entry point
• Exits if any blacklisted instructions are found
– Privileged instructions (mov cr3, etc.)
– Modifications to segment registers
– ret, sysenter, prefix bytes
– Ensures all branches to 32b aligned address
118
NaCl Runtime
119
Summarizing NaCl
120
Bonus: NaCl Bug
and edx, 0xffffffe0
call [edx]
121
Program Shepherding: Strawman
Fetch
Instruction
• Idea: interpret each
Syscall? Load/store? instruction
• Check if instruction is
Check eff. addr is doing something
params legal?
disallowed by policy
Other instructions
• If so, kill program
• If not, update state
Execute according to instruction
Instruction
semantics
Kill Program
122
Strawman: Pros and Cons
Fetch
Instruction
Pros
Syscall? Load/store? • No disassembly
problems
Check eff. addr is • Can strictly enforce
params legal?
policy
Other instructions
Cons
Execute
• Extremely slow
Instruction • Execute 10s/100s of
machine instr for each
target instr
Kill Program
123
Dynamic Binary Translation
to the Rescue!
124
Program Shepherding
Restricting Least restrictive Most restrictive
Code origins Any Dynamically writ- ten Only code from disk, Only code from disk,
code, if self- contained can be dynamically originally
and no loaded loaded
system calls
Function Any Only to after Direct call targeted by Random xor as in Return only from
returns calls only one return StackGhost [14] called function
Intra-segment Any Only to function entry points (if have symbol Only to bindings given
call or jump table) in an interface list
Inter-segment Any Only to export of tar- Only to import of Only to bindings given
call or jump get segment source segment in an interface list
125
Isolation
Isolation via
Virtual Machines
126
Virtual Machines
VM2 VM1
Apps Apps
Guest OS 2 Guest OS 1
Virtual Machine Monitor (VMM)
Host OS
Hardware
129
Types of VMs
app1 app1 app1
app3
app2 app2 app2
app1
app3 app3
app2
Guest OS
app4
OS 1 OS 2 VMM app5
VMM Host OS
Hardware Hardware
Type I Type II
130
Type I VMM Strawman
Strawman implementation
• VMM becomes the OS
• OS is a regular user-space application
Slide #134
Topics
Rootkits
– User-mode Rootkits
– Kernel Rootkits
– Detecting Rootkits
– Recovery from a Rootkit
Slide #135
What is a rootkit?
Collection of attacker tools installed after
an intruder has gained access
– Log cleaners
– File/process/user hiding tools
– Network sniffers
– Backdoor programs
Slide #136
Rootkit Goals
1. Remove evidence of original attack and activity
that led to rootkit installation.
2. Hide future attacker activity (files, network
connections, processes) and prevent it from being
logged.
3. Enable future access to system by attacker.
4. Install tools to widen scope of penetration.
5. Secure system so other attackers can’t take control
of system from original attacker.
Slide #137
Concealment Techniques
• Remove log and audit file entries.
• Modify system programs to hide attacker files,
network connections, and processes.
• Modify logging system to not log attacker
activities.
• Modify OS kernel system calls to hide attacker
activities.
Slide #138
Installation Concealment
• Use a subdirectory of a busy system directory like
/dev, /etc, /lib, or /usr/lib
• Use dot files, which aren’t in ls output.
• Use spaces to make filenames look like expected dot
files: “. “ and “.. “
• Use filenames that system might use
– /dev/hdd (if no 4th IDE disk exists)
– /usr/lib/libX.a (libX11 is real Sun X-Windows)
• Delete rootkit install directory once installation is
complete.
Slide #139
Attack Tools
• Network sniffer
– Including password grabber utility
• Password cracker
• Vulnerability scanners
• Autorooter
– Automatically applies exploits to host ranges
• DDOS tools
Slide #140
History of Rootkits
Slide #141
History of Rootkits
Slide #142
Rootkit Types
User-mode Rootkits
– Binary Rootkits replace user programs.
• Trojans: ls, netstat, ps
• Trojan backdoors: login, sshd.
– Library Rootkits replace system libraries.
• Intercept lib calls to hide activities and add
backdoors.
Kernel Rootkits
– Modify system calls/structures that all user-mode
programs rely on to list users, processes, and sockets.
– Add backdoors to kernel itself.
Slide #143
Binary Rootkits
• Install trojan-horse versions of common
system commands, such as ls, netstat, and ps
to hide attacker activities..
• Install programs to edit attacker activity from
log and accounting files.
• Install trojan-horse variants of common
programs like login, passwd, and sshd to
allow attacker continued access to system.
• Install network sniffers.
Slide #144
Linux Root Kit (LRK) v4 Features
chsh Trojaned! User->r00t
crontab Trojaned! Hidden Crontab Entries
du Trojaned! Hide files
fix File fixer!
ifconfig Trojaned! Hide sniffing
inetd Trojaned! Remote access
linsniffer Packet sniffer!
login Trojaned! Remote access
ls Trojaned! Hide files
netstat Trojaned! Hide connections
passwd Trojaned! User->r00t
ps Trojaned! Hide processes
rshd Trojaned! Remote access
sniffchk Program to check if sniffer is up and running
syslogd Trojaned! Hide logs
tcpd Trojaned! Hide connections, avoid denies
top Trojaned! Hide processes
wted wtmp/utmp editor!
z2 Zap2 utmp/wtmp/lastlog eraser!
Slide #145
Linux Root Kit (LRK) v4 Trojans
ifconfig – Doesn’t display PROMISC flag when sniffing.
login – Allows login to any account with the rootkit password.
If root login is refused on your terminal login as "rewt".
Disables history logging when backdoor is used.
ls – Hides files listed in /dev/ptyr. All files shown with 'ls -/' if
SHOWFLAG enabled.
passwd – Enter your rootkit password instead of old password
to become root.
ps – Hides processes listed in /dev/ptyp.
rshd – Execute remote commands as root: rsh -l
rootkitpassword host command
syslogd – Removes log entries matching strings listed in
/dev/ptys.
Slide #146
Binary Rootkit Detection
Use non-trojaned programs
– ptree is generally uncompromised
– tar will archive hidden files, the list with -t
– lsof is also generally safe
– Use known good tools from CD-ROM.
File integrity checks
– tripwire, AIDE, Osiris
– rpm –V –a
– Must have known valid version of database offline or
attacker may modify file signatures to match Trojans.
Slide #147
Library Rootkits
• t0rn rootkit uses special system library
libproc.a to intercept process information
requested by user utilities.
• Modify libc
– Intercept system call data returning from kernel,
stripping out evidence of attacker activities.
– Alternately, ensure that rootkit library providing
system calls is called instead of libc by placing it in
/etc/ld.so.preload
Slide #148
Kernel Rootkits
Kernel runs in supervisor processor mode
– Complete control over machine.
Rootkits modify kernel system calls
– execve modified to run Trojan horse binary for some
programs, while other system calls used by integrity
checkers read original binary file.
– setuid modified to give root to a certain user.
Advantage—Stealth
– Runtime integrity checkers cannot see rootkit changes.
– All programs impacted by kernel Trojan horse.
– Open backdoors/sniff network without running
processes.
Slide #149
Types of Kernel Rootkits
Loadable Kernel Modules
– Device drivers are LKMs.
– Can be defeated by disabling LKMs.
– ex: Adore, Knark
Alter running kernel in memory.
– Modify /dev/kmem directly.
– ex: SucKit
Alter kernel on disk.
Slide #150
Kernel Rootkit Detection
List kernel modules
– lsmod
– cat /proc/modules
Examine kernel symbols (/proc/kallsyms)
– Module name listed in [] after symbol name.
Slide #151
Kernel Rootkit Detection
Check system call addresses
– Compare running kernel syscall addresses with
those listed in System.map generated at kernel
compile.
All of these signatures can be hidden/forged.
Slide #152
Knark (circa 2004)
• Linux-based LKM rootkit
• Features
– Hide/unhide files or directories
– Hide TCP or UDP connections
– Execution redirection
– Unauthenticated privilege escalation
– Utility to change UID/GID of a running process.
– Unauthenticated, privileged remote execution daemon.
– Kill –31 to hide a running process.
• modhide: assistant LKM that hides Knark from
module listing attempts.
Slide #153
Lots of Open Source Rootkits Now
154
Rootkit Detection
Offline system examination
– Mount and examine disk using another OS
kernel+image.
– Knoppix: live CD linux distribution.
Computer Forensics
– Examine disk below filesystem level.
– Helix: live CD linux forensics tool.
Slide #155
Rootkit Detection Utilities
chkrootkit
– Detects >50 rootkits on multiple UNIX types.
– Checks commonly trojaned binaries.
– Examines log files for modifications.
– Checks for LKM rootkits.
– Use –p option to use known safe binaries from CDROM.
carbonite
– LKM that searches for rootkits in kernel.
– Generates and searches frozen image kernel process
structures.
Slide #156
Detection Countermeasures
• Hide rootkit in unused sectors or in unused
fragments of used sectors.
• Install rootkit into flash memory like PC BIOS,
ensuring that rootkit persists even after disk
formatting and OS re-installation.
Slide #157
Rootkit Recovery
• Restore compromised programs from backup
– Lose evidence of intrusion.
– Did you find all the trojans?
• Backup system, then restore from tape
– Save image of hard disk for investigation.
– Restore known safe image to be sure that all
trojans have been eliminated.
– Patch system to repair exploited vulnerability.
Slide #158
Key Points
• Backdoors allow intruder into system without using
exploit again.
• Rootkits automatically deeply compromise a system
once root access is attained.
• Rootkits are easy to use, difficult to detect.
• Don’t trust anything on a compromised system—
access disk from a known safe system, like an
Ubuntu Live CD.
• Recovery requires a full re-installation of the OS
and restoration of files from a known good backup.
Slide #159
References
1. Oktay Altunergil, “Scanning for Rootkits,”
http://www.linuxdevcenter.com/pub/a/linux/2002/02/07/rootkits.html, 2002.
2. Silvio Cesare, “Runtime kernel kmem patching,” http://vx.netlux.org/lib/vsc07.html, 1998.
3. William Cheswick, Steven Bellovin, and Avriel Rubin, Firewalls and Internet Security, 2nd edition, 2003.
4. Anton Chuvakin, “An Overview of UNIX Rootkits,” iDEFENSE whitepaper, 2003.
5. Dave Dittrich, “Rootkits FAQ,” http://staff.washington.edu/dittrich/misc/faqs/rootkits.faq, 2002.
6. Greg Hoglund and Gary McGraw, Exploiting Software: How to Break Code, Addison-Wesley, 2004.
7. Samuel T. King et. al., “SubVirt: Implementing malware with virtual machines”,
http://www.eecs.umich.edu/virtual/papers/king06.pdf, 2006.
8. McClure, Stuart, Scambray, Joel, Kurtz, George, Hacking Exposed, 3rd edition, McGraw-Hill, 2001.
9. Peikari, Cyrus and Chuvakin, Anton, Security Warrior, O’Reilly & Associates, 2003.
10. pragmatic, (nearly) Complete Loadable Linux Kernel Modules,
http://www.thc.org/papers/LKM_HACKING.html, 1999.
11. Marc Russinovich, “Sony, Rootkits and Digital Rights Management Gone Too Far,”
http://blogs.technet.com/markrussinovich/archive/2005/10/31/sony-rootkits-and-digital-rights-
management-gone-too-far.aspx
12. Jennifer Rutkowska, “Red Pill: or how to detect VMM using (almost) one CPU instruction,”
http://www.invisiblethings.org/papers/redpill.html, 2004.
13. Ed Skoudis, Counter Hack Reloaded, Prentice Hall, 2006.
14. Ed Skoudis and Lenny Zeltser, Malware: Fighting Malicious Code, Prentice Hall, 2003.
15. Ranier Wichman, “Linux Kernel Rootkits,” http://la-samhna.de/library/rootkits/index.html, 2002.
Slide #160
Extra Material Follows
END OF MODULE 2
161
Isolation Summary
• Access control – mandatory vs discretionary
• Unix school of isolation:
– users/permissions
• New approaches to isolation
– chroot, jails and containers
– System call interposition
– Software fault isolation
– Virtual machine monitors
162
Isolation Summary (Continued)
• Problem: full isolation is too restrictive
– Even isolated processes need to communicate
through some regulated interface
– But this ends being the place where attacks occur
• Challenges in isolation
– Specifying policy
– Unexpected interactions
– Covert channels
163
Intrusion Detection Systems (IDS)
Another Digression
164
Intrusion and Intrusion Detection
• Intrusion : Attempting to break into or misuse
your system.
• Intruders may be from outside the network or
legitimate users of the network.
• Intrusion can be a physical, system or remote
intrusion.
165
Different ways to intrude
• Buffer overflows
• Unhandled input
• Unsanitized input
• Race conditions
• …
166
Intrusion Detection Systems (IDS)
Signature Based:
Intrusion Detection Systems look for attack
signatures, which are specific patterns that
usually indicate malicious or suspicious intent.
168
Anomaly based IDS
• This IDS models the normal usage of the
network as a noise characterization.
• Anything distinct from the noise is assumed to
be an intrusion activity.
– E.g flooding a host with lots of packet.
• The primary strength is its ability to recognize
novel attacks.
169
Drawbacks of Anomaly detection IDS
• Assumes that intrusions will be accompanied by
manifestations that are sufficiently unusual so as to
permit detection.
• These generate many false alarms and hence
compromise the effectiveness of the IDS.
170
Signature based IDS
• This IDS possess an attacked description that
can be matched to sensed attack
manifestations.
• The question of what information is relevant
to an IDS depends upon what it is trying to
detect.
– E.g DNS, FTP etc.
171
Signature based IDS (contd.)
• Interpret a certain series of packets, or a certain piece of
data contained in those packets,as an attack.
• For example, look for the string “phf” as an indicator of a
CGI program attack.
• Signature analysis systems are typically based off of
simple pattern matching algorithms. E.g. simply look for
a sub string within a stream of data carried by network
packets.
• When it finds this sub string (for example, the ``phf'' in
``GET /cgi-bin/phf?''), it identifies those network packets
as vehicles of an attack.
172
Drawbacks of Signature based IDS
173
Host/Applications based IDS
174
Drawbacks of the host based IDS
175
Strengths of the host based IDS
• Attack verification
• System specific activity
• Works on encrypted n/w environments
• Near Real-Time detection and response.
• No additional hardware
176
Stack based IDS
177
Network based IDS
178
Strengths of Network based IDS
179
Commercial ID Systems
• ISS – Real Secure from Internet Security
Systems:
– Real time IDS.
– Contains both host and network based IDS.
• Tripwire – File integrity assessment tool.
• Zeek and Snort – open source public-domain
system.
180
Zeek: Real time IDS
181
Design goals for Zeek
182
Structure of the Zeek System
Tcpdump filter
Filtered Packet Stream
libpcap
Packet Stream
Network
183
Zeek - libpcap
184
Zeek – Event Engine
185
Zeek – TCP Handler
186
Policy Script Interpreter
187
Future of IDS
188
Looking Forward
• In the 90 and 00s, attacks were pretty dumb
– IDS could be somewhat effective
• Now, advanced persistent threats (APTs) are
becoming more and more common
– Vodaphone Greece Hack (2007)
– Operation Aurora (2009)
– Stuxnet (2010)
– German Parliament network (2014)
– DNC Hack (2015-ish)
189
How do we deal with APTs?
• We don’t have good tools to deal with them
• Software is still hopelessly insecure while
ttacks keep getting smarter
• New problems due to adversarial machine
learning
• Need more focus on reliable defences
– Safe programming languages
– Newer hardware architectures (enclaves etc.)
– Automated verification
190
Homework
Think about different isolation mechanisms
• Why do we have so many?
• What are the trade-offs, pros- and cons- of each?
• What attacks are prevented by a particular class
of mechanisms that aren’t prevent by another?
• Can these mechanisms be stacked one on top of
the attack? If so, which ones?
• What assumptions are being by these
mechanisms? What is trusted?
191
VMM Introspection: [GR’03]
192
Intrusion Detection / Anti-virus
Runs as part of OS kernel and user space process
– Kernel root kit can shutdown protection system
– Common practice for modern malware
malware
Guest OS
IDS VMM
Hardware
194
Sample checks
Stealth root-kit malware:
– Creates processes that are invisible to “ps”
– Opens sockets that are invisible to “netstat”
195
Sample checks
2. Application code integrity detector
– VMM computes hash of user app code running in VM
– Compare to whitelist of hashes
• Kills VM if unknown program appears
196
Isolation
Subverting VM
Isolation
197
Subvirt [King et al. 2006]
Virus idea:
– Once on victim machine, install a malicious VMM
– Virus hides in VMM
– Invisible to virus detector running inside VM
anti-virus
anti-virus
OS
OS VMM and virus
HW HW 198
The MATRIX
199
200
VM Based Malware (blue pill virus)
• VMBR: a virus that installs a malicious VMM (hypervisor)
201
VMM Detection
Can an OS detect it is running on top of a VMM?
Applications:
202
VMM detection (red pill techniques)
• VM platforms often emulate simple hardware
– VMWare emulates an ancient i440bx chipset
… but report 8GB RAM, dual CPUs, etc.
203
VMM Detection
Bottom line: The perfect VMM does not exist
204
Isolation
Software Fault
Isolation
205
Software Fault Isolation [Whabe et al.,
1993]
206
Software Fault Isolation
SFI approach:
– Partition process memory into segments
app #1 app #2
207
Segment matching technique
Guard Many
• Designed for MIPS processor. ensures codeavailable.
registers does not
• dr1, dr2: dedicatedload
registers
datanot used
from by binary
another segment
– compiler pretends these registers don’t exist
– dr2 contains segment ID
• Indirect load instruction R12 [R34] becomes:
dr1 R34
scratch-reg (dr1 >> 20) : get segment ID
compare scratch-reg and dr2 : validate seg. ID
trap if not equal
R12 [dr1] : do load
208
Address sandboxing technique
• dr2: holds segment ID
• Indirect load instruction R12 [R34] becomes:
209
Problem: what if jmp [addr] jumps directly into indirect load?
(bypassing guard)
Solution:
jmp guard must ensure [addr] does not bypass load guard
Cross domain calls
caller callee
domain domain
br addr br addr
br addr ret stub br addr
br addr br addr
• Performance
– Usually good: mpeg_play, 4% slowdown
212
Isolation: summary
• Many sandboxing techniques:
Physical air gap, Virtual air gap (VMMs),
System call interposition, Software Fault isolation
Application specific (e.g. Javascript in browser)
213
Problem: covert channels
• Covert channel: unintended communication channel
between isolated components
– Can be used to leak classified data from secure
component to public component
Classified VM Public VM
secret covert
malware
VMM
214
An example covert channel
Both VMs use the same underlying hardware