LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-20-2009, 04:01 AM   #1
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Rep: Reputation: 16
Is it possible to map httpd sealert to its access log?


Hi All,
One of our web servers has logged many of the same "setroubleshoot: SELinux is preventing the httpd from using potentially mislabeled files /boot (boot_t). For complete SELinux messages. run sealert -l e143c369-a72d-453e-84fe-6b62b7f05c5f" recently. This looks suspicious. We'd like to map these sealert to the httpd access log to see if there's any malicious activity. We added a '%P' option to the Apache combined logformat, so the httpd process id could be logged too. Then we grep'ed all the Apache access logs using the pid from the above sealert -l command. There are not many of them, so we can test them one by one. Shockingly, none of the access served by the specified pid can repeat the same sealert.
The server was installed a Centos 5 (x86_64) and upgraded to the 5.3 version two days ago. The main components are as following:
httpd-2.2.3-22.el5.centos
php-5.1.6-23.2.el5_3
mysql-5.0.45-7.el5
Zend Optimizer v3.2.8

Is there any other way we can try to find out the real access which triggered these alerts? The sealert -l output is attached.
Any suggestion will be appreciated.

Regards,
Frank Wang
Attached Files
File Type: txt sealert-l.output.txt (2.4 KB, 12 views)
 
Old 04-20-2009, 11:33 AM   #2
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
The upside is Selinux prevented access, meaning no harm could be done. Since you run Auditd you can put a -w watch on /boot. That way you will find any process that tries to access the directory. If you run a continuous log monitor you could have it trigger running any diagnostic (lsof -P -n +D/boot, gdb) or process-conserving tool (cryo?) when the event happens. If you don't run Auditd then you need to run something inotify-based (or worse like continuously running fuser on /boot). Since you appear to run something PHP-based (and publicly accessable?) I'd invest in more auditing / hardening like checking site code, checking out Suhosin, mod_security, Samhain, Snort. A combination of those may not help prevent the event but may generate enough details for you to work with.
 
Old 04-20-2009, 12:04 PM   #3
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ******* View Post
The upside is Selinux prevented access, meaning no harm could be done. Since you run Auditd you can put a -w watch on /boot. That way you will find any process that tries to access the directory.
Thanks for the quick reply.
The auditd is enabled, but the auditd man page doesn't show any -w option, nor the /etc/sysconfig/auditd. Where should I put the '-w watch on /boot'? Could you elaborate on that?
Thanks again!
 
Old 04-21-2009, 08:49 AM   #4
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
The audit(d?).conf manpage should. Please do check man auditctl with respect to directory versus file watches.
 
Old 04-21-2009, 11:59 AM   #5
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ******* View Post
The audit(d?).conf manpage should. Please do check man auditctl with respect to directory versus file watches.
Sorry for my unfamiliar with the selinux. I've set the -w /boot using auditctl. And the new sealert -l output has two more lines now:

host=www.domain.com type=CWD msg=audit(1240327881.255:46212): cwd="/var/www/domain.com/bbs"
host=www.domain.com type=PATH msg=audit(1240327881.255:46212): item=0 name="/boot" inode=2 dev=08:01 mode=040755 ouid=0 ogid=0 rdev=00:00 obj=system_ubject_r:boot_t:s0

That /var/www/domain.com/bbs directory is the document root of a BBS site. And its access seems normal. Can we infer that something from there triggers the sealert?

Thanks!
 
Old 04-22-2009, 11:17 AM   #6
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
Quote:
Originally Posted by yafrank View Post
I've set the -w /boot using auditctl.
So you didn't put in rules for each file in /boot?


Quote:
Originally Posted by yafrank View Post
That /var/www/domain.com/bbs directory is the document root of a BBS site. And its access seems normal.
Normal? Why should a process be allowed to access /boot? A BBS (as in a publicly accessable service) has in my opinion no business where the kernel and related files reside.


Quote:
Originally Posted by yafrank View Post
Can we infer that something from there triggers the sealert?
Depends on if everything is captured by rules and is logged. But simplifying it, yes, and because since Selinux stopped access I guess there's no problem.
 
Old 04-23-2009, 04:39 AM   #7
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ******* View Post
So you didn't put in rules for each file in /boot?
I really need to read more about selinux. Ok, here's the adjustment:
for i in `find /boot`; do
> auditctl -w $i
> done
And the outcome is similar to the 'auditctl -w /boot,' two extra lines shown like the following:
Code:
host=www.domain.com type=CWD msg=audit(1240464939.807:65243): cwd="/var/www/domain.com/bbs"

