Linux系统是服务器最常见的操作系统,当然也面临着非常多的安全事件,相较Windows操作系统,Linux采用了明确的访问权限控制和全面的管理工具,具有非常高的安全性和稳定性。Linux系统被入侵后,攻击者为了掩盖踪迹,经常会清除系统中的各种日志,包括Web的access和error日志、last日志、message日志、secure日志等,给我们后期应急响应和取证分析带来了非常大的阻力。所以,恢复被清除的日志是非常重要的取证和分析环节,一下是使用lsof命令恢复日志文件的案例,适用于常见的日志恢复工作。
一、前提条件
不能关闭服务器,不能关闭相关服务或进程,如恢复apache的访问日志 /var/log/httpd/access_log ,不能关闭或者重启服务器系统,也不能重启httpd服务。
二、实施过程
1. 找到相关进程pid
复制代码
[root@localhost ~]# lsof | grep access_log
httpd 1392 root 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7330 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7331 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7332 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7333 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7334 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7335 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7336 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7337 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
代码如下:
[root@localhost ~]# lsof | grep access_log
httpd 1392 root 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7330 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7331 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7332 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7333 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7334 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7335 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7336 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
httpd 7337 apache 7w REG 253,0 0 263802 /var/log/httpd/access_log
这里我们重点关注一下第一、第二、第三、第四列,分别表示进程名、pid、用户、文件描述符,我们看到这里的文件描述符是7w,所以我们在下一步操作过程要记住这个7.
2. 找回日志
复制代码
[root@localhost ~]# wc -l /proc/1392/fd/7
55 /proc/1392/fd/7
[root@localhost ~]# cat /proc/1392/fd/7 > /var/log/httpd/access_log
代码如下:
[root@localhost ~]# wc -l /proc/1392/fd/7
55 /proc/1392/fd/7
[root@localhost ~]# cat /proc/1392/fd/7 > /var/log/httpd/access_log
我们先通过wc或者tail命令查看日志信息,然后再将日志重写到access_log中即可。
三、总结
在Linux系统的/proc 分区下保存着进程的目录和名字,包含fd(文件描述符)和其下的子目录(进程打开文件的链接),那么如果删除了一个文件,还存在一个 inode的引用:/proc/进程号/fd/文件描述符。我们只要知道当前打开文件的进程pid和文件描述符fd就能利用lsof工具列出进程打开的文件。通过lsof我们就可以进行简单的文件恢复工作,当然这里不局限于日志文件,只要是存在引用的文件。
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 80
-
2025-05-29 30
-
2025-05-25 38
-
2025-05-25 57
-
2025-05-29 84
热门评论