Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Monitoring all filesystem modifications
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Wed Jul 28, 2004 1:10 pm    Post subject: Monitoring all filesystem modifications Reply with quote


29.1.2005 Update: minor bugfix
10.1.2005 Update: now working with 2.6.10 and UDEV


Overview:.
After loading this kernel module you can monitor all file system alterations by simply typing:
Code:
cat /dev/fsysmon

It's original purpose was to feed a daemon with data but nevertheless I found it to be even more useful as a standalone project.

Download:.
http://www.logic.at/staff/robinson/fsysmon-0.2.tar.gz

Requirements:
- Kernel 2.6 with Enabled Support for Security Modules. The following should be sufficient:
Code:

CONFIG_SECURITY=y

[EDIT]Since someone asked me why this is needed here a short explanation: In 2.4. it was possible to overwrite entries of the syscall table. This is necessary to enable the filesystem monitoring. In 2.6. one has to use the security hooks to get the same functionality because the syscall table is no longer exported.
[/EDIT]

Building:
Note: The default behavour of the module is to monitor all file - adding, moving, removing, renaming operations. If you also want to monitor file content modifications you have to uncomment the following line in fsysmon.c:
Code:

// #define INODE_ACCESS (optionally)

Building the module:
Code:

tar zxvf fsysmon-0.1.tar.gz
cd /usr/src/linux
make SUBDIRS=/path_to_archive/fsysmon-0.1/module/ modules


Loading:
Code:

cd /path_to_archive/fsysmon-0.1/module/
su
insmod ./fsysmon.ko


Usage:
The module creates a device called /dev/fsysmon.
In case you are using UDEV you have to create the device yourself:
Find out it's major number:
Code:
grep fsysmon /proc/devices
253 fsysmon

Create the device:
Code:
mknod /dev/fsysmon c 253 1


To monitor the filesystem alterations you can simply type:
Code:
cat /dev/fsysmon

This will output a line everytime something was modified. The first character of the line determines its meaning, the rest consists of the pathname of the corresponding file without the first character (which is '/' anyways).

Semantics of the first character:
a: file was added
r: file was removed
u: file content was updated

Example:
Output Line: ahome/user/fileXY
Meaning: fileXY was just created in directory /home/user

Unloading:
Code:

su
rmmod fsysmon

Caution: It is important to unload the module if you don't read from /dev/fsysmon otherwise the module will eat up all your memory after a while.
If you continuously read from the device you can leave it running as long as you want.


Hope this is helpful!
regards


Last edited by thaldyron on Sat Jan 29, 2005 5:13 pm; edited 6 times in total
Back to top
View user's profile Send private message
beastmaster2000
n00b
n00b


Joined: 29 Jul 2004
Posts: 1

PostPosted: Thu Jul 29, 2004 7:31 am    Post subject: Reply with quote

This tool seems to make life a lot easier when trying to find out _why_ my harddisk never switches to standby... :)
Back to top
View user's profile Send private message
GentooBox
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1168
Location: Denmark

PostPosted: Thu Jul 29, 2004 12:46 pm    Post subject: Reply with quote

that is a damn nice kernel module.

Does it work on all kind of filesystems ?
_________________
Encrypt, lock up everything and duct tape the rest
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Thu Jul 29, 2004 2:16 pm    Post subject: Reply with quote

GentooBox wrote:
that is a damn nice kernel module.

Does it work on all kind of filesystems ?

Thanks! :)
If you mean filesystems like reiserfs, ext3 or vfat the answer is yes.
Everything that depends on the inode system calls is monitored (files, sockets, pipes,...)
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Sat Jul 31, 2004 2:07 am    Post subject: Reply with quote

how this is better than tripwire/afick usage?
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Sat Jul 31, 2004 4:25 pm    Post subject: Reply with quote

FonderiaDigitale wrote:
how this is better than tripwire/afick usage?

I'm not very familiar with tripwire and therefore don't know if tripwire makes it that easy to monitor filesystem alterations by simply parsing the output of a device.
However, I think my kernel module is some sort of a lightweight approach compared to the features of tripwire. AFAIK tripwire is focused on security related issues rather than just producing helpful debug output.
Back to top
View user's profile Send private message
Mit
Apprentice
Apprentice


Joined: 13 Apr 2003
Posts: 260
Location: Under a rock.

PostPosted: Sat Jul 31, 2004 6:08 pm    Post subject: Reply with quote

now, that sort of thing could be useful to feed into a virus scanner for some form of real time scanning on a desktop linux machine... might have a play with it see if i can come up with anything :) as that is the one worry, no specific realtime virus scanner (and as linux popularity increases so will Linux virii/viruses)
Back to top
View user's profile Send private message
twiggy
n00b
n00b


