目的

监控Web站点目录(/var/html/www)下的所有文件是否被恶意篡改(文件内容被更改)

文件被更改会有如下特征:

大小可能会变化
修改时间会变化
文件内容会变化,利用md5sum指纹校验
增加或删除文件,对比每次检测前后的文件数量

实验步骤

第一步:在企业网站发布代码后,即对所有网站数据建立初始指纹库和文件库,这个步骤很重要,没有基础的指纹库,无法进行入侵检测

1.建立测试数据

[root@localhost ~]# mkdir /var/html/www -p
[root@localhost ~]# cp -a /etc/a* /var/html/www/
[root@localhost ~]# cp -a /etc/b* /var/html/www/
[root@localhost ~]# ls /var/html/www/
abrt        alsa          at.deny  avahi              bluetooth
adjtime     alternatives  at-spi2  bash_completion.d  bonobo-activation
aliases     anacrontab    audisp   bashrc             brltty
aliases.db  asound.conf   audit    binfmt.d           brltty.conf

2.建立初始的文件指纹库

[root@localhost ~]# find /var/html/www/ -type f|xargs md5sum > /opt/zhiwen.db
[root@localhost ~]# cat /opt/zhiwen.db
0c18947e88b495de161b078c1467c9d6  /var/html/www/abrt/abrt-action-save-package-data.conf
bf1d986df3e106423f132124d10f0820  /var/html/www/abrt/abrt.conf
b6fa2f81eab31d579be78e777b4246cf  /var/html/www/abrt/gpg_keys.conf
2876e889d2a25c672819152946183cee  /var/html/www/abrt/plugins/xorg.conf
......

3.建立初始文件库
/opt/wenjian.db文件中包含初始文件的文件名

[root@localhost ~]# find /var/html/www/ -type f > /opt/wenjian.db
[root@localhost ~]# cat /opt/wenjian.db
/var/html/www/abrt/abrt-action-save-package-data.conf
/var/html/www/abrt/abrt.conf
/var/html/www/abrt/gpg_keys.conf
/var/html/www/abrt/plugins/xorg.conf
/var/html/www/abrt/plugins/python.conf
/var/html/www/abrt/plugins/CCpp.conf
/var/html/www/abrt/plugins/vmcore.conf
/var/html/www/adjtime
/var/html/www/aliases
/var/html/www/aliases.db
......

第二步:监测文件内容和数量的变化

监测文件内容的变化
篡改文件内容:

[root@localhost ~]# echo redhat >> /var/html/www/brltty.conf

检查所有文件内容是否变化:

[root@localhost ~]# md5sum -c --quiet /opt/zhiwen.db
/var/html/www/brltty.conf: FAILED                   #校验失败
md5sum: WARNING: 1 computed checksum did NOT match

2.监测文件数量的变化
新增加文件数:

[root@localhost ~]# echo redhat.txt > /var/html/www/test.txt

利用指纹库无法监测新增文件:

[root@localhost ~]# echo redhat.txt > /var/html/www/test.txt
[root@localhost ~]# md5sum -c --quiet /opt/zhiwen.db
/var/html/www/brltty.conf: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

获取检测前的所有文件数量及文件名:

[root@localhost ~]# find /var/html/www/ -type f > /opt/wenjian.db_curr

采用diff命令比较:

[root@localhost ~]# diff /opt/wenjian.db*
348a349
> /var/html/www/test.txt

开发脚本:
前提恢复操作:

[root@localhost ~]# find /var/html/www/ -type f | xargs md5sum >/opt/zhiwen.db
[root@localhost ~]# find /var/html/www/ -type f > /opt/wenjian.db
[root@localhost mnt]# cat invad_Alarm.sh
#!/bin/bash
RETVAL=0
CHECK_DIR=/var/html/www
[ -e $CHECK_DIR ] || exit 1zhiwendb="/opt/zhiwen.db"
filedb="/opt/wenjian.db"
errlog="/opt/err.log"[ -e $zhiwendb ] || exit 1
[ -e $filedb ] || exit 1#judge file content
echo "[root@desktop mnt]# md5sum -c --quiet /opt/zhiwen.db" >$errlog
md5sum -c --quiet /opt/zhiwen.db &>/dev/null
RETVAL=$?#com file count
find /var/html/www/ -type f >/opt/wenjian.db_curr
echo "[root@desktop mnt]# diff /opt/wenjian.db*" &>>$errlog
diff /opt/wenjian.db*" &>>$errlogif [ $RETVAL -ne 0 -o `diff /opt/wenjian.db* | wc -l` -ne 0 ];thentouch /tmp/`date +%s`.err
elseecho "Site dir is ok"
fi
[root@localhost mnt]# sh invad_Alarm.sh
Site dir is ok

篡改文件后再检测:

[root@localhost mnt]# sh invad_Alarm.sh
Site dir is ok
[root@localhost mnt]# echo redhat >> /var/html/www/brltty.conf
[root@localhost mnt]# sh invad_Alarm.sh
[root@localhost mnt]# cat /opt/err.log                 #查看错误日志
[root@desktop mnt]# md5sum -c --quiet /opt/zhiwen.db
[root@desktop mnt]# diff /opt/wenjian.db*

shell编程中文件安全性的保证相关推荐

  1. ll文件显示为?????_关于shell编程中的文件测试简单的操作实例

    谈一谈关于shell编程中的文件测试 Shell编程有时处理一个对象时,需要我们对对象进行测试. 只有符合要求的才采取下一步操作,这样做的好处可以避免程序出错. 这个测试的对象可以是文件.字符串.数字 ...

  2. shell编程中特殊字符的问题总结

    shell编程中特殊字符的问题总结 --同事王怡春的总结: 近日在编写shell脚本的遇到的一些问题,然后上网搜搜学习后,以下是总结后的版本,给大家分享,如有问题,错误,欢迎指正 一 通配符( * ) ...

  3. shell 不等于_关于shell编程中的整数值比较的两种方式的简单操作实例

    谈一谈关于shell编程中的整数值比较的两种方式 Shell编程有时处理一个对象时,需要我们对对象进行测试. 只有符合要求的才采取下一步操作,这样做的好处可以避免程序出错. 这个测试的对象可以是文件. ...

  4. shell编程中for/while/util/case/select/break/continue

    2019独角兽企业重金招聘Python工程师标准>>> Shell编程中循环命令用于特定条件下决定某些语句重复执行的控制方式,有三种常用的循环语句:for.while和until.w ...

  5. shell编程中如何执行oracle语句

    shell编程中如果向oracle中插入数据之类的,需要先把执行语句放到文件中,然后再@这个文件执行 有如下俩种方式供参考: SQL=`sqlplus user/pwd@orains << ...

  6. linux shell let命令,shell编程中的let与(())

    let与(()) 在shell编程中是可以互换的:它们在循环语句中控制变量变化非常有用: 使用let语句或者(())我们可以像C语言那样写程序~ 对于变量赋值,判断什么的不用繁琐的$VAR, -eq等 ...

  7. 掌握shell编程中数组的常见用法及示例

    From: http://www.embeddedlinux.org.cn/html/jishuzixun/201211/19-2386.html 给大家分享下数组的用法小例子,希望能给大家一点帮助. ...

  8. 轻松掌握shell编程中数组的常见用法及示例

    缘起:在老男孩进行linux培训shell编程教学中,发现不少水平不错的网友及同学对数组仍然很迷糊,下面就给大家分享下数组的用法小例子,希望能给大家一点帮助.其实SHELL的数组很简单,好用.我们学习 ...

  9. shell 编程中空格的使用,双引号,单引号,反引号

    http://blog.csdn.net/panda19881/article/details/6626727 1.定义变量时, =号的两边不可以留空格. eg: gender=femal----ri ...

最新文章

  1. python操作mysql数据库依赖包_python安装mysql的依赖包mysql-python操作
  2. 支付宝和微信的支付流程图
  3. Java实现定时调度的三种方法
  4. Sicily 6768. Log Books 解题报告
  5. 【实验】不会端口映射?看完就会了
  6. 这个 bug 让我更加理解 Spring 单例了
  7. WebSocket协议入门介绍
  8. linux dhcpd 设置 关于 subnet
  9. 如你以安全模式启动计算机,如何以安全模式启动计算机?
  10. 算法萌新如何学好动态规划(一)
  11. 联网时浏览器跳出MSN中国
  12. cad 2005 计算机,AutoCAD2005
  13. NRF24L01入门总结
  14. php微积分难吗,两句话让你学好微积分
  15. build up__css
  16. Passenger 和 Nginx
  17. #NameError: name ‘x‘ is not defined
  18. 【油猴脚本】忽视页面跳转拦截,自动继续访问页面
  19. CLRS 16.1活动选择问题
  20. ipv6的地址格式 和 常用地址

热门文章

  1. div上下左右居中老调重弹
  2. 全球与中国涂料和油墨用丙烯酸树脂市场发展规划展望及未来需求预测报告2021年版
  3. marquee标签_html滚动文字
  4. ERD Online 4.1.0对接ChatGPT,实现AI建模、SQL自由
  5. 内核proc参数注释(kernel、vm、net、fs四类)
  6. 该微信用户未开启“公众号安全助手”的消息接收功能,请先开启后再绑定 解决方法
  7. ROS2规划系统plansys2简单的例子
  8. iphone中获取屏幕分辨率的方法
  9. 一道很水的题(南工校赛决赛第一题)
  10. 云服务器和虚拟主机有什么区别?哪个比较好呢?