host=www.domain.com type=PATH msg=audit(1240464939.807:65243): item=0 name="/boot" inode=2 dev=08:01 mode=040755 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:boot_t:s0

Quote:
Normal? Why should a process be allowed to access /boot? A BBS (as in a publicly accessable service) has in my opinion no business where the kernel and related files reside.
Well, I agree with you, that's why I'd like to dig the real cause of the alert.
The meant of normal is compared to the past. The BBS application had been compromised due to its lossy configuration by another team. So did another CMS web application hosted on the same server. During those accidents, trojans were injected and we pinpointed the back door php scripts by tracing the httpd and sealert log and comparing the checksum of all. The '/boot' selaert was also triggered then by some of those malwares. And thanks to the selinux, there's no further harm observed to the underlying OS. But this time everything is quiet. No whistle blown from the team, and no complain from users. And we still don't know why there's no trace left in the httpd log so we can duplicate the alert.
We've also done the package integrity check by a rpm -Va. There's quite a few interesting thing from the result:
S.5..... /usr/lib64/libpanel.so.5.5
S.5....T /usr/bin/gnomevfs-df
S.5....T /usr/bin/gnomevfs-info
S.5....T /usr/bin/gnomevfs-ls
S.5....T /usr/bin/gnomevfs-mkdir
S.5....T /usr/bin/gnomevfs-monitor
S.5....T /usr/bin/gnomevfs-mv
S.5....T /usr/bin/gnomevfs-rm
S.5....T /sbin/sln
S.5..... /usr/lib64/libpq.so.4.1
S.5....T /sbin/dmsetup
S.5....T /usr/bin/gnome-audio-profiles-properties
S.5....T /usr/bin/gstreamer-properties
S.5....T /usr/bin/gnome-pilot-make-password
S.5....T /usr/bin/gpilot-install-file
S.5....T /usr/bin/gpilotd-session-wrapper
S.5....T /bin/dbus-daemon
S.5....T /bin/dbus-monitor
S.5....T /bin/dbus-send
S.5....T /bin/dbus-uuidgen
S.5....T /sbin/grubby
S.5..... /usr/lib64/libnl.so.1.0-pre5
S.5....T /sbin/parted
S.5....T /sbin/partprobe
S.5....T /usr/bin/dbus-binding-tool
Most of the discrepancies are introduced by the correspondent i[36]86 version of the same package. For example:
rpm -qf --qf '%{name}-%{version}-%{release}.%{arch}.rpm\n' /usr/bin/gnomevfs-rm
gnome-vfs2-2.16.2-4.el5.i386.rpm
gnome-vfs2-2.16.2-4.el5.x86_64.rpm
md5sum /usr/bin/gnomevfs-rm
d825d8faa83132773ade6256f9744f67 /usr/bin/gnomevfs-rm
The checksum agrees with the official x86_64 one. Don't know why the rpm test listing the i386 ones here.
There do have three files whose md5sum can't match the official ones:
/usr/lib64/libpanel.so.5.5
/usr/lib64/libpq.so.4.1
/usr/lib64/libnl.so.1.0-pre5
It turned out the prelink is the culprit. After a prelink -u, they all match. So, all binaries passes the integrity test at least from the package management prospective.

Any suggestion?
Thanks in advance!
 
Old 04-23-2009, 11:26 AM   #8
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
Quote:
Originally Posted by yafrank View Post
The BBS application had been compromised due to its lossy configuration by another team. So did another CMS web application hosted on the same server.
In your original post you mentioned this server was upgraded to CentOS 5.3 a few days ago. Does that mean clean install *then* upgrade or was the malware-ridden machine just upgraded? What I mean is: were backups made, do you still have the means of rigging a (virtual) machine with the original compromised content to investigate?


Quote:
Originally Posted by yafrank View Post
During those accidents, trojans were injected and we pinpointed the backdoor to php scripts by tracing the httpd and sealert log and comparing the checksum of all. The '/boot' selaert was also triggered then by some of those malwares.
Could you list what you found? Have you done any research wrt *how* the machine got compromised exactly? And how long ago? If no investigation was done, would it be better to focus on more than only /boot? (See the Auditd LSPP/CAP rulesets?)

I'll try and think of something that would make it easier to see what is accessing what but I'm not near any UNIX machines right now.
 
Old 04-24-2009, 04:16 AM   #9
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ******* View Post
In your original post you mentioned this server was upgraded to CentOS 5.3 a few days ago. Does that mean clean install *then* upgrade or was the malware-ridden machine just upgraded? What I mean is: were backups made, do you still have the means of rigging a (virtual) machine with the original compromised content to investigate?
It's just upgraded from the malware-ridden machine. We had setup test box using the infected contents then to investigate. And now only part of them are still reserved but all the back door samples were kept.

