jail(8) Hacking UNIX with FreeBSD jail(8), Secure Virtual Servers - - PowerPoint PPT Presentation

jail 8
SMART_READER_LITE
LIVE PREVIEW

jail(8) Hacking UNIX with FreeBSD jail(8), Secure Virtual Servers - - PowerPoint PPT Presentation

jail(8) Hacking UNIX with FreeBSD jail(8), Secure Virtual Servers Presentation for DefCon 14, by Isaac Levy, (.ike) .ike Context I have used jails extensively for web application servers and software development purposes the methodology


slide-1
SLIDE 1

jail(8)

Hacking UNIX with FreeBSD jail(8), Secure Virtual Servers Presentation for DefCon 14, by Isaac Levy, (.ike)

slide-2
SLIDE 2

.ike Context

  • I have used jails extensively for web

application servers and software development purposes

  • the methodology I’m presenting here is

attempting to be ‘stock’ UNIX (no ‘ike- specific’ magic formulas)

  • I am not a jail author, no commit bit...
slide-3
SLIDE 3

Warranty / Announcement

  • I’ll be out and about later if anyone has

more complex questions or strategies they want to discuss

  • I’m *trying* to stick to classic UNIX

process and ideas, and ‘stock’ methodology (no ike-specific magic)

  • I’m assuming you all know your way

around various *NIX Operating Systems

slide-4
SLIDE 4

scale, patterns, complexity (a big picture exercise)

slide-5
SLIDE 5

http://www.powersof10.com/ http://www.youtube.com/watch?v=4i6B7HzijSo Film: Powers of Ten, 1977, Charles and Ray Eames

slide-6
SLIDE 6

Film: Powers of Ten, 1977, Charles and Ray Eames http://www.powersof10.com/ http://www.youtube.com/watch?v=4i6B7HzijSo

slide-7
SLIDE 7

Film: Powers of Ten, 1977, Charles and Ray Eames http://www.powersof10.com/ http://www.youtube.com/watch?v=4i6B7HzijSo

slide-8
SLIDE 8

Internet universe, (according to ike, today.)

home user user bin sbin s r c ports local bin sbin mem ed0 ed1 kmem bin lib jails etc rc.d da0 usr dev sbin root dev var p r
  • c
d a 1 null tmp hd2 mnt FreeBSD kernel b
  • t

BSD UNIX

slide-9
SLIDE 9
slide-10
SLIDE 10

Open Systems Interconnection (OSI) Reference Model

Upper Layers Lower Layers Application Layer (7) Presentation Layer (6) Session Layer (5) Transport Layer (4) Network Layer (3) Data Link Layer (2) Physical Layer (1) e-mail Newsgroups Web Applications File Transfer Host Sessions Directory Services Network Mgmt. File Services POP/SMTP Usenet HTTP FTP Telnet DNS SNMP NFS POP/25 532 80 20/21 23 53 161/162 RPC Portmapper Transmission Control Protocol (TCP) User Datagram Protocol (UDP) Internet Protocol Version 6 (ipv6) Internet Protocol Version 4 (ipv4) SLIP, PPP 802.11 SNAP Ethernnet II RS-X, CAT 1 ISDN ADSL ATM FDDI CAT 1-5 Coaxial Cables

slide-11
SLIDE 11

Internet universe, (according to ike, today.)

home user user bin sbin s r c ports local bin sbin mem ed0 ed1 kmem bin lib jails etc rc.d da0 usr dev sbin root dev var p r
  • c
d a 1 null tmp hd2 mnt FreeBSD kernel b
  • t

BSD UNIX

slide-12
SLIDE 12

yadda yadda

slide-13
SLIDE 13

Internet universe, (according to ike, today.)

home user user bin sbin s r c ports local bin sbin mem ed0 ed1 kmem bin lib jails etc rc.d da0 usr dev sbin root dev var p r
  • c
d a 1 null tmp hd2 mnt FreeBSD kernel b
  • t

BSD UNIX

slide-14
SLIDE 14

UNIX

home u s e r user bin sbin src ports local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r p r

  • c

da1 null t m p h d 2 mnt FreeBSD kernel

boot

slide-15
SLIDE 15

UNIX

dev

kernel

userland devices

slide-16
SLIDE 16

UNIX

home u s e r user bin sbin src ports local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r p r

  • c

da1 null t m p h d 2 mnt FreeBSD kernel

boot

slide-17
SLIDE 17

UNIX Spiral Galaxy

Our world is complex

h
  • m
e user u s e r bin sbin s r c p
  • r
t s local bin sbin m e m ed0 ed1 kmem bin lib etc rc.d da0 usr dev s b i n root dev v a r p r
  • c
d a 1 n u l l t m p hd2 mnt FreeBSD kernel b
  • t

(thx Dan Geer & ShmooCon).

Spiral Galaxy NGC 1232

slide-18
SLIDE 18

UNIX

Our world is simple too...

Helium Atom

dev

kernel

userland devices

slide-19
SLIDE 19

UNIX

home u s e r user bin sbin src ports local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r p r

  • c

da1 null t m p h d 2 mnt FreeBSD kernel

boot

slide-20
SLIDE 20

Mandelbrot Fractal - Julia set

slide-21
SLIDE 21

UNIX’s virtual

home u s e r user bin sbin src ports local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n dev v a r t m p h d 2 mnt FreeBSD kernel

b

  • t

j a i l s

da1 proc root

slide-22
SLIDE 22

home user user bin sbin s r c ports local b i n sbin mem ed0 ed1 kmem b i n lib etc rc.d d a usr d e v s b i n dev v a r t m p h d 2 m n t FreeBSD kernel

boot

jails

da1 proc root

slide-23
SLIDE 23

h

  • m

e user u s e r b i n sbin s r c p

  • r

t s l

  • c

a l bin sbin m e m kmem bin lib etc rc.d u s r dev sbin dev var m n t FreeBSD kernel

boot

j a i l s

proc r

  • t
slide-24
SLIDE 24

h

  • m

e user user bin sbin src ports local bin s b i n bin etc usr dev s b i n dev FreeBSD kernel

boot

j a i l s

p r

  • c

root

slide-25
SLIDE 25

h

  • m

e user user s r c ports l

  • c

a l u s r kernel

j a i l s

root

slide-26
SLIDE 26

home u s e r user s r c p

  • r

t s usr r

  • t
slide-27
SLIDE 27

user ports

slide-28
SLIDE 28

user ports

slide-29
SLIDE 29

user ports

UNIX’s virtual

slide-30
SLIDE 30
slide-31
SLIDE 31
slide-32
SLIDE 32

You get the idea- So what real-world contexts warrant virtualizing the ENTIRE operating system?

slide-33
SLIDE 33

external security threats development messes

slide-34
SLIDE 34

Mutually Untrusted Users

slide-35
SLIDE 35

Mutually Untrusted Users

slide-36
SLIDE 36

Mutually Untrusted Users

slide-37
SLIDE 37

Mutually Untrusted Users

telnet forever!

slide-38
SLIDE 38

Mutually Untrusted Users

su 24/7 ? login:admin pass:love

slide-39
SLIDE 39

Mutually Untrusted Users

slide-40
SLIDE 40

Mutually Untrusted Users

slide-41
SLIDE 41

Mutually Untrusted Users

You run *WHAT* as CGI?

slide-42
SLIDE 42

Mutually Untrusted Users

programs are users too...

slide-43
SLIDE 43

Mutually Untrusted Users

muscle memory kills!

slide-44
SLIDE 44
slide-45
SLIDE 45

Harmony.

slide-46
SLIDE 46

Once upon a time, wasn’t UNIX *fun*?

http://mckusick.com/beastie/

slide-47
SLIDE 47

maintaining old junk?

  • 3 webservers
  • 1 local-use dns cache
  • fileserver (for 2 people)
  • 2 dev servers

Rack full of stuff Example:

slide-48
SLIDE 48

Jailing Server 192.168.1.10 Jail 1 192.168.1.11 Jail 2 192.168.1.12 Jail 3 192.168.1.13 Jail 4 192.168.1.14 Jail 5 192.168.1.15 Jail 6 192.168.1.16 Jail 7 192.168.1.17

3 webservers 1 local-use dns cache fileserver (for 2 people) 2 dev servers Rack full of stuff , becomes 1u server!

jail(8)!

h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
host:/path/to/jaildir/ h
  • m
e user user bin s b i n s r c p
  • r
t s local bin sbin m e m ed0 ed1 kmem bin lib etc rc.d da0 usr d e v s b i n root dev var proc null tmp hd2 mnt /dev/null kernel boot h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
h
  • m
e user user bin sbin src ports local bin s b i n mem ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v sbin dev var tmp hd2 mnt FreeBSD kernel boot j a i l s d a 1 proc r
  • t
slide-49
SLIDE 49

jail(8)

slide-50
SLIDE 50

Definitions

  • what is a jail(8):
  • a user space utility, like ifconfig(8)
  • produces a virtual system image
  • process tree based
  • what is jail(2):
  • a system call to imprison a process
  • it calls chroot and attaches to IP
  • a very few lines of source code!
slide-51
SLIDE 51
  • what jail is not:
  • it is not a classical machine emulator
  • it is not chroot (‘jail’ vocabulary is

commonly misused with other *NIX cultures)

Definitions

slide-52
SLIDE 52

Great Uses for jail(8)

  • hardware resource sharing, an entire OS can

be dedicated to a given service

  • securely separate untrusted users/processes
  • learning/development/testing/hacking
  • insane high availability possibilities
  • honeypots
  • highly vulnerable network services
slide-53
SLIDE 53

Poor Uses for jail(8)

  • kernel access (you don’t get a kernel)
  • limited network interface access
  • limited device driver access
  • when chroot(8) will simply do the job
  • some applications require particular low-level

system calls:

  • Notably, PostgreSQL doesn’t run (securely)

in jails based on SysV IPC

slide-54
SLIDE 54

How To jail(8)

  • DEFINITIVE instructions in jail man pages,
  • 1. compile a FreeBSD userland from source

somewhere on host machine, minor tweaks.

  • 2. create an IP alias on a network interface
  • 3. run the jail(8) call with the IP, and userland,

to ‘boot’ the jail, (so to speak).

slide-55
SLIDE 55

host:/path/to/jaildir/ h

  • m

e user user bin sbin src p

  • r

t s local bin sbin mem ed0 ed1 k m e m b i n lib etc rc.d d a u s r dev sbin root dev var p r

  • c

n u l l tmp h d 2 mnt /dev/null kernel

boot

home user user bin sbin s r c p

  • r

t s local bin sbin mem ed0 ed1 k m e m b i n l i b etc rc.d d a usr dev s b i n root dev var p r

  • c

d a 1 null tmp h d 2 m n t FreeBSD kernel

b
  • t

Practical Comparison

slide-56
SLIDE 56

making a jail

slide-57
SLIDE 57

Host Machine

slide-58
SLIDE 58

preflight (simple)

  • 1. get source to build with (cvsup is great)
  • 2. make somewhere for the jails to live

(partitions, disk mounts, etc...) 3.make somewhere for jail-related start/mgmt scripts to live

(starting jails from /etc/rc.d/jail can thrash violently in most contexts! Bad!)

slide-59
SLIDE 59

preflight- (man, definitive)

slide-60
SLIDE 60

preflight- (build from src)

slide-61
SLIDE 61

preflight- (build from src)

slide-62
SLIDE 62

preflight- (build from src)

slide-63
SLIDE 63

h

  • m

e u s e r bin sbin s r c ports local b i n sbin b i n lib usr s b i n kernel jails

slide-64
SLIDE 64

preflight- (build from src)

slide-65
SLIDE 65

preflight

bin sbin s r c ports local

jails

$D

slide-66
SLIDE 66

preflight- (build from src)

compile!

slide-67
SLIDE 67

preflight- (build from src)

compile!

slide-68
SLIDE 68

preflight

host:/path/to/jaildir/ ports lib

slide-69
SLIDE 69

preflight

host:/path/to/jaildir/ home ports local b i n sbin bin lib etc u s r s b i n v a r t m p mnt

slide-70
SLIDE 70

preflight- (mount /dev)

slide-71
SLIDE 71

preflight- (mount /dev)

slide-72
SLIDE 72

preflight- (null kernel)

slide-73
SLIDE 73

preflight- (null kernel)

slide-74
SLIDE 74

preflight

host:/path/to/jaildir/ home ports local b i n sbin bin lib etc u s r s b i n v a r t m p mnt

slide-75
SLIDE 75

preflight

da1 host:/path/to/jaildir/ home local b i n sbin m e m ed0 ed1 kmem bin lib etc d a u s r dev s b i n dev v a r null t m p mnt

slide-76
SLIDE 76

preflight

  • Common Question:
  • Why isn’t there an

automated build system for this stage?

  • - Take care with the

build procedure, it’s better to automate things later, once you have basics setup.

  • (network, users,

packages, time, etc.)

slide-77
SLIDE 77

preflight- (config host)

jailinghost:/etc/rc.conf (stock)

slide-78
SLIDE 78

preflight- (config host)

jailinghost:/etc/rc.conf

slide-79
SLIDE 79

preflight- (master system)

jailinghost:/etc/ssh/sshd_conf

slide-80
SLIDE 80

home u s e r user bin sbin src ports local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n dev v a r t m p h d 2 mnt FreeBSD kernel

b

  • t

j a i l s

da1 proc root

?

slide-81
SLIDE 81

configure - call jailed sh

Text (analagous to booting a machine in su mode)

slide-82
SLIDE 82

configure - call jailed sh

Text (analagous to booting a machine in su mode)

slide-83
SLIDE 83

configure - call jailed sh

Text (analagous to booting a machine in su mode)

slide-84
SLIDE 84

configure - call jailed sh

Text configure the jail, inside the jail

slide-85
SLIDE 85

configure - call jailed sh

Text configure the jail, inside the jail

slide-86
SLIDE 86

configure - call jailed sh

Text sysctl, whee!

slide-87
SLIDE 87

configure - call jailed sh

Text root pw

slide-88
SLIDE 88

configure - call jailed sh

Text root pw

slide-89
SLIDE 89

configure - call jailed sh

Text add users

slide-90
SLIDE 90

configure - call jailed sh

Text add users

slide-91
SLIDE 91

configure - call jailed sh

Text add users

slide-92
SLIDE 92

configure - call jailed sh

Text set timezone

slide-93
SLIDE 93

configure - call jailed sh

Text set timezone

slide-94
SLIDE 94

configure - call jailed sh

Text set timezone

slide-95
SLIDE 95

configure - call jailed sh

Text set timezone

slide-96
SLIDE 96

configure - call jailed sh

Text set timezone

slide-97
SLIDE 97

configure - call jailed sh

Text network options...

slide-98
SLIDE 98

configure - call jailed sh

Text run ssh, important

slide-99
SLIDE 99

configure - call jailed sh

Text check rc.conf in jail

slide-100
SLIDE 100

configure - call jailed sh

Text check rc.conf in jail

slide-101
SLIDE 101

configure - call jailed sh

Text jail-specific stuff (just use common sense)

slide-102
SLIDE 102

configure

da1 host:/path/to/jaildir/ home local b i n sbin m e m ed0 ed1 kmem bin lib etc d a u s r dev s b i n dev v a r null t m p mnt /dev/null kernel

slide-103
SLIDE 103

configure

/dev/null kernel da1 host:/path/to/jaildir/ home u s e r user bin sbin local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r null t m p mnt /dev/null kernel re0

slide-104
SLIDE 104

configure - call jailed sh

Text we’re finished configuring jailed system!

slide-105
SLIDE 105

configure - assign ip alias

Text (use ifconfig)

slide-106
SLIDE 106

configure - assign ip alias

Text (ip for the jail)

slide-107
SLIDE 107

configure - assign ip alias

Text (original ip for the host machine)

slide-108
SLIDE 108

configure - call jailed sh

Text (analagous to booting a machine in su mode)

slide-109
SLIDE 109

configure - call jailed sh

Text (analagous to booting a machine in su mode)

slide-110
SLIDE 110

preflight

/dev/null kernel da1 host:/path/to/jaildir/ home u s e r user bin sbin local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r null t m p mnt /dev/null kernel re0

slide-111
SLIDE 111

preflight

r e

192.168.1.2 192.168.1.200 192.168.1.x da1 host:/path/to/jaildir/ home u s e r user bin sbin local b i n sbin m e m ed0 ed1 kmem bin lib etc rc.d d a u s r dev s b i n root dev v a r p r

  • c

null t m p mnt /dev/null kernel 192.168.1.200

slide-112
SLIDE 112

start tangent! (script),

remember how I said rc.d is usually a bad idea?

slide-113
SLIDE 113

start!

we’re gonna start the jail manually here....

slide-114
SLIDE 114

start!

we’re gonna start the jail manually here....

slide-115
SLIDE 115

start!

type some random junk to seed entropy,

slide-116
SLIDE 116

start!

jail finished starting

slide-117
SLIDE 117

running

jls(8) lists running jails, gives a jail ID

slide-118
SLIDE 118

using the jail

ssh into the jail, treat it like a server.

slide-119
SLIDE 119

using the jail

ssh into the jail, treat it like a server.

slide-120
SLIDE 120

using the jail

ssh into the jail, treat it like a server.

slide-121
SLIDE 121

inside the jail

just like any new server

slide-122
SLIDE 122

inside the jail

just like any new server

slide-123
SLIDE 123

inside the jail

just like any new server

slide-124
SLIDE 124

you have root!

inside the jail

slide-125
SLIDE 125

inside the jail

how do you know you are inside a jail?

http://www.freebsd.org/cgi/query-pr.cgi?pr=95977 - will explain this url later...

slide-126
SLIDE 126

stop and start jail

exit the jail, (ssh)

slide-127
SLIDE 127

stop and start jail

look at jailed processes (man page goodies)

slide-128
SLIDE 128

stop and start jail

look at jailed processes (man page goodies)

slide-129
SLIDE 129

stop and start jail

use killall with -j flag

slide-130
SLIDE 130

stop and start jail

watch out for stacking mount points!

slide-131
SLIDE 131

stop and start jail

watch out for stacking mount points!

slide-132
SLIDE 132

stop and start jail

restarting with the script this time,

slide-133
SLIDE 133

stop and start jail

restarting with the script this time,

slide-134
SLIDE 134

stop and start jail

now the jid has incrimented once, to 6

slide-135
SLIDE 135

running processes

jexec to check processes (bad idea, in practice)

slide-136
SLIDE 136

Practical Comparison

home user user bin s b i n src p

  • r

t s local bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d d a usr dev sbin dev v a r t m p h d 2 m n t FreeBSD kernel

boot

j a i l s

d a 1 p r

  • c

r

  • t

host:/path/to/jaildir/ h

  • m

e user user bin sbin src p

  • r

t s local bin sbin mem ed0 ed1 k m e m b i n lib etc rc.d d a u s r dev sbin root dev var p r

  • c

n u l l tmp h d 2 mnt /dev/null kernel

boot

host jail

slide-137
SLIDE 137

Process Tree:

JailingServer \_init \_daemon/process etc... \_daemon/process etc... \_daemon/process etc... \_daemon/process etc... \_jail (Jail 1) \_daemon/process etc... \_daemon/process etc... \_daemon/process etc... \_jail (Jail 2) \_daemon/process etc... \_daemon/process etc... \_daemon/process etc... \_jail (Jail 3) \_daemon/process etc... \_daemon/process etc... \_daemon/process etc... \_jail (Jail 4) \_daemon/process etc... \_daemon/process etc... \_daemon/process etc...

