kernel 2.4.23 + grsec 1.9.13
I'm trying to use socket_server and socket_server_gid to stop group "nogroup" from starting listening daemons. The point is to prevent exploits with Apache/PHP that install a small telnet-daemon running as "nobody", letting anyone telnet straight into the server w/o password
Tests show that enabling socket_server block the bind() call, but it doesn't seem to matter - the daemon can still accept connections on the port. Look at these straces:
## Without socket_server
## echo 0 >| /proc/sys/kernel/grsecurity/socket_server
[pid 4717] socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
[pid 4717] bind(3, {sin_family=AF_INET, sin_port=htons(14589), sin_addr=inet_addr("0.0.0.0")}}, 16) = 0
[pid 4717] listen(3, 5) = 0
[pid 4717] accept(3, <unfinished ...>
## With socket_server enabled
## echo 1 >| /proc/sys/kernel/grsecurity/socket_server
[pid 984] socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
[pid 984] bind(3, {sin_family=AF_INET, sin_port=htons(14589), sin_addr=inet_addr("0.0.0.0")}}, 16) = -1 EACCES (Permission denied)
[pid 984] listen(3, 5) = 0
[pid 984] accept(3, <unfinished ...>
In the second example, bind() returns EACCES, but the daemon still accepts on the port (14589). When telneting to port 14589 you get access to a login shell running as the Apache user (nobody/nogroup).
What's wrong here?
Am I missing something obvious?
How can I prevent Apache/PHP from opening listening sockets?
Blocking bind() seems totally useless?
Grateful for any help.