Quote:
Originally Posted by ******* View Post
Could you list what you found? Have you done any research wrt *how* the machine got compromised exactly? And how long ago? If no investigation was done, would it be better to focus on more than only /boot? (See the Auditd LSPP/CAP rulesets?)

I'll try and think of something that would make it easier to see what is accessing what but I'm not near any UNIX machines right now.
We did scrutinize those accidents. The first one was in last April. An online content editor like FCKeditor of the CMS has a security hole in its file uploading function. It failed to check multiple file extensions containing php. The team managing it carelessly exposed this module to the ordinary user which do not need it. The cracker took advantage of it and uploaded a back door script with trival effort. Then he/she modified one of the key JS file used by nearly all parts, appending an iframe pointing to the entry of a chain of malicious sites which caught many vulnerable surfer's computers. The cracker also uploaded several copies of the back door to other directories of the site. The httpd log revealed the whole trace clearly. Sealert was also triggered a couple of times then. Experiment of the back door script in the test box showed selinux played a vital role in preventing further damage outside the websites directories. Selinux simplely blocked them. Nevertheless, a lots of key info of the server was leaked.
The next one is still the CMS, a missing input verify caused the database exposed to the attacker. One of the editor's password was too simple and was cracked. She was assigned a much higher right than her work require - channel templates modify and generate privilege. The cracker regenerated all the channels she can reach and embedded similar iframe too.
The third one was the BBS site at the end of last year. This time was a WAP function security hole in multi-byte character conversion. The team didn't notice the early warning from the community and still let the few used WAP function enabled by default. The rest are similar.
In all those accidents, the holes were plugged and back door script deleted and all infected files found restored, and every php script was checksummed to satisfied integrity.
I'm not quite understand the Auditd LSPP/CAP rulesets. I'll try to study it first.
Thanks for your patience so long.
 
Old 04-27-2009, 08:42 AM   #10
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
I do see a potential problem with upgrading a malware-ridden machine. Any compromise of lesser-privileged user processes effectively contains the scope but the problem might escalate when gone undetected for too long. It is too easy for a cracker to upload one of those PHP shells and comfortably probe the system for a prolonged period of time to find suitable privilege escalation exploits. I'm not saying they did (and I'm also not saying they didn't) but if they went kernel level then (unless there's residue or collateral damage) only an autopsy of the corpse (boot a Live CD) could uncover that.

The CAPP and LSPP rules (see /usr/share/doc/audit-%{version}/*.rules) are part of the Audit package and provide auditing rules to use or use as example. One other thing Auditd can do is log by syscall number. You don't want to do this on a production server but on a controlled testbox logging may be of limited use.
 
Old 05-04-2009, 11:57 AM   #11
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Sorry for the long delay.
I'm currently rsync'ing all the files from the server to a local test box for easier evaluation later, and it'll probably take about a week to finish. I'll compare all the system files with the official release to see if it's clean.
I'm also considering migrate the web service to a chroot jail. The http://www.cyberciti.biz/tips/chroot...tos-linux.html looks promising. I need to test it first though.
 
Old 05-05-2009, 01:17 PM   #12
yafrank
LQ Newbie
 
Registered: Nov 2004
Posts: 23

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by yafrank View Post
I'm also considering migrate the web service to a chroot jail. The http://www.cyberciti.biz/tips/chroot...tos-linux.html looks promising. I need to test it first though.
I'm not so sure now after reading it carefully. It needs selinux disabled for Apache at least and is probably not a good idea. Some comments there states that the Apache 2.2.10 has native support for chroot, and it's true according to http://www.apache.org/dist/httpd/CHANGES_2.2. It's probably better to go this route.
 
Old 05-05-2009, 02:42 PM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Odd. Usually they're quite thorough but there is absolutely nothing in the article that supports valid reasons for disabling SELinux. Not disabling it seems a good choice to me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LOG httpd missing ovan Linux - Server 4 05-30-2007 05:05 AM
var/log/httpd joeard Linux - Distributions 1 12-08-2006 08:45 PM
[SOLVED] noob with httpd-access.log (Attempting to Crack me?) kwlskwlguy Linux - Security 6 08-10-2005 06:47 AM
httpd access log entries hywaydave Linux - Security 3 02-11-2005 03:39 PM
Date issue with httpd log sopiaz57 Linux - Software 2 12-19-2003 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration