LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Monitor creation of hidden system files (https://www.linuxquestions.org/questions/linux-security-4/monitor-creation-of-hidden-system-files-4175485257/)

mollyf 11-20-2013 08:37 AM

Monitor creation of hidden system files
 
I have a RHEL/Apache webserver with approx 500 users actively publishing into a large website (about 60Gb of content) and and I would like to be able to monitor the creation or uploading of any hidden files (e.g. .htaccess) to immediately trigger a cron job to review their contents and edit inline if those files contain specific configuration directives which are prohibited.

Any of the monitoring tools I've looked at work on the basis of detecting all new files created and/or watching existing files for change. I haven't found anything to monitor for specific filenames or dot files as they are created.

Does anyone know if this is possible or how to go about it?

Thanks!

smallpond 11-20-2013 08:47 AM

For .htaccess you are better off using the AllowOverride rules provided by the Apache config. Not sure what other types of files would be interesting to look at.

linosaurusroot 11-20-2013 08:49 AM

I'd suggest you deny use of .htaccess in your apache config.

Or rig your kernel to log the creation or renaming of files - and have a program following the logfile to read what files it should examine.

mollyf 11-20-2013 08:59 AM

Thanks for the suggestions but unfortunately denying or even limiting the creation of .htaccess files is not an option. I had considered logging the new files created and periodically checking that list but given that the directives I'm interested in pose a security risk I was hoping to eliminate the period between checking, even it it's only a few minutes, by checking on the fly at file creation time if that was possible.

zhjim 11-20-2013 09:22 AM

Checkout fam: http://en.wikipedia.org/wiki/File_Alteration_Monitor

unSpawn 11-21-2013 12:41 AM

Dnotify was a kernel 2.4 era mechanism, since kernel 2.6 we have Inotify. If you search LQ then you're bound to find scripts using Inotify, or else try software that incorporates it like Samhain (or IIRC Linux Malware Detect or ClamAV, since you're running a web server?).

mollyf 11-21-2013 08:34 AM

Thanks again for the suggestions. I'd already looked at both inotify and fam but reading the documentation I saw inotify isn't recursive and so not practical where I have literally thousands of sub-folders with new ones being added daily and FAM appears to be only good for monitoring existing files for change. Unless I'm missing something anyone who's actually used either tool can fill me in on?

zhjim 11-21-2013 10:00 AM

Never worked with any of them.

Just for the recursive listing of a directory tree you can either go with
Code:

find /var/www -type d
or

Code:

ls -Rd
Both totaly untested and dark shoots.

Guttorm 11-21-2013 10:58 AM

Hi

The inotify kernel calls are not recursive, but userspace tools can be:

Code:

inotifywait -q -e moved_to,close_write -m -r /var/www/ | grep .htaccess
But it needs to set up watches for all subdirectories, so if it's many thousands, it might be a problem. From "man inotifywait":

Quote:

-r, --recursive
Watch all subdirectories of any directories passed as arguments. Watches will be set up recursively to an unlimited depth. Symbolic links are not traversed. Newly created subā
directories will also be watched.

Warning: If you use this option while watching the root directory of a large tree, it may take quite a while until all inotify watches are established, and events will not be
received in this time. Also, since one inotify watch will be established per subdirectory, it is possible that the maximum amount of inotify watches per user will be reached.
The default maximum is 8192; it can be increased by writing to /proc/sys/fs/inotify/max_user_watches.

unSpawn 11-21-2013 01:08 PM

FWIW there's also recursive Inotify daemons in PERL and Python.

stoggy 12-02-2013 09:56 PM

in order to watch uploads... You would either need to have something in the app the files are being uploaded with, scpd, ftpd, tar files make this very difficult... or you would need something in the FS to watch, which would be selinux, it has a log target, so the files could be allowed but there would be a log of it. Then watch your log files for these logs.

Like unspawn said you could use perl but then you have another process doing it, if the process dies ...


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