CS-527 Software Security OS Security Asst. Prof. Mathias Payer - - PowerPoint PPT Presentation

cs 527 software security
SMART_READER_LITE
LIVE PREVIEW

CS-527 Software Security OS Security Asst. Prof. Mathias Payer - - PowerPoint PPT Presentation

CS-527 Software Security OS Security Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Kyriakos Ispoglou https://nebelwelt.net/teaching/17-527-SoftSec/ Spring 2017 Unix security model Table of Contents Unix


slide-1
SLIDE 1

CS-527 Software Security

OS Security

  • Asst. Prof. Mathias Payer

Department of Computer Science Purdue University TA: Kyriakos Ispoglou https://nebelwelt.net/teaching/17-527-SoftSec/

Spring 2017

slide-2
SLIDE 2

Unix security model

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 2 / 28

slide-3
SLIDE 3

Unix security model

Unix security

Everything is a file. Keep things simple. Separate between user-space and kernel space. Isolate on process level (use virtual memory, unprivileged processes). (But allow communication through shared memory or IPC.)

Mathias Payer (Purdue University) CS-527 Software Security 2017 3 / 28

slide-4
SLIDE 4

Unix security model

Unix privilege model

Distinguish between users. Allow groups of multiple users. Each file has a set of three read/write/execute sets for users, groups, and all other users. Access permissions restrict access to files, directories, programs Extremely simple but allows layering and chaining. More complex privilege models can be mapped through layering across, e.g., multiple directories.

Mathias Payer (Purdue University) CS-527 Software Security 2017 4 / 28

slide-5
SLIDE 5

Unix security model

Unix process permissions

Real User ID (RUID): inherits UID (if unchanged) of the parent process, allows tracking of who started process. Effective User ID (EUID): the UID the process currently used for policy decisions (e.g., file access). Saved User ID (SUID): allows restoring previous UID. Now, how do you get rid of privileges? int setresuid(uid t ruid, uid t euid, uid t suid); Unprivileged user processes may change the real UID, effective UID, and saved set-user-ID, each to one of: the current real UID, the current effective UID or the current saved set-user-ID. Privileged processes (on Linux, those having the CAP SETUID capability) may set the real UID, effective UID, and saved set-user-ID to arbitrary values. Similar mechanism for groups

Mathias Payer (Purdue University) CS-527 Software Security 2017 5 / 28

slide-6
SLIDE 6

Principle of Least Privilege

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 6 / 28

slide-7
SLIDE 7

Principle of Least Privilege

Compartmentalization

Break large monolithic over-privileged software into smaller components. Develop “fault compartments”, that each fail individually. Goal: when one compartment fails, the others can still function. Think of compartments in ships, if one is flooded it can be separated.

Mathias Payer (Purdue University) CS-527 Software Security 2017 7 / 28

slide-8
SLIDE 8

Principle of Least Privilege

Isolation

Ensure that individual components can only interact through well-defined channels (APIs). No other components at the same privilege level can interact with the component without going through the API. Needs some higher privileged component to control interaction.

Mathias Payer (Purdue University) CS-527 Software Security 2017 8 / 28

slide-9
SLIDE 9

Principle of Least Privilege

Principle of Least Privilege

A privilege gives an entity the permission to access a resource. Enforce minimal privileges for intended purpose. Assumes compartmentalization (break software into smaller components) and isolation (ensure that components can only interact along exposed API). Drop privileges when you no longer need them.

Mathias Payer (Purdue University) CS-527 Software Security 2017 9 / 28

slide-10
SLIDE 10

Principle of Least Privilege

Example: mail agents

Mail agents need to do a plethora of tasks: (i) send/receive data from the network, (ii) manage a pool of received/unsent messages, (iii) provide access to stored messages for each user. Two approaches: sendmail and qmail Sendmail uses a typical Unix approach with a large monolithic server and is known for the high complexity and previous security vulnerabilities. QMail uses a modern least privilege approach with a set of communicating processes.

Mathias Payer (Purdue University) CS-527 Software Security 2017 10 / 28

slide-11
SLIDE 11

Principle of Least Privilege

Example: qmail

Separate modules run under separate user IDs (isolation) Each user ID has only limited access to a subset of the resources (least privilege) Only one very small component runs as suid root Only one very small component running as root

Mathias Payer (Purdue University) CS-527 Software Security 2017 11 / 28

slide-12
SLIDE 12

Principle of Least Privilege

Example: qmail

qmail-smtpd (qmaild) qmail-queue (suid qmailq) qmail-inject (“user”) qmail-send (qmails) qmail-rspawn (qmailr) qmail-remote (qmailr) qmail-lspawn (root) qmail-local (sets uid user)

Network Local

Mathias Payer (Purdue University) CS-527 Software Security 2017 12 / 28

slide-13
SLIDE 13

Principle of Least Privilege

qmail components

qmaild/“user” : incoming email suid qmaild : split message into contents and headers, signal qmail-send qmail-send : send locally or remotely qmail-lspawn : root, spawns qmail-local with ID of user qmail-local : handles alias expansion, delivers locally, or signals qmail-queue if needed qmail-remote : sends remote message

Mathias Payer (Purdue University) CS-527 Software Security 2017 13 / 28

slide-14
SLIDE 14

Isolation techniques

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 14 / 28

slide-15
SLIDE 15

Isolation techniques

Confining applications

“Strongly” isolate processes from the rest of the system. Limit a process to a view of the file system chroot (Linux) and jail (FreeBSD): the process executes under a different root. What are the potential problems? An attacker can escape from a jail if there is a link to the

  • utside (e.g., ..).

Mathias Payer (Purdue University) CS-527 Software Security 2017 15 / 28

slide-16
SLIDE 16

