Sandboxing, Virtualisation, and Mobile Device Security

License

This work by Z. Cliffe Schreuders at Leeds Beckett University is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Contents

General notes about the labs

Preparation

Introduction to application-oriented access controls and sandboxing

Isolation sandboxes

Container-based sandboxes

Copy on write sandboxes

System-level sandboxes

Rule-based system-wide access controls

Coarse grained rights

Optional C programming and capabilities exercise

Rule-based fine-grained controls

Using AppArmor to confine a simple program

Using AppArmor to confine a Trojan horse simulation

Using SELinux to confine a simple program

Mobile security: Android

Qubes and AppVMs

Conclusion

General notes about the labs

Often the lab instructions are intentionally open ended, and you will have to figure some things out for yourselves. This module is designed to be challenging, as well as fun!

However, we aim to provide a well planned and fluent experience. If you notice any mistakes in the lab instructions or you feel some important information is missing, please let me (Cliffe) know and I will try to address any issues.

The labs are written to be informative and, in order to aid clarity, instructions that you should actually execute are generally written in this colour. Note that all lab content is assessable for the module, but the colour coding may help you skip to the “next thing to do”, but make sure you dedicate time to read and understand everything. Coloured instructions in italics indicates you need to change the instructions based on your environment: for example, using your own IP address.

You should maintain a lab logbook / document, which should include your answers to the questions posed throughout the labs (in this colour).

Preparation

If you are working on campus in the IMS labs using the oVirt online labs, click here for instructions on how to login on campus in the IMS labs and create VMs from templates.

If you are working remotely using the oVirt online labs, click here for instructions on how to login via VPN and create VMs from templates.

The oVirt system is a new online lab infrastructure hosted here at Leeds Beckett. This infrastructure is currently on trial, as a pilot. There is a good chance there will be some technical issues, and ls not every lab will be available via this system. However, if you are happy to benefit from this experiment, please keep in mind that you may need to fall back to one of the below methods.

If you are working remotely having downloaded our VMs or by copying them when you were on campus, click here for instructions on how to download VMware Player and configure the VMs to run remotely.

If you are on campus using the IMS system, click here for instructions on how to use the IMS system and VM download scripts.

Start these VMs:

user: student, password: student

user: root, password: tiaspbiqe2r

        user: student, password: student

user: user, password: user8675security

user: root, password: toor8675000

user: user, password: user8675security

user: root, password: toor8675000

You may prefer to create and start these as required through the lab.

Introduction to application-oriented access controls and sandboxing

There are many reasons for not trusting software: the authors may have been designed the software to act maliciously (malware) or they may have made some design or implementation mistakes that make the software vulnerable to attack. This is where access controls come in. Access controls restrict what each subject on a system is authorised to do. Traditionally access controls (such as Unix file permissions, which are user-oriented) have focussed on restricting what each user on a system can do. However, over time this has proven to be insufficient, since this means that every program on a system is trusted with all of a user’s authorisation: any program can read or delete all of a user’s personal documents, Web history, and so on.

Sandboxing (or application-oriented access controls) involves restricting what a program or group of programs can do. This can significantly improve the security of a system, since a rogue program can do far less damage to the system, if it is restricted to only the permissions it requires to function correctly.

Isolation sandboxes

One approach to sandboxing is to run applications in isolated environments, with only access to resources (such as files) that are accessible from within the sandbox.

Container-based sandboxes

Container-based sandboxes share the kernel, but have separate user-space resources. This is more efficient than system-level virtualisation. For example, chroot() is a system call on Unix systems, that changes the root directory for a process and its children. The new namespace of the application limits it to only access files inside the specified directory tree. A wrapper program “chroot” can be used to launch programs into a “chroot jail”. Only root can perform a chroot, but should change identity asap  because root can also escape a chroot jail (by performing another chroot()), so no program in a chroot should ever stay as root.

There are resources such as process controls and networking that are not mediated. Other mechanisms solve some of these problems, such as FreeBSD Jails.

