Linux操作系统被入侵的原因通常可以归结为两大类。首先是弱密码问题,许多用户为了方便管理,使用简单或默认的密码,这使得攻击者能够通过暴力破解或字典攻击轻松获取系统访问权限。其次是软件漏洞问题,许多系统管理员未能及时关闭不必要的端口和服务,或未能及时修补已知的漏洞。这些开放的端口和未修补的漏洞,成为了攻击者利用专门工具发起攻击的切入点,大大增加了系统被入侵的风险。合理的密码管理和及时的系统更新对于提高系统安全性至关重要。
当系统出现异常时,怀疑系统被入侵,可以通过以下方式进行排查。
检查用户信息文件 /etc/passwd,查询特权用户特权用户(uid 为0)
awk -F: '$3==0{print $1}' /etc/passwd
检查用户密码文件 /etc/shadow,查询可以远程登录的帐号信息
awk '/\$1|\$6/{print $1}' /etc/shadow
ubuntu系检查/var/log/auth.log文件,centos系检查/var/log/secure文件,记录了系统的认证信息,包含了用户的登录和失败尝试,
grep "Failed password" /var/log/auth.log
grep "Accepted password" /var/log/auth.log
grep "Failed password" /var/log/secure
grep "Accepted password" /var/log/secure,
查找尝试登录的 IP 地址,并统计出现的次数
grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr
who查看当前登录用户(tty本地登陆pts远程登录)
last显示系统的历史登录记录,包括用户、登录时间、登录方式等
w查看系统信息,想知道某一时刻用户的行为
uptime查看登陆多久、多少用户,负载
检查异常端口和连接
netstat -antlp|more
查看下pid所对应的进程文件路径,运行ls -l /proc/$PID/exe或file /proc/$PID/exe($PID 为对应的pid 号)
检查异常进程
使用ps命令,分析进程
ps aux | grep pid
入侵排查:
启动项文件: more /etc/rc.local /etc/rc.d/rc[0~6].d ls -l /etc/rc.d/rc3.d/
检查定时任务
基本使用
1、利用crontab创建计划任务基本命令
crontab -l 列出某个用户cron服务的详细内容
Tips:默认编写的crontab文件会保存在 (/var/spool/cron/用户名 例如: /var/spool/cron/root crontab -r 删除每个用户cront任务(谨慎:删除所有的计划任务)
crontab -e 使用编辑器编辑当前的crontab文件
如:*/1 * * * * echo “hello world” >> /tmp/test.txt 每分钟写入文件
2、利用anacron实现异步定时任务调度使用案例
每天运行 /home/backup.sh脚本: vi /etc/anacrontab @daily 10 example.daily /bin/bash /home/backup.sh 当机器在 backup.sh 期望被运行时是关机的,anacron会在机器开机十分钟之后运行它,而不用再等待 7天。
入侵排查
重点关注以下目录中是否存在恶意脚本
/var/spool/cron/*
/etc/crontab
/etc/cron.d/*
/etc/cron.daily/*
/etc/cron.hourly/*
/etc/cron.monthly/*
/etc/cron.weekly/
/etc/anacrontab
/var/spool/anacron/*上面目录都是与 Linux 系统中的定时任务(cron)相关的目录 。定时任务是一种在指定时间或周期执行某些命令或脚本的功能。每个目录的作用如下:
• /var/spool/cron/* :存放每个用户(包括 root)的 crontab 文件,每个文件以用户名命名,用于定义用户自己的定时任务 。
• /etc/crontab :系统级别的 crontab 文件,由 root 用户管理,用于定义系统级别的定时任务 。
• /etc/cron.d/* :存放一些特殊格式的 crontab 文件,可以被 /etc/crontab 文件引用,也可以单独运行
• /etc/cron.daily/* ,/etc/cron.hourly/* ,/etc/cron.monthly/* ,/etc/cron.weekly/ :存放按照日、小时、月、周周期执行的脚本文件 。
• /etc/anacrontab :anacron 是 cron 的一个补充工具,用于在系统没有运行或关机时执行错过的定时任务 。这个文件用于定义 anacron 的配置和任务
• /var/spool/anacron/* :存放 anacron 的时间戳文件,记录上次执行任务的时间
检查服务
服务自启动
第一种修改方法:
chkconfig [–level 运行级别] [独立服务名] [on|off]
chkconfig –level 2345 httpd on
开启自启动chkconfig httpd on (默认level是2345)
入侵排查
1、查询已安装的服务:
RPM包安装的服务
chkconfig –list 查看服务自启动状态,可以看到所有的RPM包安装的服务
ps aux | grep crond 查看当前服务
检查异常文件
1、查看敏感目录,如/tmp目录下的文件,同时注意隐藏文件夹,以“..”为名的文件夹具有隐藏属性
2、得到发现WEBSHELL、远控木马的创建时间,如何找出同一时间范围内创建的文件?
可以使用find命令来查找,如 find /opt -iname “*” -atime 1 -type f 找出 /opt 下一天前访问过的文件
3、针对可疑文件可以使用stat进行创建修改时间。
This deep dive into Linux forensics highlights that technical defenses are only as strong as the operational processes. Remember that robust security requires a ‘Defense-in-Depth’ mindset, focusing on user training and zero-trust principles, not just patching. For seamless access to advanced tools and platforms, checking out 2jl download apk can be useful.
Wondering about the payment tech behind sites like 6bet? It’s more than just the games; the financial backbone really matters for a smooth player experience. 🤔
Really digging the structure here! For newcomers, the step-by-step approach is key. If you’re looking for more guided learning, check out Jilicrown APK vip; it seems very thorough.