Beginners trouble generating/writing policies
Posted: Fri Jun 15, 2012 11:27 am
Hello
i've got a problem with subject and full learning: they builds quite open policies.
First of, i began with full system learning. It's a simple SSH box, so i got this (with minor adjustments):
This seems a bit open (or maybe that's where i am wrong), as it set for subject /usr/sbin/sshd o access to root directory to writeable. Ok, i could not login, while RBAC enabled, so i added a learning subject for /bin/bash (as the grsec logs implied):
The learning itself went without errors:
The generated subject for /bin/bash looked like this:
Which again, looks very open to me (rxw to root dir). Maybe /bin/bash is hard to train, so i tried another one: /usr/bin/id, which should be simpler, as it really doesnt do very much (according to strace). Again, got a quit open policy for the subject:
So i assume i am doing either something fundamentally wrong or (auto) learning is just meant to "point you in the right direction" (docs state one should better rely on auto learning, rather than creating policies manually).
Also, i tried to build the /usr/bin/id policy manually, by giving access only to anything opened (as seen in the learning logs and strace -f id):
However, this did not work, lead to a segmentation fault.
So the questions are:
* How else should subject learning be used - or am i to paranoid about the generated restrictions?
* What is wrong with my manually generated policy for /usr/bin/id? Especially: How can i "debug" this myself?(strace did not work -> either i gave it to open restrictions and no seg fault was thrown, or it failed)
Thanks & Greets
Walt
i've got a problem with subject and full learning: they builds quite open policies.
First of, i began with full system learning. It's a simple SSH box, so i got this (with minor adjustments):
- Code: Select all
# policy generated from full system learning
define grsec_denied {
/boot h
/dev/grsec h
/dev/kmem h
/dev/mem h
/dev/port h
/etc/grsec h
/proc/kcore h
/proc/slabinfo h
/proc/modules h
/proc/kallsyms h
/lib/modules hs
/lib64/modules hs
/etc/ssh h
}
role admin sA
subject / rvka
/ rwcdmlxi
role shutdown sARG
subject / rvka
/
/dev
/dev/urandom r
/dev/random r
/etc r
/bin rx
/sbin rx
/lib rx
/lib64 rx
/usr rx
/proc r
$grsec_denied
-CAP_ALL
connect disabled
bind disabled
role default
subject /
/ h
-CAP_ALL
connect disabled
bind disabled
role sshd u
# Role: sshd
subject / {
/ h
-CAP_ALL
bind disabled
connect disabled
}
role root uG
role_transitions admin shutdown
# Role: root
subject / {
/ h
/dev/initctl
/sbin/gradm x
-CAP_ALL
bind disabled
connect disabled
}
# Role: root
subject /usr/sbin/sshd o {
user_transition_allow sshd root
group_transition_allow nogroup root
/ w
/bin h
/bin/bash x
/dev h
/dev/log rw
/dev/null rw
/dev/urandom r
/dev/pts rw
/dev/ptmx rw
/etc r
/etc/grsec h
/etc/ssh/keys r
/lib rx
/proc w
/proc/filesystems r
/proc/sys/kernel/ngroups_max r
/usr h
/usr/lib rx
/usr/sbin h
/usr/sbin/sshd x
/usr/share h
/usr/share/ssh/blacklist.DSA-1024 r
/usr/share/ssh/blacklist.RSA-2048 r
/usr/share/ssh/blacklist.RSA-4096 r
/var h
/var/run
/var/run/motd r
/var/run/utmp r
-CAP_ALL
+CAP_SETGID
+CAP_SETUID
+CAP_SYS_CHROOT
+CAP_SYS_RESOURCE
bind 0.0.0.0/32:4301 stream tcp
connect disabled
sock_allow_family ipv6 netlink
}
This seems a bit open (or maybe that's where i am wrong), as it set for subject /usr/sbin/sshd o access to root directory to writeable. Ok, i could not login, while RBAC enabled, so i added a learning subject for /bin/bash (as the grsec logs implied):
- Code: Select all
subject /bin/bash ol {
/ h
-CAP_ALL
bind disabled
connect disabled
}
The learning itself went without errors:
- Code: Select all
$ gradm -E -L /tmp/grsec.bash.logs
# do some hundred logins, try call some shell progs like date, id and such
$ gradm -D
$ gradm -O /tmp/grsec.bash.profile -L /tmp/grsec.bash.logs
The generated subject for /bin/bash looked like this:
- Code: Select all
subject /bin/bash o {
/ rxw
/dev/grsec h
/etc/grsec h
-CAP_ALL
bind disabled
connect disabled
sock_allow_family unix inet
}
Which again, looks very open to me (rxw to root dir). Maybe /bin/bash is hard to train, so i tried another one: /usr/bin/id, which should be simpler, as it really doesnt do very much (according to strace). Again, got a quit open policy for the subject:
- Code: Select all
subject /usr/bin/id o {
/ rx
/dev/grsec h
/etc/grsec h
-CAP_ALL
bind disabled
connect disabled
sock_allow_family unix inet
}
So i assume i am doing either something fundamentally wrong or (auto) learning is just meant to "point you in the right direction" (docs state one should better rely on auto learning, rather than creating policies manually).
Also, i tried to build the /usr/bin/id policy manually, by giving access only to anything opened (as seen in the learning logs and strace -f id):
- Code: Select all
subject /usr/bin/id o {
/ h
/dev/grsec h
/etc/group r
/etc/grsec h
/etc/locale.alias r
/etc/nsswitch.conf r
/etc/passwd r
/lib h
/lib/ld-2.11.3.so r
/lib/libc-2.11.3.so r
/lib/libdl-2.11.3.so r
/lib/libnsl-2.11.3.so r
/lib/libnss_compat-2.11.3.so r
/lib/libnss_files-2.11.3.so r
/lib/libnss_nis-2.11.3.so r
/lib/libselinux.so.1 r
/proc/filesystems r
/proc/sys/kernel/ngroups_max r
/selinux r
/usr/lib/locale/locale-archive r
/usr/share/locale/en/LC_MESSAGES/coreutils.mo r
/var/run r
/var/run/nscd/socket r
-CAP_ALL
bind disabled
connect disabled
sock_allow_family unix inet
}
However, this did not work, lead to a segmentation fault.
So the questions are:
* How else should subject learning be used - or am i to paranoid about the generated restrictions?
* What is wrong with my manually generated policy for /usr/bin/id? Especially: How can i "debug" this myself?(strace did not work -> either i gave it to open restrictions and no seg fault was thrown, or it failed)
Thanks & Greets
Walt