Joined: 25 Nov 2003
Posts: 65
Location: Sweden

PostPosted: Sun Aug 01, 2004 12:08 am    Post subject: Reply with quote

Mit wrote:
..no specific realtime virus scanner (and as linux popularity increases so will Linux virii/viruses)


If that were really true it would happen NOW!
There's no doubt that there will be alot more security flaws but not real viruses for obvious reasons..
_________________
Bite my shiny metal ass!
Back to top
View user's profile Send private message
Mit
Apprentice
Apprentice


Joined: 13 Apr 2003
Posts: 260
Location: Under a rock.

PostPosted: Sun Aug 01, 2004 7:40 am    Post subject: Reply with quote

twiggy wrote:
Mit wrote:
..no specific realtime virus scanner (and as linux popularity increases so will Linux virii/viruses)


If that were really true it would happen NOW!
There's no doubt that there will be alot more security flaws but not real viruses for obvious reasons..

I wouldn't like to bet on that, problem being even thou Linux is inherantly far more secure when it comes to users and access etc, when more people start using it, the 'untrained' ones will start using root to do normal things, just like Windows and Administrator (yes, i've seen people use administrator to surf the net etc on a server)

Anyway, a realtime virus scanner can't do any harm for linux to have one (or many) - maybe i've just not come across one that doesn't have a stupidly large price tag next to it yet... perhaps it does exist :)

Hey, why not more options.. after all, thats what Linux is about - options :D
Back to top
View user's profile Send private message
twiggy
n00b
n00b


Joined: 25 Nov 2003
Posts: 65
Location: Sweden

PostPosted: Sun Aug 01, 2004 2:55 pm    Post subject: Reply with quote

As i said before there will be alot more security issues in the future but you know viruses does NOT feed on popularity! We won't see the same thing that is happening with windows unless everyone starts running everything as root :)
_________________
Bite my shiny metal ass!
Back to top
View user's profile Send private message
GentooBox
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1168
Location: Denmark

PostPosted: Sun Aug 01, 2004 5:27 pm    Post subject: Reply with quote

twiggy wrote:
As i said before there will be alot more security issues in the future but you know viruses does NOT feed on popularity! We won't see the same thing that is happening with windows unless everyone starts running everything as root :)


Im running everything as root. ;)

Its nice to have the kernel module as a extra kernel feature.
i made a script that checks if something is getting written to my binary files or some of them is changed.

I case some guy want to install a backdoor on my box.
_________________
Encrypt, lock up everything and duct tape the rest
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Tue Sep 07, 2004 8:28 pm    Post subject: Reply with quote

doesn't compile on 2.6.9-rc1...
Code:

mirko3 linux # make SUBDIRS=/root/fsysmon-0.1/module/ modules
  CC [M]  /root/fsysmon-0.1/module/fsysmon.o
/root/fsysmon-0.1/module/fsysmon.c: In function `fsysmon_inode_create':
/root/fsysmon-0.1/module/fsysmon.c:80: sorry, unimplemented: inlining failed in call to 'filenames_entry': function body not available
/root/fsysmon-0.1/module/fsysmon.c:201: sorry, unimplemented: called from here
make[1]: *** [/root/fsysmon-0.1/module/fsysmon.o] Error 1
make: *** [_module_/root/fsysmon-0.1/module] Error 2


any clue, anyone?
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Wed Sep 08, 2004 9:12 pm    Post subject: Reply with quote

mirko_3 wrote:
doesn't compile on 2.6.9-rc1...
Code:

mirko3 linux # make SUBDIRS=/root/fsysmon-0.1/module/ modules
  CC [M]  /root/fsysmon-0.1/module/fsysmon.o
/root/fsysmon-0.1/module/fsysmon.c: In function `fsysmon_inode_create':
/root/fsysmon-0.1/module/fsysmon.c:80: sorry, unimplemented: inlining failed in call to 'filenames_entry': function body not available
/root/fsysmon-0.1/module/fsysmon.c:201: sorry, unimplemented: called from here
make[1]: *** [/root/fsysmon-0.1/module/fsysmon.o] Error 1
make: *** [_module_/root/fsysmon-0.1/module] Error 2


any clue, anyone?
This initially happened to me to (not for this specific module(s) though). Are you using GCC 3.4 ?
_________________
~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Mon Sep 13, 2004 1:37 pm    Post subject: Reply with quote

sorry for the delay in replying, but I wasn't at home...
yes, I'm using gcc 3.4... does that mean I have to use 3.3.x?
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Thu Sep 16, 2004 9:28 pm    Post subject: Reply with quote

Ok, gcc-config to switch gcc version and fsysmon compiled. I even was able to force it to load (because of different gcc versions I use to compile the module and the kernel, I had to force it). But it doesn't work; from dmesg:
Code:

