SELinux complete Flashcards

1
Q

What’s the main thing that selinux does?

A

Type enforcement:
This type/domain has access to this type/domain for this class to do this action.

This goes beyond DAC or UBAC, Even if you have every right to think of outside selinux, inside it you can only do what your role and type dictates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define:
domain
type
class
permissions

A

domain - type of requester
type - type of object acted upon
class - file/directory/whatever
permission - rwx

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Break down what everything is in this SELinux statement:
allow auditd_t auditd_log_t:file { write };

A

allow <domain> <type>:<class> { <permissions> };</permissions></class></type></domain>

if the process runs within the auditd_t domain (and thus has a security context with auditd_t in its third position)
and if the target has the type auditd_log_t set,
and the target is a file
then the permission write is granted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you search if this rule is enabled?

allow auditd_t auditd_log_t:file { write };

A

sesearch –allow –source auditd_t –target auditd_log_t –class file –perm write

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Where are the audit logs? How would you know a log item is related to SELinux?

A

/var/log/audit/audit.log

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Not all of SELinux denials are logged, how would disable that to see them?
Afterword, re-enable

A

semodule –disable_dontaudit –build (semodule -DB

semodule –build (semodule -B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What command would you use to search audit.log for SELinux logs within the last 10 mins?

A

auserach -m avc –start recent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the SELinux command to search logs?

A

sealert -l “*”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you relabel context for /this directory recursively?
Then delete it.

A

semanage fcontext -at httpd_sys_content_t “/this(/.*)?”

semanage fcontext -dt httpd_sys_content_t “/this(/.*)?”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Look at the policy for auditd_t in terms of what it’s allowed to do to var_t

A

sesearch -s auditd_t -t var_t -SA

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a domain transisiton:

A

type_transition init_t initrc_exec_t : process initrc_t;

[kernel_t] –(execute init_exec_t)–> [init_t]
[init_t] –(execute initrc_exec_t)–> [initrc_t]
[initrc_t] –(execute sshd_exec_t)–> [sshd_t]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

For the below domain transition, define what is the entrypoint and what is the transition point:

[initrc_t] –(execute sshd_exec_t)–> [sshd_t]

A

sshd_exec_t is an entrypoint for sshd_t

sshd_t is a transition point for sshd_exec_t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the rules for Domain transitions to happen?

A

1) The domain has execute permission on a file.

2) The file context is identified as an entrypoint for the target domain.

3) The origin domain is allowed to transition to the target domain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Let’s troubleshoot the domain transition below via the three rules we learned about.

[initrc_t] –(execute sshd_exec_t)–> [sshd_t]

The domain has execute permissions on a file

The file context is identified as an entrypoint for the target domain

The origin domain is allowed to transition to the target domain.

A

sesearch -s initrc_t -t sshd_exec_t -c file -p execute -Ad

sesearch -s sshd_t -t sshd_exec_t -c file -p entrypoint -Ad

sesearch -s initrc_t -t sshd_t -c process -p transition -Ad

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are booleans used for?

A

Some activities on SElinux are denied when it would only make sense that they should be allowed, these are normally left up to choice, therefore we have booleans.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Let’s say we turn on the boolean abrt_anon_write, do that and then check what policies have changed

A

setsebool -P abrt_anon_write on

sesearch -b abrt_anon_write -AC
sesearch –bool abrt_anon_write –show_cond –allow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Here is the output of the boolean sesearch, what does it mean?

DT allow abrt_t public_content_rw_t : file { ioctl read write … } ; [ abrt_anon_write ]

A

DT allow abrt_t public_content_rw_t : file { ioctl read write … } ; [ abrt_anon_write ]

D - disabled
T - but if true it is active
if F was there instead of T
F - if False then it’s active
C - shows the DT Condition

18
Q

Let’s say you are showing a denial in your logs:
mozilla_t is denied read access on usera_home_t file.
Instead of changing a policy, let’s see if there’s a boolean for that.

A

sesearch -s mozilla_t -t user_home_t -AC

19
Q

What are customizable types and where are they located?

A

Customizable types are for files with no predetermined location.

/etc/selinux/targeted/contexts/customizable_types

20
Q

Can users change file context in their home files? How would we know if they can or not?

A

Yes, with chcon, they won’t persist though, unless customizable types are used.

users are part of the user_t, to relabel the permission is called RELABELFROM and RELABELTO. Let’s search it!

sesearch -s user_t -t home_bin_t -c file -p relabelto -A

21
Q

How do you know if your system can go into permissive mode?

How do you know if you can disable selinux on boot

A

Systems that can go into permissive mode have this set to “y”
CONFIG_SECURITY_SELINUX_DEVELOP=y

CONFIG_SECURITY_SELINUX_BOOTPARAM is enabled then you can disable on boot.

22
Q

What boolean would you turn on to make sure selinux can’t be set to permissive unless a reload is performed?

A

setsebool -P secure_mode_policyload

23
Q

Restore everything back to the context mapping definition

A

restorecon -RF /

24
Q

Some processes are selinux aware, and may act weird if it’s disabled, how do we check if a process is selinux aware?

A

ldd /sbin/sshd | grep selinux

25
Q

Allow sshd_t to be permissive then check out all processes under permissive

A

semanage permissive -a sshd_t
semanage permissive -l

26
Q

What bad thing will happen if you disable selinux?

A

All files will not generate contexts, if you turn it back on they get default_t which isn’t great.

27
Q

What are attributes?

A

Groups several domains together to have the same policy. For instance, let’s say you have a domain under the attribute “this_attribute”, that domain and everything else associated with it will get the same permission and policy like the one below:

allow this_attribute etc_t:file read

Normally if you see something without a _t it’s an attribute

28
Q

See what types are a part of the userdomain attribute.

Se attributes assigned to a domain

A

seinfo -auserdomain -x

seinfo -tuser_t -x

29
Q

What domains are a part of the unconfined_domain_type?

check if the unconfined type is available.

A

seinfo -aunconfined_domain_type -x

seinfo -tunconfined_t
if this shows unconfined_t, then it’s on.

30
Q

What are modules?

Show all modules, show where they are located.

Show active policy

A

Module all you to add and remove them to change policy

semodule -l

/usr/share/selinux/targeted
(base is base policy)

sestatus | grep loaded

/etc/selinux/targeted/policy

31
Q

What is the purpose of role? Show what domains are allowed for the user role.

A

It dictates what they can enter and what domains they fall under.

If you’re a user_r even if you’re granted sudo access, it won’t work because you don’t have access to the domains.

seinfo -ruser_r -x

if you try to access something that’s not attached to your role you’ll get this error:
invalid context: user_u:user_r:portage_t

32
Q

Show what roles all users have access to and then change your role

A

semanage user -l

newrold -r sysadm_r

33
Q

What is the purpose of SELinux users

Show all users

Show what users are mapped to what roles

Add modify and delete an SELinux user to a group

Now that you’ve changed the user, change their home directory to match

A

Users determine what roles you can have

semanage user -l

semanage login -l

semanage login -a -s staff_u %network
semanage login -d -s staff_u %network
semanage login -m -s staff_u %network

chcon -R -u staff_u -r staff_r /home/ben
or
restorecon -vF /home/ben

34
Q

Add a new SELinux user named infra_u, give them both staff and sysadm roles

A

semanage user -a -R “staff_r sysadm_r” infra_u

35
Q

Can one user access another users files?

A

if the files have ubac_constrained_type attached to them

36
Q

Can you change users mid-session

A

No, but system_u can

37
Q

What does a constraint do?

A

Whitelists, tells under what circumstances and operation is allowed. Constraints look at the ENTIRE context.

38
Q

What does the below constraint mean?

constrain dir_file_class_set { create relabelto relabelfrom }
(
u1 == u2
or t1 == can_change_object_identity
);

See what the can_change_object_identity attribute can do

Show all constraints

A

a domain can only create or relabel(to and from) if the two contexts match
or
if the domain has the can_change_object_identity attribute assigned to it.

seinfo -acan_change_object_identity -x

seinfo –constrain

39
Q

Describe Sensitivity levels and Categories in terms of MLS

A

Sensitivity levels mark things under a certain sensitivity. Highest is called clearance and lowest is current sensitivity.

If a user has public and internal sensitivity levels he won’t be able to access files even if an acl allows, type allows, or anything else.

Categories:
Label assigned to a resource like:
hr, sales, project1

If you want a user to access a sales category that is confidential:
confidential:sales
If you only have this you don’t have access to confidential:hr or anything else.

40
Q

Explain categories and sensitivtity levels in terms of how they are assigned

A

Now that we know the two factors that play into MLS, let’s see it in terms of a board/example:
Example Current sensitivity level Clearance sensitivity level Category set
user_u:user_r:user_t:s0 s0 (lowest sensitivity level) s0 (lowest sensitivity level) c0 (a default category, gets translated to “”)
user_u:user_r:user_t:s0-s0:c0.c15 s0 (lowest sensitivity level) s0 (lowest sensitivity level) c0.c15 (range of c0 to c15)
user_u:user_r:user_t:s0-s2:c1,c4.c8 s0 (lowest sensitivity level) s2 c1,c4.c8 (c1 plus c4 to c8)

41
Q

What is the audit log used for?

A

kernel feature (paired with userspace tools) that can log system calls. For example, opening a file, killing a process or creating a network connection. These audit logs can be used to monitor systems for suspicious activity