PATH:
usr
/
sbin
#! /usr/bin/python3 # ------------------------------------------------------------------ # # Copyright (C) 2005-2006 Novell/SUSE # Copyright (C) 2011 Canonical Ltd. # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License published by the Free Software Foundation. # # ------------------------------------------------------------------ import re, os, sys, errno, json # PLEASE NOTE: we try to keep aa-status as minimal as possible, for # environments where installing all of the python utils and python # apparmor module may not make sense. Please think carefully before # importing anything from apparmor; see how the apparmor.fail import is # handled below. # setup exception handling try: from apparmor.fail import enable_aa_exception_handler enable_aa_exception_handler() except ImportError: # just let normal python exceptions happen (LP: #1480492) pass def cmd_enabled(): '''Returns error code if AppArmor is not enabled''' if get_profiles() == {}: sys.exit(2) def cmd_profiled(): '''Prints the number of loaded profiles''' profiles = get_profiles() sys.stdout.write("%d\n" % len(profiles)) if profiles == {}: sys.exit(2) def cmd_enforced(): '''Prints the number of loaded enforcing profiles''' profiles = get_profiles() sys.stdout.write("%d\n" % len(filter_profiles(profiles, 'enforce'))) if profiles == {}: sys.exit(2) def cmd_complaining(): '''Prints the number of loaded non-enforcing profiles''' profiles = get_profiles() sys.stdout.write("%d\n" % len(filter_profiles(profiles, 'complain'))) if profiles == {}: sys.exit(2) def cmd_verbose(): '''Displays multiple data points about loaded profile set''' global verbose verbose = True profiles = get_profiles() processes = get_processes(profiles) stdmsg("%d profiles are loaded." % len(profiles)) for status in ('enforce', 'complain'): filtered_profiles = filter_profiles(profiles, status) stdmsg("%d profiles are in %s mode." % (len(filtered_profiles), status)) for item in filtered_profiles: stdmsg(" %s" % item) stdmsg("%d processes have profiles defined." % len(processes)) for status in ('enforce', 'complain', 'unconfined'): filtered_processes = filter_processes(processes, status) if status == 'unconfined': stdmsg("%d processes are unconfined but have a profile defined." % len(filtered_processes)) else: stdmsg("%d processes are in %s mode." % (len(filtered_processes), status)) # Sort by name, and then by pid filtered_processes.sort(key=lambda x: int(x[0])) filtered_processes.sort(key=lambda x: x[1]) for (pid, profile, exe) in filtered_processes: if exe == profile: profile = "" stdmsg(" %s (%s) %s" % (exe, pid, profile)) if profiles == {}: sys.exit(2) def cmd_json(pretty_output=False): '''Outputs multiple data points about loaded profile set in a machine-readable JSON format''' global verbose profiles = get_profiles() processes = get_processes(profiles) i = { 'version': '1', 'profiles': {}, 'processes': {} } for status in ('enforce', 'complain'): filtered_profiles = filter_profiles(profiles, status) for item in filtered_profiles: i['profiles'][item] = status for status in ('enforce', 'complain', 'unconfined'): filtered_processes = filter_processes(processes, status) for (pid, profile, exe) in filtered_processes: if exe not in i['processes']: i['processes'][exe] = [] i['processes'][exe].append({ 'profile': profile, 'pid': pid, 'status': status }) if pretty_output: sys.stdout.write(json.dumps(i, sort_keys=True, indent=4, separators=(',', ': '))) else: sys.stdout.write(json.dumps(i)) def cmd_pretty_json(): cmd_json(True) def get_profiles(): '''Fetch loaded profiles''' profiles = {} if os.path.exists("/sys/module/apparmor"): stdmsg("apparmor module is loaded.") else: errormsg("apparmor module is not loaded.") sys.exit(1) apparmorfs = find_apparmorfs() if not apparmorfs: errormsg("apparmor filesystem is not mounted.") sys.exit(3) apparmor_profiles = os.path.join(apparmorfs, "profiles") try: f = open(apparmor_profiles) except IOError as e: if e.errno == errno.EACCES: errormsg("You do not have enough privilege to read the profile set.") else: errormsg("Could not open %s: %s" % (apparmor_profiles, os.strerror(e.errno))) sys.exit(4) for p in f.readlines(): match = re.search("^([^\(]+)\s+\((\w+)\)$", p) profiles[match.group(1)] = match.group(2) f.close() return profiles def get_processes(profiles): '''Fetch process list''' processes = {} contents = os.listdir("/proc") for filename in contents: if filename.isdigit(): try: for p in open("/proc/%s/attr/current" % filename).readlines(): match = re.search("^([^\(]+)\s+\((\w+)\)$", p) exe = os.path.realpath("/proc/%s/exe" % filename) if match: processes[filename] = { 'profile' : match.group(1), \ 'exe': exe, \ 'mode' : match.group(2) } elif exe in profiles: # keep only unconfined processes that have a profile defined processes[filename] = { 'profile' : exe, \ 'exe': exe, \ 'mode' : 'unconfined' } except: pass return processes def filter_profiles(profiles, status): '''Return a list of profiles that have a particular status''' filtered = [] for key, value in list(profiles.items()): if value == status: filtered.append(key) filtered.sort() return filtered def filter_processes(processes, status): '''Return a list of processes that have a particular status''' filtered = [] for key, value in list(processes.items()): if value['mode'] == status: filtered.append([key, value['profile'], value['exe']]) return filtered def find_apparmorfs(): '''Finds AppArmor mount point''' for p in open("/proc/mounts","rb").readlines(): if p.split()[2].decode() == "securityfs" and \ os.path.exists(os.path.join(p.split()[1].decode(), "apparmor")): return os.path.join(p.split()[1].decode(), "apparmor") return False def errormsg(message): '''Prints to stderr if verbose mode is on''' global verbose if verbose: sys.stderr.write(message + "\n") def stdmsg(message): '''Prints to stdout if verbose mode is on''' global verbose if verbose: sys.stdout.write(message + "\n") def print_usage(): '''Print usage information''' sys.stdout.write('''Usage: %s [OPTIONS] Displays various information about the currently loaded AppArmor policy. OPTIONS (one only): --enabled returns error code if AppArmor not enabled --profiled prints the number of loaded policies --enforced prints the number of loaded enforcing policies --complaining prints the number of loaded non-enforcing policies --json displays multiple data points in machine-readable JSON format --pretty-json same data as --json, formatted for human consumption as well --verbose (default) displays multiple data points about loaded policy set --help this message ''' % sys.argv[0]) # Main global verbose verbose = False if len(sys.argv) > 2: sys.stderr.write("Error: Too many options.\n") print_usage() sys.exit(1) elif len(sys.argv) == 2: cmd = sys.argv.pop(1) else: cmd = '--verbose' # Command dispatch: commands = { '--enabled' : cmd_enabled, '--profiled' : cmd_profiled, '--enforced' : cmd_enforced, '--complaining' : cmd_complaining, '--json' : cmd_json, '--pretty-json' : cmd_pretty_json, '--verbose' : cmd_verbose, '-v' : cmd_verbose, '--help' : print_usage, '-h' : print_usage } if cmd in commands: commands[cmd]() sys.exit(0) else: sys.stderr.write("Error: Invalid command.\n") print_usage() sys.exit(1)
[+]
..
[-] lvchange
[edit]
[-] lvmdiskscan
[edit]
[-] pam_extrausers_update
[edit]
[-] vgs
[edit]
[-] pvdisplay
[edit]
[-] e2undo
[edit]
[-] pam_tally
[edit]
[-] update-initramfs
[edit]
[-] uuidd
[edit]
[-] userdel
[edit]
[-] remove-shell
[edit]
[-] setcap
[edit]
[-] apache2ctl
[edit]
[-] cryptdisks_start
[edit]
[-] cgdisk
[edit]
[-] xfs_mdrestore
[edit]
[-] cryptsetup
[edit]
[-] dbconfig-generate-include
[edit]
[-] grub-mkdevicemap
[edit]
[-] tcpdump
[edit]
[-] lvremove
[edit]
[-] unix_chkpwd
[edit]
[-] lvmsar
[edit]
[-] nologin
[edit]
[-] kpartx
[edit]
[-] augenrules
[edit]
[-] slattach
[edit]
[-] phpdismod
[edit]
[-] blkzone
[edit]
[-] genl
[edit]
[-] ebtables-nft-restore
[edit]
[-] ntfslabel
[edit]
[-] xtables-nft-multi
[edit]
[-] xfs_io
[edit]
[-] cryptsetup-reencrypt
[edit]
[-] runuser
[edit]
[-] modprobe
[edit]
[-] thin_delta
[edit]
[-] update-grub
[edit]
[-] aa-remove-unknown
[edit]
[-] a2ensite
[edit]
[-] partprobe
[edit]
[-] grpconv
[edit]
[-] iscsi_discovery
[edit]
[-] vcstime
[edit]
[-] devlink
[edit]
[-] insmod
[edit]
[-] lvreduce
[edit]
[-] zic
[edit]
[-] xfs_fsr
[edit]
[-] veritysetup
[edit]
[-] ownership
[edit]
[-] lvconvert
[edit]
[-] shadowconfig
[edit]
[-] grpunconv
[edit]
[-] pwck
[edit]
[-] raw
[edit]
[-] accessdb
[edit]
[-] blkdeactivate
[edit]
[-] ldconfig.real
[edit]
[-] pwconv
[edit]
[-] mdadm
[edit]
[-] era_check
[edit]
[-] thin_repair
[edit]
[-] update-rc.d
[edit]
[-] ldconfig
[edit]
[-] arptables-nft
[edit]
[-] apparmor_parser
[edit]
[-] mkntfs
[edit]
[-] xfs_mkfile
[edit]
[-] dhclient-script
[edit]
[-] xfs_repair
[edit]
[-] irqbalance
[edit]
[-] runlevel
[edit]
[-] halt
[edit]
[-] lvrename
[edit]
[-] swapoff
[edit]
[-] vgscan
[edit]
[-] thin_metadata_size
[edit]
[-] update-grub-gfxpayload
[edit]
[-] xfs_rtcp
[edit]
[-] fsck
[edit]
[-] sysctl
[edit]
[-] mkswap
[edit]
[-] autrace
[edit]
[-] mkhomedir_helper
[edit]
[-] pdata_tools
[edit]
[-] grub-set-default
[edit]
[-] mkfs.ext4
[edit]
[-] vgextend
[edit]
[-] iptables-nft
[edit]
[-] bcache-super-show
[edit]
[-] aa-teardown
[edit]
[-] pam_extrausers_chkpwd
[edit]
[-] xfs_growfs
[edit]
[-] shutdown
[edit]
[-] rarp
[edit]
[-] readprofile
[edit]
[-] cron
[edit]
[-] dbconfig-load-include
[edit]
[-] xfs_metadump
[edit]
[-] ausearch
[edit]
[-] xfs_copy
[edit]
[-] grub-bios-setup
[edit]
[-] ebtables-restore
[edit]
[-] lvextend
[edit]
[-] e2fsck
[edit]
[-] vgcreate
[edit]
[-] installkernel
[edit]
[-] rtacct
[edit]
[-] agetty
[edit]
[-] apache2
[edit]
[-] lvm
[edit]
[-] nameif
[edit]
[-] pvremove
[edit]
[-] grub-mkconfig
[edit]
[-] locale-gen
[edit]
[-] groupmod
[edit]
[-] acpid
[edit]
[-] make-ssl-cert
[edit]
[-] phpenmod
[edit]
[-] fstrim
[edit]
[-] mklost+found
[edit]
[-] update-info-dir
[edit]
[-] vgexport
[edit]
[-] iscsi-iname
[edit]
[-] ipmaddr
[edit]
[-] ip
[edit]
[-] mount.fuse
[edit]
[-] a2query
[edit]
[-] mount.vmhgfs
[edit]
[-] cache_dump
[edit]
[-] blockdev
[edit]
[-] luksformat
[edit]
[-] rmt
[edit]
[-] cryptdisks_stop
[edit]
[-] ip6tables-save
[edit]
[-] vgconvert
[edit]
[-] cfdisk
[edit]
[-] update-passwd
[edit]
[-] split-logfile
[edit]
[-] start-stop-daemon
[edit]
[-] grub-reboot
[edit]
[-] validlocale
[edit]
[-] httxt2dbm
[edit]
[-] zerofree
[edit]
[-] update-locale
[edit]
[-] make-bcache
[edit]
[-] ip6tables
[edit]
[-] on_ac_power
[edit]
[-] iptables-nft-restore
[edit]
[-] modinfo
[edit]
[-] chcpu
[edit]
[-] cache_metadata_size
[edit]
[-] ip6tables-nft
[edit]
[-] dosfsck
[edit]
[-] pam_getenv
[edit]
[-] ip6tables-nft-restore
[edit]
[-] thin_rmap
[edit]
[-] pam_tally2
[edit]
[-] groupadd
[edit]
[-] dmeventd
[edit]
[-] biosdecode
[edit]
[-] lsmod
[edit]
[-] pvscan
[edit]
[-] setvtrgb
[edit]
[-] e2scrub_all
[edit]
[-] mkfs.ntfs
[edit]
[-] wipefs
[edit]
[-] mkfs.vfat
[edit]
[-] mkinitramfs
[edit]
[-] mkdosfs
[edit]
[-] irqbalance-ui
[edit]
[-] fsck.vfat
[edit]
[-] pam_timestamp_check
[edit]
[-] arptables-save
[edit]
[-] update-ca-certificates
[edit]
[-] auditd
[edit]
[-] mkfs.bfs
[edit]
[-] ip6tables-legacy-restore
[edit]
[-] cache_repair
[edit]
[-] aureport
[edit]
[-] update-pciids
[edit]
[-] mysqld
[edit]
[-] vgdisplay
[edit]
[-] ufw
[edit]
[-] setvesablank
[edit]
[-] useradd
[edit]
[-] fdisk
[edit]
[-] fdformat
[edit]
[-] ntfsresize
[edit]
[-] iptables-legacy-restore
[edit]
[-] vgreduce
[edit]
[-] iscsid
[edit]
[-] mkfs.xfs
[edit]
[-] init
[edit]
[-] vgcfgrestore
[edit]
[-] multipath
[edit]
[-] fatlabel
[edit]
[-] mkfs.ext2
[edit]
[-] iptables-apply
[edit]
[-] apparmor_status
[edit]
[-] add-shell
[edit]
[-] isosize
[edit]
[-] groupmems
[edit]
[-] ntfsclone
[edit]
[-] multipathd
[edit]
[-] fsck.xfs
[edit]
[-] ethtool
[edit]
[-] telinit
[edit]
[-] rsyslogd
[edit]
[-] adduser
[edit]
[-] e4crypt
[edit]
[-] fsck.fat
[edit]
[-] grub-probe
[edit]
[-] cppw
[edit]
[-] xfs_admin
[edit]
[-] swapon
[edit]
[-] pvck
[edit]
[-] ip6tables-translate
[edit]
[-] iptables-restore
[edit]
[-] ip6tables-restore-translate
[edit]
[-] plymouthd
[edit]
[-] service
[edit]
[-] iptunnel
[edit]
[-] e2image
[edit]
[-] iptables-save
[edit]
[-] e2freefrag
[edit]
[-] groupdel
[edit]
[-] mke2fs
[edit]
[-] vpddecode
[edit]
[-] vgck
[edit]
[-] vigr
[edit]
[-] fsck.ext3
[edit]
[-] swaplabel
[edit]
[-] php-fpm7.4
[edit]
[-] arptables-restore
[edit]
[-] mkfs.msdos
[edit]
[-] newusers
[edit]
[-] dmsetup
[edit]
[-] ebtables-nft
[edit]
[-] e4defrag
[edit]
[-] iptables-legacy-save
[edit]
[-] iptables-nft-save
[edit]
[-] depmod
[edit]
[-] tipc
[edit]
[-] mkfs.btrfs
[edit]
[-] update-mime
[edit]
[-] fsck.msdos
[edit]
[-] netplan
[edit]
[-] getty
[edit]
[-] grub-install
[edit]
[-] xfs_db
[edit]
[-] kbdrate
[edit]
[-] mount.ntfs
[edit]
[-] deluser
[edit]
[-] phpquery
[edit]
[-] a2enconf
[edit]
[-] pvcreate
[edit]
[-] iucode-tool
[edit]
[-] hdparm
[edit]
[-] debugfs
[edit]
[-] xfs_estimate
[edit]
[-] mkfs.cramfs
[edit]
[-] a2dismod
[edit]
[-] ip6tables-legacy-save
[edit]
[-] thin_ls
[edit]
[-] applygnupgdefaults
[edit]
[-] iptables-legacy
[edit]
[-] ebtables
[edit]
[-] cache_writeback
[edit]
[-] mkfs.ext3
[edit]
[-] mount.lowntfs-3g
[edit]
[-] faillock
[edit]
[-] vgmerge
[edit]
[-] tzconfig
[edit]
[-] overlayroot-chroot
[edit]
[-] update-grub2
[edit]
[-] arpd
[edit]
[-] killall5
[edit]
[-] xfs_spaceman
[edit]
[-] iptables-restore-translate
[edit]
[-] switch_root
[edit]
[-] upgrade-from-grub-legacy
[edit]
[-] vgmknodes
[edit]
[-] addgroup
[edit]
[-] losetup
[edit]
[-] thin_dump
[edit]
[-] a2dissite
[edit]
[-] fixparts
[edit]
[-] arptables-nft-save
[edit]
[-] xfs_info
[edit]
[-] xtables-legacy-multi
[edit]
[-] fsadm
[edit]
[-] visudo
[edit]
[-] ldattach
[edit]
[-] lvmdump
[edit]
[-] xfs_ncheck
[edit]
[-] lvmconfig
[edit]
[-] ntfscp
[edit]
[-] aa-status
[edit]
[-] findfs
[edit]
[-] badblocks
[edit]
[-] thin_check
[edit]
[-] popularity-contest
[edit]
[-] vgimportclone
[edit]
[-] plipconfig
[edit]
[-] blkid
[edit]
[-] arptables-nft-restore
[edit]
[-] thin_restore
[edit]
[-] mpathpersist
[edit]
[-] getpcaps
[edit]
[-] resize2fs
[edit]
[-] popcon-largest-unused
[edit]
[-] dhclient
[edit]
[-] arp
[edit]
[-] lvdisplay
[edit]
[-] fsfreeze
[edit]
[-] capsh
[edit]
[-] iptables-translate
[edit]
[-] thin_trim
[edit]
[-] dpkg-reconfigure
[edit]
[-] dosfslabel
[edit]
[-] blkdiscard
[edit]
[-] chroot
[edit]
[-] rmmod
[edit]
[-] dmidecode
[edit]
[-] route
[edit]
[-] pvmove
[edit]
[-] pivot_root
[edit]
[-] e2scrub
[edit]
[-] ntfsundelete
[edit]
[-] sgdisk
[edit]
[-] vgimport
[edit]
[-] tarcat
[edit]
[-] hwclock
[edit]
[-] ip6tables-nft-save
[edit]
[-] lvresize
[edit]
[-] xfs_freeze
[edit]
[-] xfs_logprint
[edit]
[-] tc
[edit]
[-] filefrag
[edit]
[-] lvs
[edit]
[-] ebtables-save
[edit]
[-] fsck.btrfs
[edit]
[-] a2disconf
[edit]
[-] nfnl_osf
[edit]
[-] ifconfig
[edit]
[-] cache_check
[edit]
[-] sshd
[edit]
[-] arptables
[edit]
[-] fsck.ext4
[edit]
[-] iscsiadm
[edit]
[-] delgroup
[edit]
[-] xtables-monitor
[edit]
[-] era_invalidate
[edit]
[-] dmstats
[edit]
[-] rtmon
[edit]
[-] addgnupghome
[edit]
[-] iucode_tool
[edit]
[-] e2mmpstatus
[edit]
[-] logsave
[edit]
[-] xfs_scrub
[edit]
[-] chmem
[edit]
[-] chgpasswd
[edit]
[-] pvchange
[edit]
[-] mount.ntfs-3g
[edit]
[-] reboot
[edit]
[-] pam-auth-update
[edit]
[-] poweroff
[edit]
[-] lvcreate
[edit]
[-] usermod
[edit]
[-] dpkg-preconfigure
[edit]
[-] invoke-rc.d
[edit]
[-] audispd
[edit]
[-] auditctl
[edit]
[-] vgcfgbackup
[edit]
[-] vgsplit
[edit]
[-] era_restore
[edit]
[-] vgrename
[edit]
[-] gdisk
[edit]
[-] fsck.ext2
[edit]
[-] sulogin
[edit]
[-] pwunconv
[edit]
[-] lvscan
[edit]
[-] dumpe2fs
[edit]
[-] fsck.cramfs
[edit]
[-] mkfs.minix
[edit]
[-] atd
[edit]
[-] iptables
[edit]
[-] mii-tool
[edit]
[-] rmt-tar
[edit]
[-] logrotate
[edit]
[-] chpasswd
[edit]
[-] zramctl
[edit]
[-] ebtables-nft-save
[edit]
[-] cache_restore
[edit]
[-] pvs
[edit]
[-] unix_update
[edit]
[-] fstab-decode
[edit]
[-] grub-macbless
[edit]
[-] getcap
[edit]
[-] ip6tables-restore
[edit]
[-] iscsistart
[edit]
[-] xfs_quota
[edit]
[-] rtcwake
[edit]
[-] pvresize
[edit]
[-] bridge
[edit]
[-] ip6tables-legacy
[edit]
[-] mkfs
[edit]
[-] lvmpolld
[edit]
[-] xfs_scrub_all
[edit]
[-] ctrlaltdel
[edit]
[-] cpgr
[edit]
[-] e2label
[edit]
[-] sfdisk
[edit]
[-] lvmsadc
[edit]
[-] vipw
[edit]
[-] tune2fs
[edit]
[-] vgchange
[edit]
[-] apachectl
[edit]
[-] era_dump
[edit]
[-] vgremove
[edit]
[-] xfs_bmap
[edit]
[-] iconvconfig
[edit]
[-] a2enmod
[edit]
[-] mkfs.fat
[edit]
[-] mdmon
[edit]
[-] ip6tables-apply
[edit]
[-] check_forensic
[edit]
[-] grpck
[edit]
[-] fsck.minix
[edit]
[-] integritysetup
[edit]
[-] parted
[edit]