- 极安网首页
- 网络安全工具
Linux应急响应检测脚本(挖矿/病毒检测)
作者:Admin • 发布:
• 栏目:
网络安全工具 挖矿病毒检测脚本
- #!/bin/bash
- echo "Linux安全检查与应急响应工具"
- echo "Version:1.3"
- echo "Author:Daily"
- echo "Date:2020-11-11"
- dos2unix buying.sh
- date=$(date +%Y%m%d-%H%M%S)
- ipadd=$(ifconfig -a | grep -w inet | grep -v 127.0.0.1 | awk 'NR==1{print $2}')
- check_file="/tmp/buying_${ipadd}_${date}/check_file/"
- danger_file="/tmp/buying_${ipadd}_${date}/danger_file.txt"
- log_file="/tmp/buying_${ipadd}_${date}/log/"
- rm -rf $check_file
- rm -rf $danger_file
- rm -rf log_file
- mkdir /tmp/buying_${ipadd}_${date}/
- echo "检查发现危险项,请注意:" > ${danger_file}
- mkdir $check_file
- echo "" >> $danger_file
- mkdir $log_file
- cd $check_file
- if [ $(whoami) != "root" ];then
- echo "安全检查必须使用root账号,否则某些项无法检查"
- exit 1
- fi
- saveresult="tee -a checkresult.txt"
- echo "[0.1]正在检查IP地址....." && "$saveresult"
- echo -------------0.IP及版本-------------------
- echo -------------0.1IP地址-------------------
- echo "[0.1]正在检查IP地址....." | $saveresult
- ip=$(ifconfig -a | grep -w inet | awk '{print $2}')
- if [ -n "$ip" ];then
- (echo "[*]本机IP地址信息:" && echo "$ip") | $saveresult
- else
- echo "[!!!]本机未配置IP地址" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------12历史命令--------------------------
- echo ------------12.1系统操作历史命令---------------
- echo ------------12.1.1系统操作历史命令---------------
- echo "[12.1.1]正在检查操作系统历史命令....." | $saveresult
- history=$(more /root/.bash_history)
- if [ -n "$history" ];then
- (echo "[*]操作系统历史命令如下:" && echo "$history") | $saveresult
- else
- echo "[!!!]未发现历史命令,请检查是否记录及已被清除" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------2.网络连接---------------------
- echo "[2.1]正在检查网络连接情况....." | $saveresult
- netstat=$(netstat -anlp | grep ESTABLISHED)
- netstatnum=$(netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}')
- if [ -n "$netstat" ];then
- (echo "[*]网络连接情况:" && echo "$netstat") | $saveresult
- if [ -n "$netstatnum" ];then
- (echo "[*]各个状态的数量如下:" && echo "$netstatnum") | $saveresult
- fi
- else
- echo "[*]未发现网络连接" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------20.2CPU分析-----------------
- echo ------------20.2.1CPU情况-----------------
- echo "[20.2.1]正在检查CPU相关信息....." | $saveresult
- (echo "CPU硬件信息如下:" && more /proc/cpuinfo ) | $saveresult
- (echo "CPU使用情况如下:" && ps -aux | sort -nr -k 3 | awk '{print $1,$2,$3,$NF}') | $saveresult
- printf "\n" | $saveresult
- echo ------------20.2.2占用CPU前5进程-----------------
- echo "[20.2.2]正在检查占用CPU前5资源的进程....." | $saveresult
- (echo "占用CPU资源前5进程:" && ps -aux | sort -nr -k 3 | head -5) | $saveresult
- printf "\n" | $saveresult
- echo ------------20.2.3占用CPU较大进程-----------------
- echo "[20.2.3]正在检查占用CPU较大的进程....." | $saveresult
- pscpu=$(ps -aux | sort -nr -k 3 | head -5 | awk '{if($3>=20) print $0}')
- if [ -n "$pscpu" ];then
- echo "[!!!]以下进程占用的CPU超过20%:" && echo "UID PID PPID C STIME TTY TIME CMD"
- echo "$pscpu" | tee -a 20.2.3_pscpu.txt | tee -a $danger_file | $saveresult
- else
- echo "[*]未发现进程占用资源超过20%" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------7.进程分析--------------------
- echo ------------7.1系统进程--------------------
- echo "[7.1]正在检查进程....." | $saveresult
- ps=$(ps -aux)
- if [ -n "$ps" ];then
- (echo "[*]系统进程如下:" && echo "$ps") | $saveresult
- else
- echo "[*]未发现系统进程" | $saveresult
- fi
- printf "\n" | $saveresult
- echo "[7.2]正在检查守护进程....." | $saveresult
- if [ -e /etc/xinetd.d/rsync ];then
- (echo "[*]系统守护进程:" && more /etc/xinetd.d/rsync | grep -v "^#") | $saveresult
- else
- echo "[*]未发现守护进程" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------9.运行服务----------------------
- echo "[9.1]正在检查运行服务....." | $saveresult
- services=$(systemctl | grep -E "\.service.*running" | awk -F. '{print $1}')
- if [ -n "$services" ];then
- (echo "[*]以下服务正在运行:" && echo "$services") | $saveresult
- else
- echo "[!!!]未发现正在运行的服务!" | $saveresult
- fi
- printf "\n" | $saveresult
- echo -------------4.启动项-----------------------
- echo -------------4.1 用户自定义启动项-----------------------
- echo "[4.1]正在检查用户自定义启动项....." | $saveresult
- chkconfig=$(chkconfig --list | grep -E ":on|启用" | awk '{print $1}')
- if [ -n "$chkconfig" ];then
- (echo "[*]用户自定义启动项:" && echo "$chkconfig") | $saveresult
- else
- echo "[!!!]未发现用户自定义启动项" | $saveresult
- fi
- printf "\n" | $saveresult
- echo -------------4.2 系统自启动项-----------------------
- echo "[4.2]正在检查系统自启动项....." | $saveresult
- systemchkconfig=$(systemctl list-unit-files | grep enabled | awk '{print $1}')
- if [ -n "$systemchkconfig" ];then
- (echo "[*]系统自启动项如下:" && echo "$systemchkconfig") | $saveresult
- else
- echo "[*]未发现系统自启动项" | $saveresult
- fi
- printf "\n" | $saveresult
- echo -------------4.3 危险启动项-----------------------
- echo "[4.3]正在检查危险启动项....." | $saveresult
- dangerstarup=$(chkconfig --list | grep -E ":on|启用" | awk '{print $1}' | grep -E "\.(sh|per|py)$")
- if [ -n "$dangerstarup" ];then
- (echo "[!!!]发现危险启动项:" && echo "$dangerstarup") | tee -a $danger_file | $saveresult
- else
- echo "[*]未发现危险启动项" | $saveresult
- fi
- printf "\n" | $saveresult
- echo ------------5.查看定时任务-------------------
- echo ------------5.1系统定时任务分析-------------------
- echo ------------5.1.1查看系统定时任务-------------------
- echo "[5.1.1]正在分析系统定时任务....." | $saveresult
- syscrontab=$(more /etc/crontab | grep -v "# run-parts" | grep run-parts)
- if [ -n "$syscrontab" ];then
- (echo "[!!!]发现存在系统定时任务:" && more /etc/crontab ) | tee -a $danger_file | $saveresult
- else
- echo "[*]未发现系统定时任务" | $saveresult
- fi
- printf "\n" | $saveresult
- # if [ $? -eq 0 ]表示上面命令执行成功;执行成功输出的是0;失败非0
- #ifconfig echo $? 返回0,表示执行成功
- # if [ $? != 0 ]表示上面命令执行失败
- echo ------------5.1.2分析系统可疑定时任务-------------------
- echo "[5.1.2]正在分析系统可疑任务....." | $saveresult
- dangersyscron=$(egrep "((chmod|useradd|groupadd|chattr)|((wget|curl)*\.(sh|pl|py)$))" /etc/cron* var _wpcom_js = {"webp":"","ajaxurl":"https:\/\/www.secvery.com\/wp-admin\/admin-ajax.php","theme_url":"https:\/\/www.secvery.com\/wp-content\/themes\/secvery","slide_speed":"10000","lightbox":"1","user_card_height":"238","video_height":"482","login_url":"https:\/\/www.secvery.com\/login?modal-type=login","register_url":"https:\/\/www.secvery.com\/register?modal-type=register","TCaptcha":{"appid":"2098616795"},"errors":{"require":"\u4e0d\u80fd\u4e3a\u7a7a","email":"\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u7535\u5b50\u90ae\u7bb1","pls_enter":"\u8bf7\u8f93\u5165","password":"\u5bc6\u7801\u5fc5\u987b\u4e3a6~32\u4e2a\u5b57\u7b26","passcheck":"\u4e24\u6b21\u5bc6\u7801\u8f93\u5165\u4e0d\u4e00\u81f4","phone":"\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801","sms_code":"\u9a8c\u8bc1\u7801\u9519\u8bef","captcha_verify":"\u8bf7\u70b9\u51fb\u6309\u94ae\u8fdb\u884c\u9a8c\u8bc1","captcha_fail":"\u70b9\u51fb\u9a8c\u8bc1\u5931\u8d25\uff0c\u8bf7\u91cd\u8bd5","nonce":"\u968f\u673a\u6570\u6821\u9a8c\u5931\u8d25","req_error":"\u8bf7\u6c42\u5931\u8d25"},"follow_btn":"