摘 要
近年来,Linux操作系统迅速在中国普及,同时Linux操作系统的安全性也受到大家的关注,本文详细描述了在 Linux操作系统下如何对文件系统的各种操作进行有效的监控。 当前对于Linux操作系统安全性的解决方法是用户级限制,对某个文件的读写位进行限制,这样很容易被黑客攻击,使操作系统的安全性大大降低,针对操作系统的以上缺陷,本文描述了利用一种新的内核机制来监控对文件的各种操作,用户只需要限定要监控的目录或文件,inotify设备将自动捕获相关文件操作信息,反馈给用户,使用户对相关目录或文件的使用情况得到及时的了解,大大提高了系统的安全性。 本文主要介绍了利用inotify机制来完成文件系统监控功能,对用户所进行的文件相关操作记录下来,反馈给订阅相关服务人员,此外针对开发中涉及到的包括多线程问题、共享内存问题、GTK+编程、编译内核等难点,本文介绍了需要注意的问题,并提出了解决方案。 最后,本文结合实验验证了监控系统软件的有效性,得到了良好的结 果,并对软件的进一步开发,提出了建议。 关键字:Linux;文件监控系统;inotify;GTK+;线程技术; Abstract Recently, Linux operating system is becoming universal at an increasing rate. Meanwhile, more and more attention is paid to its security. This paper describes in detail how to monitor effectively all kinds of operations to files system under Linux operating system. At present, the solution to the security problems of Linux operating system is the constrains at the user level, that is, constrain the read/write location of a certain file. However, this leads to easier attack by hacker and low security of operating system. In view of the foregoing fault of operating system, this paper introduced a new way using a new kernel mechanism to monitor each operation to files. In that way, what the users need to do is to clear the indexes or files to be monitored, and the equipment will gather relating operating information automatically and return it to the users. As a result, users get a timely recognition of using condition to relating indexes or files and the security of the system a great improvement. This paper introduces how to monitor the action about file by using inotify, and give the information to the users who book the file.Besides, this paper introduces the problems need to be considered in using of and the resolution to the problems will be encountered in system development, like the problem of multithreading, GTK+ programming, kernel compiling and so on. Finally, integrated with experiment, this paper tests the effectiveness of the monitoring system software, attains a satisfied results, and in addition, gives suggestions to the software’s further development. key word: Linux;inotify;file monitor system;GTK+;Multithreading technique; 目 录 第一章 引言 4 1.1课题目的和意义 5 1.2国际国内研究状况和进展 5 1.3本文工作 6 第二章 INOTIFY新机制的介绍 7 2.1、INOTIFY简介 7 2.2、用户接口 8 2.3、内核实现机理 9 2.4、使用示例 12 2.5、典型应用 16 第三章 关键技术介绍 18 3.1 LINUX内核补丁及编译 18 3.2 GTK+的应用 19 3.3 多线程技术 24 3.4 MYSQL技术 29 第四章 文件监控系统的业务需求 40 第五章 监控系统的总体结构 41 5.1 系统开发、运行环境 41 5.2 系统结构以及功能 41 第六章 监控系统的详细设计 45 6.1 功能设计 45 6.2 模块设计 46 6.3 数据库设计 48 第七章 文件监控系统的原型实现 51 7.1 系统运行准备 51 7.2 实时监控功能 53 7.3 查询功能 55 7.4用户管理及订阅功能 58 第八章 工作总结及展望 65 8.1工作总结 66 8.2工作展望 66 参考文献 67 第一章 引言 1.1课题目的和意义 当UNIX/LINUX迅猛发展的同时,黑客也利用各种技术漏洞,对操作系统加以攻击,通常黑客在获得系统的root权限后,都要在系统上留下一定的后门,以备再次登陆之便。后门的留法可谓多种多样,但是多数都是采用替换系统配置文件,或者是其它二进制可执行文件的方法来实现。以往的做法是在做完系统后,对系统安全相关的配置文件和可执行文件进行校验,生成校验码,保存下来,在以后的系统检察中,查看文件的校验码是否改变,如果发生改变,则可以认为系统已被攻破,不再可信,需要恢复!这确实能够达到目的,但是这种做法欠实时性,并且效率较为低下。Linux系统的2.6以上内核为我们提供了另一种监视文件系统变化的途径,它就是inotify机制!inotify机制是由著名开源桌面搜索beagle首先引入的,因为PC环境中较少有文件系统的变化,并且没有必要为每次文件系统的变化都重建索引,那样做效率是及其低下的,事实上,我们只需要重建更改部分的索引就行了。所以inotify就诞生了。inotify以前曾用设备文件的方式实现内核和用户空间的通信,现在改成了系统调用并且被官方内核采纳。 本文详细介绍利用inotify这种新机制来对操作系统的安全性加以提高,对inotify的用法加以详细的论述,论题就是围绕着inotify展开讨论。 |