2017年09月13日 16:27:19 Hai__Yun 阅读数:3020 标签: 管理木马 更多node
我的分类: linuxlinux
版权声明:感谢阅读,一直在努力。有什么建议或者不足之处还望多多见谅,能够留言告诉小编,小编会虚心接受你们的意见 https://blog.csdn.net/Hai__Yun/article/details/77967748算法
当一个入侵者进入了你的系统而且种植了木马,一般会想法来隐蔽这个木马(除了木马自身的一些隐蔽特性外,他会尽可能给你检查系统的过程设置障碍),一般入侵者会修改一些文件,好比管理员一般用ps -aux
来查看系统进程,那么入侵者极可能用本身通过修改的ps
程序来替换掉你系统上的ps
程序,以使用ps命令查不到正在运行的木马程序。若是入侵者发现管理员正在运行crontab
做业,也有可能替换掉crontab
程序等等。因此由此能够看出对于系统文件或是关键文件的检查是很必要的。目前就系统完整性检查的工具用的比较多的有两款: Tripwire
和AIDE
,前者是一款商业软件,后者是一款免费的但功能也很强大的工具。sql
AIDE
(Advanced Intrusion Detection Environment
,高级入侵检测环境)是个入侵检测工具,主要用途是检查文档的完整性。数据库
AIDE
可以构造一个指定文件的数据库,它使用aide.conf
做为其配置文件。 AIDE
数据库可以保存文件的各类属性,包括:权限(permission
)、索引节点序号(inode number
)、所属用户(user
)、所属用户组(group
)、文件大小、最后修改时间(mtime
)、建立时间(ctime
)、最后访问时间(atime
)、增长的大小以及链接数。 AIDE
还可以使用下列算法: sha1
、 md5
、 rmd160
、 tiger
,以密文形式创建每一个文件的校验码或散列号.vim
/proc
文件系统、用户起始目录以及临时目录.[root@A ~]# yum install -y aide #使用yum安装 Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package aide.x86_64 0:0.14-11.el6 will be installed --> Finished Dependency Resolution 。。。省略后面内容
配置文件路径:/etc/aide.conf
安全
定义监控/app
目录,但不监控/app
目录下的f3
文件。规则为:权限+全部者+所属组+sha512+修改时间+访问时间+改变时间app
[root@A ~]# cp /etc/aide.conf /etc/aide.conf.bak #对配置文件修改前建议备份 [root@A ~]# vim /etc/aide.conf #编辑配置文件 # Example configuration file for AIDE. @@define DBDIR /var/lib/aide #数据库目录 @@define LOGDIR /var/log/aide #日志目录 # The location of the database to be read. database=file:@@{DBDIR}/aide.db.gz #数据库文件 # The location of the database to be written. #database_out=sql:host:port:database:login_name:passwd:table #database_out=file:aide.db.new database_out=file:@@{DBDIR}/aide.db.new.gz # Whether to gzip the output to database gzip_dbout=yes # Default. verbose=5 report_url=file:@@{LOGDIR}/aide.log report_url=stdout #report_url=stderr #NOT IMPLEMENTED report_url=mailto:root@foo.com #NOT IMPLEMENTED report_url=syslog:LOG_AUTH # These are the default rules. # #p: permissions #权限 #i: inode: #索引节点 #n: number of links #连接数 #u: user #用户 #g: group #组 #s: size #大小 #b: block count # 块大小 #m: mtime # 修改时间 #a: atime # 访问时间 #c: ctime # 改变时间 #S: check for growing size #检查增长的大小 #acl: Access Control Lists #selinux SELinux security context #xattrs: Extended file attributes #md5: md5 checksum #md5校验 #sha1: sha1 checksum # sha1校验 #sha256: sha256 checksum #sha256校验 #sha512: sha512 checksum #sha512校验 #rmd160: rmd160 checksum #rmd160校验 #tiger: tiger checksum #tiger校验 #rmd160: rmd160 checksum #rmd160校验 #tiger: tiger checksum #tiger校验 #haval: haval checksum (MHASH only) # haval校验 #gost: gost checksum (MHASH only) # gost校验 #crc32: crc32 checksum (MHASH only) # crc32校验 #whirlpool: whirlpool checksum (MHASH only) #R: p+i+n+u+g+s+m+c+acl+selinux+xattrs+md5 #L: p+i+n+u+g+acl+selinux+xattrs #E: Empty group #>: Growing logfile p+u+g+i+n+S+acl+selinux+xattrs # You can create custom rules like this. # With MHASH... # ALLXTRAHASHES = sha1+rmd160+sha256+sha512+whirlpool+tiger+haval+gost+crc32 ALLXTRAHASHES = sha1+rmd160+sha256+sha512+tiger # Everything but access time (Ie. all changes) EVERYTHING = R+ALLXTRAHASHES # Sane, with multiple hashes # NORMAL = R+rmd160+sha256+whirlpool NORMAL = R+rmd160+sha256 # For directories, don't bother doing hashes DIR = p+i+n+u+g+acl+selinux+xattrs # Access control only PERMS = p+i+u+g+acl+selinux # Logfile are special, in that they often change LOG = > # Just do md5 and sha256 hashes LSPP = R+sha256 # Some files get updated automatically, so the inode/ctime/mtime change # but we want to know when the data inside them changes DATAONLY = p+n+u+g+s+acl+selinux+xattrs+md5+sha256+rmd160+tiger mon = p+u+g+sha512+m+a+c # 自定义规则监控:权限+全部者+所属组+sha512+修改时间+访问时间+改变时间 /app mon #定义/app目录使用规则 mon !/app/f3 #可是/app目录下的f3文件不监控,“!”表示忽略这个文件的检查
[root@A app]# cp /etc/fstab /app/f1 #先把文件建立好 [root@A app]# echo 123 > f2 [root@A app]# echo www.iav18.cn > f3 [root@A app]# ls f1 f2 f3 [root@A app]# aide --init AIDE, version 0.14 ### AIDE database at /var/lib/aide/aide.db.new.gz initialized.
把当前初始化的数据库做为开始的基础数据库(建议初始数据库存放到安全的地方)ide
[root@A ~]# cd /var/lib/aide/ [root@A aide]# ls aide.db.new.gz [root@A aide]# cp aide.db.new.gz aide.db.gz [root@A aide]# ls aide.db.gz aide.db.new.gz
[root@A ~]# aide --check #检测定义的/app目录是否被改动,没有被改动 AIDE, version 0.14 ### All files match AIDE database. Looks okay! [root@A ~]# cd /app/ #切换到/app目录 [root@A app]# ls # 列出目录下的内容 f1 f2 f3 [root@A app]# echo > f1 #输入一个换行符到f1文件 [root@A app]# aide --check #再次检查,发现文件f1的 SHA5十二、Ctime、Mtime已经被修改 AIDE found differences between database and filesystem!! Start timestamp: 2017-09-13 15:18:54 Summary: Total number of files: 4 Added files: 0 Removed files: 0 Changed files: 1 --------------------------------------------------- Changed files: --------------------------------------------------- changed: /app/f1 -------------------------------------------------- Detailed information about changes: --------------------------------------------------- File: /app/f1 Mtime : 2017-09-13 15:08:30 , 2017-09-13 15:18:51 Ctime : 2017-09-13 15:08:30 , 2017-09-13 15:18:51 SHA512 : ej+ts/Q6q9CANmKXMfdEdCv3Lcl1otID , vmiIOMqGhuXJBom/KrWFzvETfJmbSMcL
若是是合法的修改,那么也会被检测出有问题。此时就须要更新数据了。工具
[root@A app]# aide -c /etc/aide.conf --update #更新数据库 AIDE found differences between database and filesystem!! Start timestamp: 2017-09-13 15:25:29 Summary: Total number of files: 4 Added files: 0 Removed files: 0 Changed files: 1 --------------------------------------------------- Changed files: --------------------------------------------------- changed: /app/f1 -------------------------------------------------- Detailed information about changes: --------------------------------------------------- File: /app/f1 Atime : 2017-09-13 15:10:09 , 2017-09-13 15:18:54 Mtime : 2017-09-13 15:08:30 , 2017-09-13 15:18:51 Ctime : 2017-09-13 15:08:30 , 2017-09-13 15:18:51 SHA512 : ej+ts/Q6q9CANmKXMfdEdCv3Lcl1otID , vmiIOMqGhuXJBom/KrWFzvETfJmbSMcL [root@A app]# cd /var/lib/aide/ #cd到/var/lib/aide/目录 [root@A aide]# ls aide.db.gz aide.db.new.gz [root@A aide]# cp aide.db.new.gz aide.db.gz #覆盖基准数据库 cp: overwrite `aide.db.gz'? y [root@A aide]# aide --check #再次检查数据库就没问题了。 AIDE, version 0.14 ### All files match AIDE database. Looks okay!