You will create a chroot environment (a directory containing all the files that the “sandboxed” programs require), and run some programs inside it:...

On your openSUSE system:

Create a directory:

sudo mkdir /opt/chrootdir

Copy everything needed to run ls (LS) inside a chroot into a directory

First, we should look at the details of the ls executable:

ls -la /bin/ls

These details show that the file in /bin/ls is actually a symbolic link to the same file in /usr/bin/ls. In order to copy the file and have it correctly work within the cage, you would need to bear this in mind..

Now try running the ldd command on ls:

        ldd /usr/bin/ls

You should get a result that looks something like this:

If you are patient you could copy each required file into your chroot directory. Otherwise, as you can see, all but one of the files can be found in /lib64/.

Try the following (copy all the /lib64/ files into the cage):

sudo rsync -av /lib64 /opt/chrootdir/

Then, copy the one file not found in /lib64/ and the file it is symlinked to::

sudo mkdir -p /opt/chrootdir/usr/lib64/

sudo rsync -av /usr/lib64/libpcre.so.1 /opt/chrootdir/usr/lib64/

sudo rsync -av /usr/lib64/libpcre.so.1.2.1 /opt/chrootdir/usr/lib64/

Finally, copy ls.

sudo mkdir /opt/chrootdir/bin/ /opt/chrootdir/usr/bin/

sudo rsync -av /bin/ls /opt/chrootdir/bin/

sudo rsync -av /usr/bin/ls /opt/chrootdir/usr/bin/

Run ls in a chroot:

sudo chroot /opt/chrootdir/ /usr/bin/ls

Note that ls can only see the files in the chroot cage.

Run ls in the chroot, and attempt to view the root (/) directory:

sudo chroot /opt/chrootdir/ /usr/bin/ls /

Note that again, as far as anything in the chrooted program is concerned, what the rest of the system calls “/opt/chrootdir/”, it sees as “/”. This is referred to as the program’s namespace.

Create a new complete chroot environment, for running any command line programs, including bash (the Linux shell command prompt).

Add an openSUSE repo config:

sudo zypper --root /opt/chrootdir/ ar http://download.opensuse.org/distribution/leap/42.1/repo/oss/suse leap421

Install some software into the directory:

sudo zypper --root /opt/chrootdir/ install rpm zypper wget vim

This may take a little while. You can continue the exercise in another bash window/tab, or read about bind mounting while you wait.

Once the install is complete, bind mount /sys, /dev, and /proc into the cage:

sudo mount --bind /dev /opt/chrootdir/dev

(repeat for /sys and /proc, make sure to change it in both places)

Read “man mount” to see what this does, and understand the security consequences.

Why might it not be a good idea to bind mount the entire root “/” directory into the chroot cage?

Now run bash inside the chroot::

sudo chroot /opt/chrootdir /bin/bash

Create a new user within the chroot (you will be prompted to enter a password for the new user):

useradd -g users -d /home/username -m username; passwd username

Then to make bash switch to this new user::

su – username

Note that you can now run commands and (mostly) only affect the chroot directory.

Experiment with what is possible from within the chroot cage. You may wish to copy across further files and their dependencies from the main system to run from inside the chroot.

Tips: to share the same X server (so you can run graphical program from the chroot, run “export DISPLAY=:0”.

What can you see in /, /opt, /proc?

Can you access anything outside of the chroot?

Understand that you can still access the network and possibly do damage via the bind mounted directories.

In general, we would typically create a minimal install for a chroot environment, such as https://wiki.debian.org/Debootstrap

Copy on write sandboxes

Copy on write sandboxes allow applications to read all files, but confines any writes to a separate area. Upon termination, these kinds of sandboxes typically ask which changes to keep and which to discard (as illustrated below). Examples of copy on write sandboxes includes Sandboxie, Pastures, and Alcatraz.

Copy on write sandbox, isolates changes to the sandbox. Image: http://www.sandboxie.com/ by Sandboxie Holdings, LLC.  All rights reserved.

On your Windows system:

Install Sandboxie (a copy-on-write sandbox).

The Sandboxie install can be found on  http://www.sandboxie.com

Disable Windows defender, in order to download and extract the Netbus remote access malware. This can be done by opening the Windows Defender interface, clicking ‘Tools’ -> ‘Options’ -> Administrator, and unchecking ‘Use this program’.

The Netbus program can be found at the following URL: https://dl.packetstormsecurity.net/trojans/nb16_p04.zip. Note that depending on your browser, you may be presented with a warning message that you need to bypass before downloading. When prompted, the password for this archive is p4ssw0rd.

Run the Netbus server in your Sandbox, being careful to launch patch.exe into the sandbox (right click the executable, and choose from the context menu).

Connect to the Netbus infected machine by running NetBus.exe, and investigate what kind of damage you can do.

You will be able to access files on the hard drive.

Can you write to files?

Can you view all the files that have changed within the sandbox? Where are these stored on the storage disk?

Outside of the sandbox, are the files changed? Why not?

After restarting the infected computer is the Netbus server still running? Why not?

System-level sandboxes

System-level sandboxes provide a complete environment for operating systems. You have already seen this in previous lab work, where virtual machines have been used to run separate operating systems on the same hardware, and each OS can have a separate set of software with limited access to the host computers resources. A hypervisor, AKA virtual machine monitor (VMM), multiplexes the hardware to run hardware-level virtual machines (VM).

Usually VMs are very much isolated from each other, but as you can imagine sometimes you may want to share data between VMs, for example if you have a Linux PC, and want to edit some files using a Windows program, which is in a VM, then you need some way of sharing data across VMs.

In that case, you can use shared folders, to “poke a hole” through the VM isolation

If following this lab on campus, you can see this in action using the IMS systems:

The Linux IMS system we have in place includes VMware Player, which provides hardware emulation virtualisation. VMware (and the similar open source Virtual Box) can run virtual machines of Linux, Windows, and many other operating systems.

This allows you to have multiple operating systems running on your machine at a time

Set up shared folders between the IMS Linux host and a Windows VM:

To do so you need to install VMware Tools in the guest OS. Edit the Virtual Machine properties, and click “options”. 

Search the Internet for further information if you need to.

Make sure you can open and edit a file (of your choosing) inside and outside the VM.

Is it a good idea to give all your VMs write access to your home directory? Why not?

Can hardware emulation VMs be used to confine individual applications?

Rule-based system-wide access controls

Rule-based system-wide access controls can control what each application is authorised to do. The security system enforces exactly which files or resources are accessible to each process. They don't typically require applications to be launched into a sandbox, rules are applied to any applications that have policies.

Coarse grained rights

Some rule-based controls are quite coarsely grained. For example, Android (which we will explore later) grants permissions such as “Network”, “SD Card”, “Camera”, and “GPS” access.

Another coarsely grained system is Linux capabilities, which break up root’s special permissions, so that some programs can be granted specific “capabilities” rather than run as root. Normally on Unix, there are two types of users: privileged (uid=0) and unprivileged (uid!=0). The root user (0) is allowed to do practically anything, and bypasses all kernel permission checks. Capabilities divide these privileges. Which makes it possible to, for example, allow a program to have raw network access or to call chroot (CAP_CHROOT), without granting it all of root’s other privileges, such as the ability to access every file on the system.

See “man capabilities” for the full list of available capabilities.

One of the limitations of the traditional Unix approach to privilege, is that programs that require special permissions, such as ping, need to run as root. In this case, it is so that ping can do raw network operations -- something normal users can't do. However, when ping runs as root (via setuid), then a programming mistake (vulnerability) in ping could possibly allow normal users root access.

Capabilities help to solve the problem. Instead of running the program setuid root, we can give it the capability to do what it needs without access to everything else that root is allowed to do.

Do the following to check whether ping is currently setuid:

ls -la /usr/bin/ping

-rwsr-xr-x 1 root root 39992 Oct 25 2015 /usr/bin/ping

Ping your Windows VM (you might need to disable its firewall), to check that the program works (and that your network connection is ok)  (Ctrl-C to stop):

ping 192.168.201.XX

Now make a copy of ping:

Sudo cp /bin/ping /tmp/ping

As your normal user (not root), try pinging your Windows VM again:

/tmp/ping 192.168.201.XX

It won’t work, since it doesn't have the required permissions:

student@linux-djla:~> /tmp/ping 192.168.201.XX

ping: icmp open socket: Operation not permitted

Make sure setcap is installed; check the man page:

man setcap

Hint: If not, sudo zypper libcap-progs

Now set ping to use the capability, by attaching the capability to the file:

sudo /sbin/setcap cap_net_raw=ep /tmp/ping

Check that the program now has the capability, by running:

sudo /sbin/getcap /tmp/ping

You should now be able to use the /tmp/ping program as any user, and it will be able to ping as before:

/tmp/ping 192.168.201.XX

The advantage is that now the program cannot do all the other things root can do, so a vulnerability in ping wouldn't expose your entire system

Optional C programming and capabilities exercise

SEED Lab (Computer SEcurity EDucation):

“The learning objective of this lab is for students to gain first-hand experiences on capability, to appreciate the advantage of capabilities in access control, and to master how to use capability in to achieve the principle of least privileges. In addition, through this lab, by dissecting the capability mechanism in Linux, students will gain insights on how capability is implemented in operating systems. This lab is based on POSIX 1.e capability, which is implemented in recent versions of Linux kernel.”

Lab available under the GNU Free Documentation License:

http://www.cis.syr.edu/~wedu/seed/Labs/Capability_Exploration/

This is a fairly advanced look at Linux capabilities from a programmer's point of view. It involves C programming, and hacking at libraries. Recommended if you are happy programming C.

These SEED labs should run in most Linux systems, if you want or need their exact setup you can download the SEED VM, or follow the instructions here: http://www.cis.syr.edu/~wedu/seed/lab_env.html

Rule-based fine-grained controls

Another approach taken by some schemes, is to simply specify a list of all the resources each application is authorised to access. This is the approach taken by AppArmor and TOMOYO, which are Linux Kernel security features.

You will use AppArmor to confine a harmless text editor and a Trojan horse simulation.

Using AppArmor to confine a simple program

First you will create a policy using AppArmor that will confine the text editor KWrite, and make sure KWrite can edit a file named “/home/student/Demo/mine.txt”.

On the openSUSE Leap 42.1 VM:

Start by creating this file. From the command line:

mkdir -p /home/student/Demo/

echo "this is a test" > /home/student/Demo/mine.txt

echo "this is a test" > /home/student/Demo/other.txt

Graphical Tools for managing AppArmor can be found in YaST.

Start AppArmor Configuration by searching the system using the Application Menu, as shown below.

(user: root, password: tiaspbiqe2r)

Starting AppArmor Configuration

Once you have opened the configuration manager, start KWrite. Then, click “Settings” in AppArmor Configuration. Select the entry for KWrite and then click “Toggle Mode” to change its mode for “enforce” to “complain”, as shown below.

 

Complaining mode stops enforcing AppArmor profile rules  and logs the behaviour of the program. Using genprof or logprof then steps you through each resource that the program accessed, so that you can decide whether or not to allow the program to access those resources in the future.

Switch back to the KWrite program, and open the file you want it to be able to access (/home/student/Demo/mine.txt). Close KWrite afterwards.

From a terminal window, enter the following command:

        sudo genprof kwrite

Press the “S” key in order to “Scan system log for AppArmor events”.

You will then step through each of the things the program did, and you need to decide whether it should be able to perform this action in the future.

Vetting rules for inclusion in an AppArmor profile

For example, KWrite likely tried to access “/etc/xdg/kdeglobals” with read access. This file is a global configuration file for kde, the desktop environment. Unlike most other items you will vet, this has a severity level of “unknown”. This severity level is a warning that ranges from 1 (low) to 10 (high) based on what the process is attempting. The severity level should be considered carefully, as some processes require access to resources that rank high in terms of severity in order to perform their basic function.

There are a number of options available when vetting a log entry; you have the option of using the abstraction “abstractions/kde” which will also grant other privileges needed by kde applications. Or you can click allow to add the privilege to just allow access to this specific file. Alternatively, you can click glob which will generalise the name using wildcards. You can also do this manually using edit.

“Opts” can be used to choose whether to only allow the access when the user running the program owns the file being accessed, also audit can be set so that every time the file is accessed it is logged.

In this case, add the abstraction because you know it is a KDE application.

For each access attempt, decide whether the program requires access to the resources in order to function as expected, and add the permission using abstractions or direct permissions.

If the program being confined starts another program the options available will be different. In that case you choose how you want the subsequent process to be confined. Your choices would then include whether you want the new program to inherit the same rules, have its own profile, or be unconfined.

Once you have finished vetting each of the privileges, you will be given the option view the profile changes, save them, and so on. Save the changes.

Have a look at the file that has been created, by browsing to the file, as shown below.

Browsing to an AppArmor profile file

Return to the AppArmor Configuration in YaST. Your new KWrite profile should be in enforce mode, meaning it will actually enforce your rules. Using the same procedure that you used to switch to “complain” mode, re-enable “enforce” mode instead.

Now, test the profile you created.

Run KWrite and check that you can use it to access the “mine.txt” file and function as required. If you attempt to access other files KWrite should be denied that access. For example, try using KWrite to open another file (/home/user/Demo/other.txt). This should be denied.

If your rules do not seem to be having an effect, check that your profile is in enforcing mode and not in complaining mode. You can toggle this in the YaST AppArmor control panel.

Logprof can be used to add to profiles based on denied access attempts. Note that now that you are in enforcing mode you can still develop policy, and this is much safer as you are confining what the program can do as you are developing policy. Profiles can be created entirely in enforce mode by creating an empty profile by clicking starting the Add Profile Wizard and clicking finish straight away, ensuring that the mode is set to enforce, then running the program and using the Update profile wizard.

Care needs to be taken when deciding which rules to include, since any recorded behaviour that you accept will always be allowed in the future.

Is there any security benefit to confining KWrite?

If using on campus computers, on openSUSE 11.1 with AppArmor VM:

Using AppArmor to confine a Trojan horse simulation

I have created a simulation of a Trojan horse, it looks like a harmless clone of Tetris, KSirtet (“TetrisK” backwards). However, it also attempts to access lots of resources that could compromise the security of the system and user data.

Your task is to confine the KSirtet Trojan simulation using AppArmor, so that it can still act legitimately as a game, but cannot act maliciously.

Execute the Trojan (Ksirtet, found in the menu), and note that it looks harmless.

Use the YaST tools for creating AppArmor profiles, to create an AppArmor profile to confine Ksirtet – ask your tutor if you require further hints.

What potentially harmful things is the Trojan attempting?

Once you think you have created a policy that will protect you, check the score that the Trojan simulation provides. (You are aiming for 0 – all threats prevented)

ksirtet -trojanscore

What malicious actions did you not notice?

Do you think AppArmor is suited to this kind of use?

What kinds of programs should be confined using AppArmor to best protect a system from attack?

Use AppArmor to confine a benign network service of your choice.

This is a more practical use of AppArmor, since as we just found, it is hard to stop malicious activity if the program is misbehaving when we create policies.

Optional extra: confine a vulnerable version of some software, and exploit a vulnerability, you should find that AppArmor can prevent the vulnerability from causing harm to the system.

Using SELinux to confine a simple program

SELinux is a mandatory access control for Linux, created by the NSA. It combines a number of models, including DTE (application-oriented), RBAC (user-oriented) and can result in complex policies. SELinux can require quite a bit of command-line wizardry, and may require some extra reading to learn how to configure it. Basically, every file has a security label that defines the type, and transition rules state what 'domain' a process is in, and what types the domain can access.

On the Fedora 11 with SELinux VM:

You will create a rough policy using SELinux which will confine KWrite, and you will make sure KWrite can edit a file named “/home/user/Demo/mine.txt”...

Start by creating this file. From the command line:

mkdir -p /home/student/Demo/

echo "this is a test" > /home/student/Demo/mine.txt

echo "this is a test" > /home/student/Demo/other.txt

Graphical Tools for managing SELinux can be found in the programs menu. Under “Administration” is “SELinux Management”. This tool can be used to view and manage all the loaded selinux policies. Including domains, file labelling and policy modules.

Starting the SELinux Policy Generation Tool

In order to confine an application you will create a new SELinux policy module using the Policy Generation Tool. This tool will create a barebones policy module. It will generate a type enforcement file (.te), an interface file (.if), a file context file (.fc) and a shell script (.sh).

Start the SELinux Policy Generation Tool, as shown above.

The root password is “tiaspbiqe2r”.

First specify the type of policy you want to create. Select to create a policy to confine a “User Application”. Then specify the name and executable path, as shown below.

Creating a new policy using SELinux Policy Generation Tool

Then select who the policy applies to. Normal users are usually in the “unconfined_u” role so, select the “unconfined_u” role.

Next, select the ports to allow the application to listen on, and then the ports it is allowed to connect to. As this program shouldn’t need network access we leave those blank. Next, choose common application traits which apply to the program. In this case select “Interacts with terminal” as we will be launching it from a command line, and “Uses dbus” as graphical programs typically use dbus to communicate.

Next select files or directories the application manages. Add the mine.txt file.

Adding files to access to the new SELinux policy

Booleans are parts of policy which can be “turned on and off” this won’t apply to our new policy. Specify where to generate the files that will make up our barebones policy: “/home/user/Documents”. Click Apply to create the files in that directory.

The new policy module you have created is a barebones policy which we will have to add to in order to give the program enough privileges to perform the tasks you expect it to perform. Now that you have created a new policy module, have a look at the files which have been created...

Change to the superuser (root):

su –

Change to the directory containing the newly created files:

cd /home/user/Documents

View the security labels associated with those files:

ls –Z

Open the type enforcement file for viewing/editing:

vi kwrite.te

Viewing security labels (ls -Z) and opening the .te file

The type enforcement (.te) file is the most important file as it contains all the rules for our new domain which confines our program.

The “permissive kwrite_t” line puts this domain into permissive mode, which allows the program to access any resources, but logs the accesses. For now we will leave it in this mode for a quick demonstration. This line is removed later to put this domain into enforcing mode.

The two most common types of lines you will see in the .te file are allow lines which specify something specific the domain is allowed to do, and macros which are abstractions which can represent multiple allow lines.

For example, the line:

allow kwrite_t self:unix_stream_socket create_stream_socket_perms;

Allow lines start with “allow” then the domain (in this case “kwrite_t”) followed by the selinux type to access (in this case “self”, in other words kwrite_t) followed by the sort of resource (in this case a unix_stream_socket ) and ending with the types of access allowed. “create_stream_socket_perms” allows the domain to create a socket to communicate with other tasks in the same domain.

For example, the line:

files_read_etc_files(kwrite_t)

Macros have a name followed by the parameter arguments sent to that macro. In this case the macro “files_read_etc_files” allows the domain “kwrite_t” to read all files marked etc_t. Those are usually configuration files in the /etc/ directory.

Exit vi, by typing “:q

Run the kwrite.sh script to compile and load the policy module:

./kwrite.sh

This script was created by the policy generation tool. It compiles the policy model, loads it into effect, and also labels our files with types as specified in the file context file.

Change from root to user to run KWrite, by opening another terminal tab.

Run KWrite in order to generate logs of what it is trying to do:

kwrite

KWrite has been denied access to dbus, which is confined by a domain in enforcing mode. Note that because the kwrite_t domain is in permissive mode most actions are permitted and logged. So lets have a look at what KWrite is trying to do and what we can do to allow it. Lets have a quick look at the log files that describe what just happened.

Grep can be used to only show us events related to KWrite, in the two places that selinux logs to /var/log/messages and /var/log/audit/audit.log. Run:

grep kwrite /var/log/messages /var/log/audit/audit.log

Send these logs to the program audit2why to translate that information into a more readable format. Run:

grep kwrite /var/log/messages /var/log/audit/audit.log | audit2why

As you can the output indicates, you need to add type enforcement allow rules if you want this access to be allowed.

If we send these logs to audit2allow it will generate rules that can be added to a type enforcement file to allow this access:

grep kwrite /var/log/messages /var/log/audit/audit.log | audit2allow

With the dash ‘R’ option it tries to find macros which grant the access:

grep kwrite /var/log/messages /var/log/audit/audit.log | audit2allow -R

Append those rules (using double arrows) to your .te file:

grep kwrite /var/log/messages /var/log/audit/audit.log | audit2allow –R >> kwrite.te

At this point you should edit the type enforcement to choose which rules we want to keep. Run:

vi kwrite.te

Each time you make changes to your policy, if you want to see them in effect you need to run the shell script again:

./kwrite.sh

Run KWrite as user again, to generate more logs which describe what KWrite is trying to do. Since you want KWrite to be able to access the mine.txt file, open mine.txt using KWrite, so that that action is logged. This time KWrite is allowed to access all the resources it tries to access, because it is still in permissive mode.

Since KWrite is still in a permissive domain, if we want KWrite to be able to do these things again in the future we have to update the .te file again with the appropriate rules. Re-run those commands to add what KWrite just did to the .te file:

grep kwrite /var/log/messages /var/log/audit/audit.log | audit2allow –R >> kwrite.te

At this point you should decide whether to leave all these rules in or remove any which are not required for KWrite to perform as expected.

Now that you have added all the privileges that the program has needed so far, we can put the program into enforcing mode by removing the “permissive kwrite_t” line. Do that by commenting out the line (as shown), or by deleting the line.

vi kwrite.te

Enter insert mode “i”. Make the changes then press Esc. Exit vi and save by typing “:wq”.

Everytime we make changes to policy if we want to see those changes in effect we need to rerun the shell script.

./kwrite.sh

Again, Care needs to be taken when deciding which rules to include. When adding to the te You should remove duplicate entries. It would have been safer to place the domain into enforcing mode before we start generating policy as we can restrict what the program is doing as we are creating policy.

Now the program is restricted by our SELinux policy module.

Try running the newly confined program, and confirm the program works as expected:

kwrite

Test KWrite to see if it can perform as expected. Open the mine.txt file, and save changes to it. KWrite can now open any files which are labelled with types which our type enforcement file allows access to.

Try using KWrite to open /etc/adjtime.

The /etc/adjtime file is labelled with a type which we have not granted access to and KWrite is therefore not allowed to open it, even though as users you are allowed to read the file with other programs. If you wanted to add a rule to allow KWrite this access you could run audit2allow again to produce a rule which we could add to your te file to allow this access.

Optional: use SELinux to confine the Ksirtet Trojan simulation.

Do you think SELinux is suited to either kind of use?

What kinds of programs should be confined using SELinux to best protect a system from attack?

Aside: My Ph.D. research involved developing an alternative to AppArmor and SELinux, based on the idea of confining applications based on the high-level functionalities they perform, such as Text Editor, Game, or Web Browser. Optionally, you can download the “openSUSE 10.3 with FBAC-LSM VM”, and experiment with creating policies for confining KWrite, Ksirtet, and other programs using the experimental software I created (FBAC-LSM).

Mobile security: Android

Android is a (mostly) free open source OS, by Google. It is based on the Linux kernel, but has a user-space unlike any “GNU/Linux” distro. Apps are usually written in Java and compiled to .dex, run in a Dalvik virtual machine, which is a modified Java Virtual Machine (JVM). Applications are confined to the permissions that developers request in a manifest file. For example:

<uses-permission android:name="android.permission.RECEIVE_SMS" />

Review the list of built in permissions:

http://developer.android.com/reference/android/Manifest.permission.html

Apps can also define their own permissions, and can communicate and provide services to one another (this needs to be carefully designed).

The Linux kernel enforces the rules. Each application has its own Unix UID (starting at UID 10000), and is assigned a number of GIDs representing what the application is allowed to do.

A config file assigns the permission names to GIDs:

/system/etc/permissions/platform.xml

Load the LiveAndroid - Live Disk VM, this is Android for x86 platforms.

Controls:

Switch to the console (Alt-F1), and use the package manager (pm) command to find out about the permissions on the system:

pm list permissions

Also note that the permissions are sorted into groups:

pm list permission-groups

Open a file and look at the way that permissions, such as “camera”, are mapped to GIDs (Linux groups):

vi /system/etc/permissions/platform.xml

List the files in /bin:

ls /bin

This should look familiar, this Android includes lots of the common GNU/Linux commands:

ls -la /bin

Notice that lots of the files are symlinks to BusyBox. Written in C, BusyBox implements many of the standard Unix commands, optimised for embedded systems.

Using ls, list the files in /system/app/, this is where applications live.

Download an application manually:

cd /system/app/

export http_proxy='http://192.168.208.51:3128'

wget http://65.99.230.146/md/2326645/LookoutAntivirusandSecurity.apk

Because you have installed via the console, the system assumes the user has accepted the permissions. The app is free to use whatever permissions the app has asked for in its manifest. Usually the user would be asked to confirm the privileges before installing.

Lets look at what that new application is actually allowed to do:

Alt-F7 to switch back to the GUI.

Click the Context Menu Key (next to the Windows key on your keyboard).

Goto Settings, Applications, Manage Applications, Lookout.

What permissions does it have? What kinds of damage could it do with them? Do you trust this app? Why/why not?

Exit back the the main page (Esc).

Click the '<' to display the menu, click “Dev Tools”, “Package Browser”, “com.lookout”

What is the Linux UID that the program will run as?

Launch Lookout via the Menu, then switch back to the console and run:

ps

Look for the process “com.lookout” and check what UID it is running as (it should match the above).

Note the PID (first number in the ps line output), and run:

cat /proc/PID/status

Look at the output for the GID 3003, this is the hard-coded GID for the network access permission, the process can indeed access the Internet.

We have looked at the Linux-y aspects of Android security.

Keep in mind that programming for Android involves requesting the privileges you require, and  being careful not to accidently give those permissions to other apps. As an end user, always think about whether you trust an app to behave with the permissions you are granting it.

Optional challenge: develop an application for Android, a simulation of a Trojan horse that accesses resources that could compromise security. This may involve a lot of extra reading, and download of the appropriate software (for example, either the Android SDK (Java), or the C++/Qt port for Android). You should request privileges in the manifest that may be used for malicious purposes.

Extra challenge: allow the application to provide a service to other applications, and restrict which other applications can  make use of the service. Android has the concept of Inter-Component Communication (ICC), the manifest file can specify the policy for access to components – each component has a permission label, and an application can request those permissions. Components can be set to public: global access, or access policy in manifest.

Qubes and AppVMs

Qubes is an experimental OS, based on the idea of having an isolated VM for each different type of task (banking, work, personal), while providing a user interface to ease the usability of doing so.

http://files.qubes-os.org/Architecture_files/droppedImage.png

Qubes AppVMs isolates groups of applications. Image: http://qubes-os.org/trac/wiki/QubesArchitecture by Invisible Things Lab.  All rights reserved.

Qubes is only available as a 64-bit OS. An ISO is available for download (and is quite hard to get working in the IMS labs). View the website, and look at the screenshots of Qubes. http://qubes-os.org

What are the security benefits of this approach?

Can you think of potential usability benefits/problems?

Conclusion

You now know about a variety of ways that you use to protect yourself from applications. If these programs or services have vulnerabilities that give a remote attacker control of the program, there is only a limited amount of damage that they can cause. This is an active area of research, with lots of potential for innovation.

At this point you have:

Well done!