user user mem ed1 kmem proc root

host:/path/to/jaildir/ h
  • m
e user user bin sbin s r c p
  • r
t s l
  • c
a l bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v s b i n root dev var proc null tmp hd2 m n t /dev/null kernel boot

host jail

slide-138
SLIDE 138

user user mem ed1 kmem proc root

host:/path/to/jaildir/ h
  • m
e user user bin sbin s r c p
  • r
t s l
  • c
a l bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v s b i n root dev var proc null tmp hd2 m n t /dev/null kernel boot

host jail

slide-139
SLIDE 139

user user mem ed1 kmem proc root

host:/path/to/jaildir/ h
  • m
e user user bin sbin s r c p
  • r
t s l
  • c
a l bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v s b i n root dev var proc null tmp hd2 m n t /dev/null kernel boot

host jail

slide-140
SLIDE 140

user user mem ed1 kmem proc root

host:/path/to/jaildir/ h
  • m
e user user bin sbin s r c p
  • r
t s l
  • c
a l bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d da0 usr d e v s b i n root dev var proc null tmp hd2 m n t /dev/null kernel boot

host jail

slide-141
SLIDE 141
slide-142
SLIDE 142
slide-143
SLIDE 143

jail(8) best practices

diagrams from “A City is Not A Tree” , essay by urban designer Christopher Alexander

slide-144
SLIDE 144

and opportunities...

slide-145
SLIDE 145

break out of jail?

  • Poul-Henning Kamp (PHK) wrote the

jail feature for R&D Associates http:// www.rndassociates.com/ who contributed it to FreeBSD around 1998.

  • To my knowledge, nobody has broken
  • ut of a jail directly, ever. It is however

assumed that nobody has tried that hard yet, as it is still considered ‘esoteric’.

  • If someone breaks jail, PHK wrote that

he would love to know about it.

slide-146
SLIDE 146

best practices

  • ssh into jails to manage their

processes!!!!

  • You always can see the jailed

filesystem/userland from host server, be careful.

  • Design your jailing system

carefully, be creative with core UNIX utilities.

  • Use your highest secure

practices for host server...

slide-147
SLIDE 147

great utilities

  • 4.x, jps, jkill, jtop
  • 5.x, 6.x, onward builtin ps, kill
  • !plus jls(8), jexec(8) jattach

(2), sysctl features for jailing

  • Design your jailing system

carefully, be creative (note about nullfs, devfs)

  • additionally, handy: pstree,

xtail, disk images via mdconfig

slide-148
SLIDE 148

common weak points

  • lost jail?
  • [hostname lockdown]
  • resource attacks
  • disks full
  • [partitions, disk images]
  • fork bombs, memory hogs
  • [securelevels, login.conf]
  • process control
  • direct driver access
  • [flags to mount devfs, procfs]
slide-149
SLIDE 149
  • lost jail?
  • [hostname lockdown]
  • resource attacks
  • disks full
  • [partitions, disk images]
  • fork bombs, memory hogs
  • [securelevels, login.conf]
  • process control
  • direct driver access
  • [flags to mount devfs, procfs]

common weak points

slide-150
SLIDE 150

Comments on Isolation

home user user bin s b i n src p

  • r

t s local bin sbin m e m ed0 ed1 kmem b i n l i b etc rc.d d a usr dev sbin dev v a r t m p h d 2 m n t FreeBSD kernel

boot

j a i l s

d a 1 p r

  • c

r

  • t

host:/path/to/jaildir/ h

  • m

e user user bin sbin src p

  • r

t s local bin sbin mem ed0 ed1 k m e m b i n lib etc rc.d d a u s r dev sbin root dev var p r

  • c

n u l l tmp h d 2 mnt /dev/null kernel

boot
slide-151
SLIDE 151

http://www.samag.com/documents/s=1151/sam0105d/0105d.htm http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/jail.html

OpenRoot Project, fork-bombs, FreeBSD SecureLevels/maxproc, reality, and process control

memory/process attacks

slide-152
SLIDE 152

# hog.c, a small utility to hog system memory # written by Brian Redman (BER) sometime around 1986 # Basic Instructions, Compile this code to a binary: cc hog.c -o hog # then run something like: hog 10 # and the hog will do just that- sit and hog 10mb of ram. # To run a hog stampede, (a fork bomb): while (1) hog 99m& end

(check the Defcon 14 CD)

memory/process attacks

slide-153
SLIDE 153

# STEP 1) # jailed /etc/login.conf file, example of restricted values: :maxproc=30:\ :memoryuse=25M:\ # STEP 2) # Set immutable flags on jailed /etc/login.conf, example: chflags schg $D/etc/login.conf # STEP 3) # Set a higher securelevel on a per-jail basis # (5.x onward, 4.x jailing only securlevels for entire host) # add the following line to the jailed /etc/sysctl.conf: kern.securelevel=2 # securelevel 1 is minimum, read the man page for securelevel

(check the Defcon 14 CD)

memory/process attacks

slide-154
SLIDE 154

honeypot?

compile and give the jail a kernel, fix sysctl:

http://www.freebsd.org/cgi/query-pr.cgi?pr=95977

slide-155
SLIDE 155

disk resource control

  • Put at least your jailed systems on a seperate

partition, or perhaps each jail (rigid in practice)

  • File-Backed Disk Images (mdconfig, in

handbook)- insanely flexible, but take extra memory (usually negligible)

slide-156
SLIDE 156

file-backed disks (.dmg)

  • WOW, they’re convienent.
  • watch out for device numbering (or things get

lost), here’s where Jailing strategies from 4.x come in handy... unless someone has a better way of manging device nodes

  • speed is getting excellent for file-backed

memorry disks, but will always introduce some

  • verhead in file I/O
slide-157
SLIDE 157

# writing 1gb blank file, (analagous to creating an unformatted harddrive) dd if=/dev/zero of=1gb.img bs=1k count=1024k # attaching the file (analagous to attaching a harddrive)... mdconfig -a -t vnode -f 1gb.img -u 1101 # formating the disk... disklabel -r -w md1101 auto # detaching the disk (analagous to ejecting a harddrive)... mdconfig -d -u 1101

FreeBSD handbook has tons more information!

file-backed disks (.dmg)

slide-158
SLIDE 158

<snip - jail start script> mdconfig -a -t vnode -f /path/to/jaildisk_file.dmg -u 200 mount /dev/md200c /path/to/jail_userland_mount_dir # regarding '-u 200' above, it can be handy to use some # variant of a jail's respective IP address for it's disk # image devide node id, so it's easy to track down on host # system with many jailed servers. # later in script, jail /path/to/jail_userland_mount_dir \ hostname.fqdn.com \ 10.0.1.200 \ /bin/sh /etc/rc </snip>

mount disks when starting jails,

file-backed disks (.dmg)

slide-159
SLIDE 159

automation

  • Tarball packaging is your friend.

clean, simple, reliable. be aware of dev/proc mounts be aware of symlinks

  • use FreeBSD Ports Mechanism!

(not for the ports collection, that’s insanely presumptuous, [borderline irresponsible]

  • CVS/SVN anyone?
slide-160
SLIDE 160

upgrading jailed systems

  • Simply use buildworld, (FROM HOST SYSTEM),
  • toss buildworld DESTDIR flag, with a jail’s

userland path

  • follow the handbook: http://www.freebsd.org/doc/

en_US.ISO8859-1/books/handbook/ makeworld.html

slide-161
SLIDE 161

/etc/sysctl.conf (host)

# $FreeBSD: src/etc/sysctl.conf,v 1.8 2003/03/13 18:43:50 mux Exp $ # # This file is read when going to multi-user and its contents piped thru # ``sysctl'' to adjust kernel values. ``man 5 sysctl.conf'' for details. # # Uncomment this to prevent users from seeing information about processes that # are being run under another UID. #security.bsd.see_other_uids=0 # ikenote jailing additives security.jail.set_hostname_allowed=0 # default = 1 # jailed resetting hostname. security.jail.enforce_statfs=2 # default = 2 # mount point info. security.jail.allow_raw_sockets=0 # default = 0 # for ping, etc... security.jail.socket_unixiproute_only=1 # default = 1 # access to routing sockets. security.jail.sysvipc_allowed=0 # default = 0 # SysV shareed mem? Ha! security.jail.chflags_allowed=0 # default = 0 # root less than root...

(check the Defcon 14 CD)

slide-162
SLIDE 162

sysctl (stock values)

$ sysctl -a | grep jail security.jail.set_hostname_allowed: 0 security.jail.socket_unixiproute_only: 1 security.jail.sysvipc_allowed: 0 security.jail.enforce_statfs: 2 security.jail.allow_raw_sockets: 0 security.jail.chflags_allowed: 0 security.jail.jailed: 0

(check the Defcon 14 CD)

slide-163
SLIDE 163

firewalls (quick comment)

  • context:
  • why jail in the first place again?
  • threats affect an entire host server
  • firewall at a higher level (mental shift to treat

the host like a network gateway!)

  • global system firewalling, throttling
  • different boxes? different rules?
slide-164
SLIDE 164

Start Script w/ Disk Image

#!/bin/sh # simple, complete script to start a jail. # define the absolute path to the jail, J=/usr/local/jails/jailed.userland.directory # define the ip address for the jail, I=10.0.1.192 # define a hostname, H=fqdn.com ifconfig en0 inet alias $I/32 mount -t procfs proc $J/proc mount_devfs devfs $J/dev ## add additonal flags to mount_devfs, to hide unnecessary devices!!! ## check the man page for mount_devfs jail $J $H $I /bin/sh /etc/rc

(check the Defcon 14 CD)

slide-165
SLIDE 165

jail crontab misc...

# comment out the following, just to keep syslog quiet for irrelevant items. # Save some entropy so that /dev/random can re-seed on boot. # */11 * * * * operator /usr/libexec/save-entropy # Adjust the time zone if the CMOS clock keeps local time, as opposed to # UTC time. See adjkerntz(8) for details. # 1,31 0-5 * * * root adjkerntz -a

(check the Defcon 14 CD)

slide-166
SLIDE 166

future directions...

important fun:

  • CARP, from PF/OpenBSD
  • GEOM
  • NFS Improvements
  • more NAS/SAN support (GEOM, ggated)
  • FreeBSD 4.x, 5.x, 6.x, (7x!)
slide-167
SLIDE 167

sick possibilities...

application server carp1 carp2 carp3 carp4 application server application server application server application server application server application server application server switchA switchB NAS safe storage switch1 switch2 net net

GEOM Gate, CARP, fun with failover jails...

slide-168
SLIDE 168

misc

  • Compile md(4) into the kernel for File-Backed

Disks, for better performance

  • GOTCHA: rm a jail directory? chflags -R noschg

jaildir

slide-169
SLIDE 169

Stillborn. Suggestions?

slide-170
SLIDE 170
slide-171
SLIDE 171

ike is proud to be a part of the New York City *BSD Users Group, and the Lower East Side Mac Unix Users Group

Special Thanks:

  • Poul-Henning Kamp wrote the jail feature for R&D

Associates http://www.rndassociates.com/ who contributed it to FreeBSD around 1998.

  • Robert Watson wrote the extended documentation,

found a few bugs, added a few new features, and cleaned up the userland jail environment. reality schooled me more BSD than he knows... wintermute (of iMeme), taught me to jail(8). He’s here somewhere- buy him a drink.

slide-172
SLIDE 172

ike is proud to be a part of the New York City *BSD Users Group, and the Lower East Side Mac Unix Users Group

isaac@diversaform.com