Isolation techniques

System Call Interposition

To change persistent state, an application must do system calls. So does an attack. System calls offer an interesting abstraction level Audit all the system calls and parameters, enforce access restrictions. Define a policy depending on what the program should do and define a least privilege policy of system calls that is required for the program to function. Can this be implemented through ptrace? ptrace suffers from TOCTTOU attacks (where an attacker-controlled thread changes the parameters after the check but before the execution of the system call).

Mathias Payer (Purdue University) CS-527 Software Security 2017 16 / 28

slide-17
SLIDE 17

Isolation techniques

Sandboxing

The seccomp interface can be used to implement an efficient sandbox (e.g., Chrome uses seccomp on Linux). After executing seccomp only read, write, exit, and sigreturn can be executed, all other system calls terminate the application. The sandbox first sets up I/O channels to a mediator, calls seccomp, and then can only request services from the trusted mediator.

Mathias Payer (Purdue University) CS-527 Software Security 2017 17 / 28

slide-18
SLIDE 18

Isolation techniques

Software-based Fault Isolation

Application and untrusted code run in the same address space. The untrusted code may only read/write the untrusted data

  • segment. How do you implement such a restriction?

For each memory read/write the target address is masked: and $0x00ff0000, %rax mov $0xc0fe0000, (%rax). Challenge for CISC architectures: jump to unaligned instructions: mov $0x80cd01b0, (%rax) → mov $1, %al; int $0x80 NaCL solves the problem by aligning individual instructions.

Mathias Payer (Purdue University) CS-527 Software Security 2017 18 / 28

slide-19
SLIDE 19

Isolation techniques

Virtualizing applications: containers

Full virtualization can be heavy-weight and incurs a lot of redundancy (the same kernel running multiple times, wasted disk/memory space). Containers solve this problem and allow the execution of “applications” in a virtual environment without replicated full virtual machines. Namespaces need to be separated: pid (processes), net (network), ipc (IPC), mnt (file system), uts (host name) namespaces. Control over the container through cgroups (controlling memory, CPU, and block I/O). AUFS, a special file system that allows different views of the same file system, adding permissions for containers and allowing to hide parts of the file system or have exclusive access to it.

Mathias Payer (Purdue University) CS-527 Software Security 2017 19 / 28

slide-20
SLIDE 20

Isolation techniques

Other isolation techniques

More drastic isolation techniques ensure clear separation. Virtual Machine Introspection (VMI) assumes a trusted hypervisor that mediates inspections. An air gap physically separates machines. (An air gap may still not be enough!) A hard problem for isolation are side channels/covert channels. An even harder problem is specifying policies.

Mathias Payer (Purdue University) CS-527 Software Security 2017 20 / 28

slide-21
SLIDE 21

Defense in Depth

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 21 / 28

slide-22
SLIDE 22

Defense in Depth

Best practices

Facts: (i) root can do everything, (ii) many programs run as root, (iii) most programs only execute few privileged actions. How can we reduce the security problem? Drop privileges as soon as possible (e.g., network service needs root privileges to bind to low port, drop privileges after binding). If you can’t drop privileges: split into multiple components, drop privileges per component. Use more than one security mechanism. Secure the weakest link. Fail securely (and quickly).

Mathias Payer (Purdue University) CS-527 Software Security 2017 22 / 28

slide-23
SLIDE 23

TOCTTOU / Confused Deputy

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 23 / 28

slide-24
SLIDE 24

TOCTTOU / Confused Deputy

Time Of Check To Time Of Use Attacks

Exploits the fact that an attacker may change the environment between a check and the following operation.

1 //

in a suid program

2 f l = ” f i l e ” ; 3 i f

( access ( f l , W OK) != 0) {

4

e x i t (1) ;

5 } 6 7 8 fd = open ( f l , O WRONLY) ; 9 w r i t e ( fd ,

buffer , s i z e o f ( b u f f e r ) ) ;

1 symlink ( ”/ etc /passwd” ,

” f i l e ” ) ;

Mathias Payer (Purdue University) CS-527 Software Security 2017 24 / 28

slide-25
SLIDE 25

TOCTTOU / Confused Deputy

Confused Deputy

Privileged code may be accessed by unprivileged code through its exposed API. If the privileged code can be tricked tricked into abusing its privileges then this it is called a confused deputy. The confused deputy is a special form of privilege escalation. The confused deputy problem may arise when using ACL but not when using capabilities. The classic example is that of a pay-per-use compiler, where the compiler has access to a billing file. Users can specify input source files and output compiled files. An adversary may specify the billing file as output, overwriting the billing information.

Mathias Payer (Purdue University) CS-527 Software Security 2017 25 / 28

slide-26
SLIDE 26

Summary and conclusion

Table of Contents

1

Unix security model

2

Principle of Least Privilege

3

Isolation techniques

4

Defense in Depth

5

TOCTTOU / Confused Deputy

6

Summary and conclusion

Mathias Payer (Purdue University) CS-527 Software Security 2017 26 / 28

slide-27
SLIDE 27

Summary and conclusion

Summary

Compartmentalize: break monolithic system into components. Isolation: Ensure that individual components can only interact through well-defined channels (APIs). Principle of least privilege: each of the components will only run with the minimal amount of permissions. System call interposition allows implementation of least privilege principle at the coarse-grained abstraction level of system calls. TOCTTOU and confused deputy attacks must be considered. Isolation comes in different flavours with different performance/protection/cost trade-offs.

Mathias Payer (Purdue University) CS-527 Software Security 2017 27 / 28

slide-28
SLIDE 28

Summary and conclusion

Questions?

?

Mathias Payer (Purdue University) CS-527 Software Security 2017 28 / 28