
Apple Web Objects
For this to work, Apache’s mod_webobjects adapter needs to be able to make a connection to localhost:1085. But since SELinux is dutifully protecting the system by disallowing Apache from opening TCP connections of its own we need to make an adjustment.
|
1 |
type=AVC msg=audit(1370168291.796:35647): avc: denied { name_connect } for pid=1892 comm="httpd" dest=1085 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket |
The low-hanging fruit would have been to toggle httpd_can_network_connect to ‘on’ but that would have allowed Apache to connect to any TCP port, not just the one we want. There are more specific SELinux booleans for MySQL and SMTP but we needed something custom that allowed Apache to connect to port 1085 only.
Step 1: Create a New Policy Module
|
1 2 3 4 5 6 7 8 9 10 |
policy_module(apache_proxy_port,1.0.0) gen_require(` type httpd_t; ') type apache_proxy_port_t; corenet_port(apache_proxy_port_t) allow httpd_t apache_proxy_port_t:tcp_socket name_connect; |
Step 2: Compile Your Module
Run make in the directory where you created your apache_proxy_port_t.te file. You’ll need to have installed the selinux-policy package beforehand though it should be installed by default.
|
1 |
~# make -f /usr/share/selinux/devel/Makefile |
Step 3: Set SELinux to Enforcing (Optional)
If your system can remain safe without SELinux enabled for a moment it makes sense to set it to enforcing temporarily while you load and test your new module. You could get locked out of your system if something went awry.
|
1 |
~# setenforce 0 |
Step 4: Install Your Module & Activate It
One of the files created in step 2 is the apache_proxy_port_t.pp file. Load it up using semodule. Both semodule and semanage come from the policycoreutils package.
|
1 2 |
~# semodule -i apache_proxy_port_t.pp ~# semanage port -a -t apache_proxy_port_t -p tcp 1085 |
You’ll also want to create another mapping for each of your application instances. Run the same command above with the port number changed (i.e., port 2001).
Step 5: Re-Enable Enforcing
If you’re not seeing any violations and things are running as expected, turn enforcement back on.
|
1 |
~# setenforce 1 |
TL;DR: If you want to allow your freshly-hijacked Apache server to open TCP connections to any port it likes, toggle the SELinux boolen. If not, use the instructions above.
** Thanks to Mr SELinux himself, Dan Walsh, for his 2007 post on policy customization.
I love to read but I’m not trying to keep every book I’ve read like they’re trophies. With very few exceptions I don’t go back and re-read old titles either. I have my kindle that I keep loaded with all my favorite subjects so there isn’t much call for the dead-tree versions unless I want to keep them around for reference. Anyone who’s tried to find information in a kindle title knows my pain.