fsysmon security module removed
fsysmon: no version magic, tainting kernel.
Module fsysmon init
There is already a security framework initialized, register_security failed.
Failure registering fsysmon module with the kernel
Failure registering fsysmon  module with primary security module.
fsysmon initialized as a security module.


and when I remove it:
Code:
Module fsysmon exit
Failure unregistering fsysmon security module with primary module.
fsysmon security module removed


Any solution?
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Mon Jan 17, 2005 3:23 pm    Post subject: Reply with quote

Hi all!

I've updated the code to work with the later 2.6.x releases. In case you are using udev you have to create the device yourself as described in the readme!

Regards
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Mon Jan 17, 2005 4:51 pm    Post subject: Reply with quote

Why thanks, I'll try it as soon as I have time!
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Sat Jan 22, 2005 7:33 pm    Post subject: Reply with quote

I've just downloaded it, but it does not compile:
Code:

mirko_3 linux # make SUBDIRS=/root/fsysmon-0.2/module/ modules
  CC [M]  /root/fsysmon-0.2/module/fsysmon.o
/root/fsysmon-0.2/module/fsysmon.c: In function `fsysmon_inode_create':
/root/fsysmon-0.2/module/fsysmon.c:81: sorry, unimplemented: inlining failed in call to 'filenames_entry': function body not available
/root/fsysmon-0.2/module/fsysmon.c:202: sorry, unimplemented: called from here
make[1]: *** [/root/fsysmon-0.2/module/fsysmon.o] Error 1
make: *** [_module_/root/fsysmon-0.2/module] Error 2


gcc version 3.4.3 20050110, CONFIG_SECURITY=y. I've no idea about what I might try to make it work....
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Sat Jan 22, 2005 7:55 pm    Post subject: Reply with quote

mirko_3 wrote:

gcc version 3.4.3 20050110, CONFIG_SECURITY=y. I've no idea about what I might try to make it work....


This is realy strange. What kernel are you using? I just tried it again myself and it worked. I'm using gcc (GCC) 3.4.3 20041125 and development-sources-2.6.10-r1. You could PM me your kernel .config then I will try to figure out if it's a kernel issue or not.
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Sat Jan 22, 2005 8:51 pm    Post subject: Reply with quote

done, I sent you a pm
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
BlackB1rd
Tux's lil' helper
Tux's lil' helper


Joined: 13 Aug 2003
Posts: 131
Location: /Europe/Netherlands/Haarlem

PostPosted: Sun Feb 12, 2006 3:34 pm    Post subject: Reply with quote

I really do like this module :) Just wondering if it could be enhanced by printing the current date/time before each file it reports? Don't know anything about C, cannot do it myself ;)
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Mon Feb 13, 2006 10:12 am    Post subject: Reply with quote

BlackB1rd wrote:
I really do like this module :)

I'm glad it's useful. :D

BlackB1rd wrote:

Just wondering if it could be enhanced by printing the current date/time before each file it reports?

This definitely can be done but is this module still needed?
Isn't there meanwhile a mechanism in the kernel (inotify?) that enables filesystem monitoring? (I'm not really up to date on the matter...)

Originally (in 2003) the module was part of an always up to date Desktop Search System which consisted of a small Haskell program that updated a database on file modifications.
Not sure how current systems work: are the always up to date or do you have to update the index after a while like locate?
Back to top
View user's profile Send private message
stef
Tux's lil' helper
Tux's lil' helper


Joined: 23 Jul 2003
Posts: 93

PostPosted: Fri Apr 07, 2006 10:28 am    Post subject: Reply with quote

hm, yes sounds interesting, as i was searching for something like that: https://forums.gentoo.org/viewtopic-t-435829-highlight-.html
anyone ideas if there's already something (using inotify?)
Back to top
View user's profile Send private message
thaldyron
Apprentice
Apprentice


Joined: 25 Sep 2002
Posts: 227
Location: On Earth

PostPosted: Sun Apr 09, 2006 8:53 am    Post subject: Reply with quote

stef wrote:
hm, yes sounds interesting, as i was searching for something like that: https://forums.gentoo.org/viewtopic-t-435829-highlight-.html
anyone ideas if there's already something (using inotify?)

That's the question. I'm wondering if maintaining my tool is still necessary or if I would waste my time doing so. Referring to your original question in the thread above, this should be possible with my module by adding a few lines of code.
Back to top
View user's profile Send private message
Simba
n00b
n00b


Joined: 08 Nov 2002
Posts: 60

PostPosted: Tue Aug 15, 2006 7:47 pm    Post subject: Realtime filesystem monitoring program Reply with quote

Just for information, there is a new tool to monitor filesystem in realtime based on inotify:
http://sourceforge.net/projects/iwatch

Simba
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum