in linux environment application whitelisting - fedoraby default (rhel/fedora) everything loaded...

41
Application Whitelisting In Linux Environment Radovan Sroka | Software Engineer | Red Hat Czech

Upload: others

Post on 20-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Application WhitelistingIn Linux Environment

Radovan Sroka | Software Engineer | Red Hat Czech

Page 2: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

What Is The Application Whitelisting?

● Security practise

● Ability to specify and run only trusted applications

● Admin defines what is allowed and what is not

Page 3: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Why Is That So Important?

Page 4: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Why Is That So Important?

● Another level of security

● Part of the certification schemes○ Common criteria○ And others..

Page 5: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

What About Red Hat?

Page 6: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

What About Red Hat?

● Introduced Fapolicyd Framework

Page 7: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Fapolicyd Framework

● Lightweight solution

● RPM/DNF integration

● Audit support

● Relies on fanotify API

Page 8: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Fanotify API

● Kernel API

● Similar to inotify

● Receiving events from open/exec system calls

● Blockable on system call side, waiting for response

Page 9: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted
Page 10: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted
Page 11: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Fapolicyd Configuration

● /etc/fapolicyd/○ fapolicyd.rules○ fapolicyd.conf○ fapolicyd.trust

Page 12: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Fapolicyd Trust Philosophy

● Optional backends

● By default (RHEL/Fedora) everything loaded from ○ rpmdb○ fapolicyd.trust

● is trusted

● The default set of rules ensures that trusted application is allowed to run

Page 13: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Rule language

● Subject/Object notation

Page 14: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Simple format

DECISION PERM SUBJECT : OBJECT

Page 15: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Decision

● allow

● allow_audit

● deny

● deny_audit

Page 16: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Permission

● open

● execute

● any

Page 17: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Simple format

DECISION PERM SUBJECT : OBJECT

Page 18: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Install Fapolicyd Framework

[root@Axis ~] dnf install fapolicyd

Page 19: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Apps In Home Directory

Problem:

● Regular user would like to run his software in ~/bin○ Enable binary○ Enable python script

Page 20: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Specific Binary

● ~/bin/my-bin

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-binmy-bin my-app.py

Page 21: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Running Daemon In Debug Mode

[root@Axis ~]# fapolicyd --debug 2>&1 | tee outLoaded 24 rulesChanged to uid 980Initializing the databaseLoading rpmdb backendLoading file backendChecking database...Starting to listen for events...

Page 22: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Specific Binary

● ~/bin/my-bin

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-binZsh: operation not permitted: ./my-bin

Page 23: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

[root@Axis ~]# less out

Loaded 24 rulesChanged to uid 980Initializing the databaseLoading rpmdb backendLoading file backendChecking database…Starting to listen for events/my-bin

Page 24: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

rule:9 dec=deny_audit perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-bin ftype=application/x-executable

Page 25: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

rule:9 dec=deny_audit perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-bin ftype=application/x-executable

allow perm=execute exe=/usr/bin/zsh trust=1: file=/home/rsroka/bin/my-bin ftype=application/x-executable trust=0

Rule:

Page 26: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Specific Binary

● ~/bin/my-bin

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-binmy-bin my-app.py

Page 27: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Python Script

● ~/bin/my-app.py

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-app.pyHello World from Python Script

Page 28: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Running Daemon In Debug Mode

[root@Axis ~]# fapolicyd --debug 2>&1 | tee outLoaded 24 rulesChanged to uid 980Initializing the databaseLoading rpmdb backendLoading file backendChecking database...Starting to listen for events...

Page 29: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Python Script

● ~/bin/my-app.py

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-app.pyzsh: operation not permitted: my-app.py

Page 30: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

[root@Axis ~]# less out

Loaded 24 rulesChanged to uid 980Initializing the databaseLoading rpmdb backendLoading file backendChecking database…Starting to listen for events/my-app

Page 31: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

rule:9 dec=deny_audit perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

Page 32: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation

rule:9 dec=deny_audit perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

allow perm=execute exe=/usr/bin/zsh trust=1: file=/home/rsroka/bin/my-app.py ftype=text/x-python trust=0

Rule:

Page 33: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Python Script

● ~/bin/my-app.py

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-app.pyzsh: operation not permitted: my-app.py Wait...What?

Page 34: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation - The Second Round

rule:2 dec=allowed perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

rule:18 dec=deny_audit perm=open auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

Page 35: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Output Investigation - The Second Round

rule:2 dec=allowed perm=execute auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

rule:18 dec=deny_audit perm=open auid=1000 pid=600 exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

allow perm=any exe=/usr/bin/zsh trust=1: file=/home/rsroka/bin/my-app.py ftype=text/x-python trust=0

Rule:

Page 36: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Python Script

● ~/bin/my-app.py

~/bin >> lsmy-bin my-app.py

~/bin >> ./my-app.pyHello World from Python Script

~/bin >> python3 my-app.pyHello World from Python Script

Page 37: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

rule:2 dec=allowed perm=execute exe=/usr/bin/zsh : file=/home/rsroka/bin/my-app.py ftype=text/x-python

rule:2 dec=allowed perm=execute exe=/usr/bin/python3.7 : file=/home/rsroka/bin/my-app.py ftype=text/x-python

allow perm=any all trust=1: file=/home/rsroka/bin/my-app.py ftype=text/x-python trust=0

Rule:

Page 38: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Directory

allow perm=any all trust=1 : dir=/home/rsroka/bin/ trust=0

Page 39: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Mark Files As Trusted

● Add files to fapolicyd.trust

# FULL PATH SIZE SHA256/home/rsroka/bin/my-bin 15523 61a9960bf7d255a85811f4afcac51062e.../home/rsroka/bin/my-app.py 153 e49f0c887cf5fd41d4d49808fc8042fc...

Page 40: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Enable Fapolicyd Framework

[root@Axis ~] systemctl enable --now fapolicyd

Page 41: In Linux Environment Application Whitelisting - FedoraBy default (RHEL/Fedora) everything loaded from rpmdb fapolicyd.trust is trusted The default set of rules ensures that trusted

Thank You!

[email protected]

● https://github.com/radosroka

● https://twitter.com/RadovanSroka

● https://github.com/linux-application-whitelisting/fapolicyd