应急响应入门篇linux分析排查技术_上_

针对常见的攻击事件,结合工作中应急响应事件分析和解决的方法,总结了一些 Linux 服务器入侵排查的思路。

img (opens new window)

# 前言:

当企业发生黑客入侵、系统崩溃或其它影响业务正常运行的安全事件时,急需第一时间进行处理,使企业的网络信息系统在最短时间内恢复正常工作,进一步查找入侵来源,还原入侵事故过程,同时给出解决方案与防范措施,为企业挽回或减少经济损失。 针对常见的攻击事件,结合工作中应急响应事件分析和解决的方法,总结了一些 Linux 服务器入侵排查的思路。

# 01 文件分析 - 敏感文件信息

在 linux 系统下一切都是文件,其中 / tmp 是一个特别的临时目录文件。每个用户都可以对它进行读写操作。因此一个普通用户可以对 / tmp 目录执行读写操作。

查看敏感目录文件,如 tmp 目录、可执行程序目录 / usr/bin ,/usr/sbin 等

\1. 使用 la -alt / 查找 tmp 目录

img (opens new window)

\2. 使用 ls —help 查看帮助信息

img (opens new window)

3.ls 的常用用法: ls 用来显示目录列表

-a 显示所有档案及目录

-l 以长格式显示目录下的内容列表

-t 用文件和目录的更改时间排序

img (opens new window)

\4. 进入 tmp 目录,查找最近新添加的可疑文件。

img (opens new window)

# 02 文件分分析 - 敏感文件信息

查看开机启动项内容 / etc/init.d/,恶意代码很有可能设置在开机启动的位置。

查看指定目录下文件时间顺序的排序:ls -alt | head -n 10

查看文件时间属性: stat 文件名

使用 ls -alh /etc/init.d // 查看开机启动项

img (opens new window)

img (opens new window)

进入开机启动项目录,对其进行筛选。

img (opens new window)

针对可以文件可以使用 stat 进行创建修改时间、访问时间的详细查看,若修改时间距离时间日期接近,有线性关联,说明可以被篡改。

如:stat apache2 查看文件详细信息。

img (opens new window)

# 03 文件分析 - 敏感文件信息

主要针对新增文件分析:

查找 24h 内被修改的文件

find ./ -mtime 0 -name “*.php”

查找 72h 内新增的文件

find ./ -ctime -2 -name “‘*.php”

权限查找,在 linux 系统中,如果具有 777 权限,那么文件就很可疑。

find ./ -iname “*.php” -perm 777 其中 -iname 忽略大小写,-perm 用于设定筛选文件权限

img (opens new window)

find ./ -ctime -2 -name “‘*.txt” // 查找 72h 内新增的 txt 文件。

img (opens new window)

find ./ -iname “*.php” -perm 777 // 查找最近新建的含. php 文件的,具有最高权限的文件。

img (opens new window)

新建立一个 z.php 文件,给予最高权限。

img (opens new window)

再次进行筛选。

img (opens new window)

# 04 - 网络连接分析

在 linux 中可以使用 netstat 进行网络连接查看

netstat -Print network connections,rounting tables,interface statistics,masquerade connections,and multicast memberships

具体帮助信息查看 man netstat

常用命令 netstat -pantl 查看处于 tcp 网络套接字相关信息

关闭未知连接使用 kill -9 pid 既可关闭。

使用:netstat -pantl 查看处于 tcp 网络套接字相关信息

img (opens new window)

ip a 查看网络信息

img (opens new window)

发现可疑进程,使用 kill -9 + pid 值,然后关闭进程。

img (opens new window)

# 05 - 进程分析 - 进程所对文件

使用 ps 命令,分析进程。根据 netstat 定位出 pid ,使用 ps 命令,分析进程

使用 ps aux 查看你所有进程信息

img (opens new window)

ps aux | grep “22” 查看最近使用了 22 端口的进程。

img (opens new window)

使用 pid 进行筛选

img (opens new window)

img (opens new window)

img (opens new window)

筛选 pid 为 647 的 进程。

img (opens new window)

img (opens new window)

查看端口未 22 的隐藏进程

img (opens new window)

# 06 - 登录分析 - 筛选异常登录

在 Linux 做的操作都会被记录到系统日志中,对于登录也可以查看日志信息查看是否有异常登录

last 命令记录着所有用户登录系统的日志,可以用来查找非授权用户的登录事件,而 last 命令的输出结果来源于 /var/log/wtmp 文件,稍有经验的入侵者都会删掉 /var/log/wtmp 以清除自己行踪,但是还是会露出蛛丝马迹在此文件中的

last -i grep -h 0.0.0.0 查看登录日志,筛选非本地登录

img (opens new window)

last -i // 查看登录日志,含登录 ip 地址。

img (opens new window)

last -i grep -v 0.0.0.0 查看登录日志,筛选非本地登录

img (opens new window)

img (opens new window)

常见的用法: who 查看当前登录用户(tty 本地登陆 pts 远程登录) w 查看某一时刻用户的行为 uptime 查看有多少用户,以此确定是否存在异常用户 lastb 显示登录失败次数,判断是存在 ssh 爆破 last 显示用户最近登录信息。 lastlog 登录成功记录

# 总结:

本文主要总结了在遇到了 Linux 系统时,应急响应先从对敏感文件分析、敏感文件信息、网络连接分析、进程分析、异常登录记录进行分析。

全文完

本文由 简悦 SimpRead (opens new window) 优化,用以提升阅读体验

使用了 全新的简悦词法分析引擎 beta,点击查看 (opens new window)详细说明

前言: (opens new window)01 文件分析 - 敏感文件信息 (opens new window)02 文件分分析 - 敏感文件信息 (opens new window)03 文件分析 - 敏感文件信息 (opens new window)04 - 网络连接分析 (opens new window)05 - 进程分析 - 进程所对文件 (opens new window)06 - 登录分析 - 筛选异常登录 (opens new window)总结: (opens new window)

Last Updated: 2022/7/8 下午2:41:42