Skip to content

Commit 52a47c8

Browse files
authored
Update LinuxCheck.sh
1 parent 833beaf commit 52a47c8

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

LinuxCheck.sh

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,38 @@ echo " ========================================================= "
77
echo " # 支持Centos、Debian系统检测 "
88
echo " # author:al0ne "
99
echo " # https://github.com/al0ne "
10-
echo " # 更新日期:2021年10月17日 "
10+
echo " # 更新日期:2022年08月5日 "
1111
echo " # 参考来源: "
1212
echo " # 1.Gscan https://github.com/grayddq/GScan "
1313
echo " # 2.Lynis https://github.com/CISOfy/lynis "
1414
echo -e "\n"
1515

16+
# 更新日志:2022年08月05日
17+
#### 修复内核模块检查日志过多问题
18+
# 更新日志:2022年03月07日
19+
#### 添加SSH软连接后门检测
1620
# 更新日期:2021年10月17日
17-
# 添加Ntpclient/WorkMiner/TeamTNT挖矿木马检测
18-
# 添加Rootkit模块检测逻辑
19-
# 添加Python pip投毒检测
20-
# 添加$HOME/.profile查看
21-
# 添加服务器风险检查(Redis)
21+
#### 添加Ntpclient/WorkMiner/TeamTNT挖矿木马检测
22+
#### 添加Rootkit模块检测逻辑
23+
#### 添加Python pip投毒检测
24+
#### 添加$HOME/.profile查看
25+
#### 添加服务器风险检查(Redis)
2226

2327
# WEB Path 设置web目录 默认的话是从/目录去搜索 性能较慢
2428
webpath='/'
2529

30+
print_msg() {
31+
echo -e "\e[00;31m[+]$1\e[00m"
32+
}
33+
2634
### 1.环境检查 ###
27-
echo -e "\e[00;31m[+]环境检测\e[00m"
35+
print_msg "环境检测"
2836
# 验证是否为root权限
2937
if [ $UID -ne 0 ]; then
30-
echo -e "\n\e[00;33m请使用root权限运行 \e[00m"
38+
print_msg "请使用root权限运行!"
3139
exit 1
3240
else
33-
echo -e "\e[00;32m当前为root权限 \e[00m"
41+
print_msg "当前为root权限"
3442
fi
3543

3644
# 验证操作系统是debian系还是centos
@@ -69,12 +77,11 @@ cmdline=(
6977
"lrzsz"
7078
"wget"
7179
"strace"
80+
"traceroute"
7281
"htop"
7382
"tar"
7483
"lsof"
7584
"tcpdump"
76-
"the_silver_searcher"
77-
"silversearcher-ag"
7885
)
7986
for prog in "${cmdline[@]}"; do
8087

@@ -83,11 +90,13 @@ for prog in "${cmdline[@]}"; do
8390
if echo "$soft" | grep -E '没有安装|未安装|not installed' >/dev/null 2>&1; then
8491
echo -e "$prog 安装中......"
8592
yum install -y "$prog" >/dev/null 2>&1
93+
yum install -y the_silver_searcher >/dev/null 2>&1
8694
fi
8795
else
8896
if dpkg -L $prog | grep 'does not contain any files' >/dev/null 2>&1; then
8997
echo -e "$prog 安装中......"
9098
apt install -y "$prog" >/dev/null 2>&1
99+
apt install -y silversearcher-ag >/dev/null 2>&1
91100
fi
92101

93102
fi
@@ -138,8 +147,8 @@ base_check() {
138147
cpu=$(ps aux | grep -v ^'USER' | sort -rn -k3 | head -15) 2>/dev/null
139148
echo -e "\e[00;31m[+]CPU TOP15: \e[00m\n${cpu}\n" | tee -a "$filename"
140149
#内存占用TOP 15
141-
cpu=$(ps aux | grep -v ^'USER' | sort -rn -k3 | head -15) 2>/dev/null
142-
echo -e "\e[00;31m[+]内存占用 TOP15: \e[00m\n${cpu}\n" | tee -a "$filename"
150+
mem=$(ps aux | grep -v ^'USER' | sort -rn -k4 | head -15) 2>/dev/null
151+
echo -e "\e[00;31m[+]内存占用 TOP15: \e[00m\n${mem}\n" | tee -a "$filename"
143152
#内存占用
144153
echo -e "\e[00;31m[+]内存占用\e[00m" | tee -a "$filename"
145154
free -mh | tee -a "$filename"
@@ -457,7 +466,7 @@ rootkit_check() {
457466
echo -e "############ Rootkit检查 ############\n" | tee -a "$vuln"
458467
#lsmod 可疑模块
459468
echo -e "\e[00;31m[+]lsmod 可疑模块\e[00m" | tee -a "$vuln"
460-
lsmod | ag -v "ablk_helper|ac97_bus|acpi_power_meter|aesni_intel|ahci|ata_generic|ata_piix|auth_rpcgss|binfmt_misc|bluetooth|bnep|bnx2|bridge|cdrom|cirrus|coretemp|crc_t10dif|crc32_pclmul|crc32c_intel|crct10dif_common|crct10dif_generic|crct10dif_pclmul|cryptd|dca|dcdbas|dm_log|dm_mirror|dm_mod|dm_region_hash|drm|drm_kms_helper|drm_panel_orientation_quirks|e1000|ebtable_broute|ebtable_filter|ebtable_nat|ebtables|edac_core|ext4|fb_sys_fops|floppy|fuse|gf128mul|ghash_clmulni_intel|glue_helper|grace|i2c_algo_bit|i2c_core|i2c_piix4|i7core_edac|intel_powerclamp|ioatdma|ip_set|ip_tables|ip6_tables|ip6t_REJECT|ip6t_rpfilter|ip6table_filter|ip6table_mangle|ip6table_nat|ip6ta ble_raw|ip6table_security|ipmi_devintf|ipmi_msghandler|ipmi_si|ipmi_ssif|ipt_MASQUERADE|ipt_REJECT|iptable_filter|iptable_mangle|iptable_nat|iptable_raw|iptable_security|iTCO_vendor_support|iTCO_wdt|jbd2|joydev|kvm|kvm_intel|libahci|libata|libcrc32c|llc|lockd|lpc_ich|lrw|mbcache|megaraid_sas|mfd_core|mgag200|Module|mptbase|mptscsih|mptspi|nf_conntrack|nf_conntrack_ipv4|nf_conntrack_ipv6|nf_defrag_ipv4|nf_defrag_ipv6|nf_nat|nf_nat_ipv4|nf_nat_ipv6|nf_nat_masquerade_ipv4|nfnetlink|nfnetlink_log|nfnetlink_queue|nfs_acl|nfsd|parport|parport_pc|pata_acpi|pcspkr|ppdev|rfkill|sch_fq_codel|scsi_transport_spi|sd_mod|serio_raw|sg|shpchp|snd|snd_ac97_codec|snd_ens1371|snd_page_alloc|snd_pcm|snd_rawmidi|snd_seq|snd_seq_device|snd_seq_midi|snd_seq_midi_event|snd_timer|soundcore|sr_mod|stp|sunrpc|syscopyarea|sysfillrect|sysimgblt|tcp_lp|ttm|tun|uvcvideo|videobuf2_core|videobuf2_memops|videobuf2_vmalloc|videodev|virtio|virtio_balloon|virtio_console|virtio_net|virtio_pci|virtio_ring|virtio_scsi|vmhgfs|vmw_balloon|vmw_vmci|vmw_vsock_vmci_transport|vmware_balloon|vmwgfx|vsock|xfs|xt_CHECKSUM|xt_conntrack|xt_state|raid*|tcpbbr|btrfs|.*diag|psmouse|ufs|linear|msdos|cpuid|veth|xt_tcpudp|xfrm_user|xfrm_algo|xt_addrtype|br_netfilter|input_leds|sch_fq|ib_iser|rdma_cm|iw_cm|ib_cm|ib_core|.*scsi.*|tcp_bbr|pcbc|autofs4|multipath|hfs.*|minix|ntfs|vfat|jfs|usbcore|usb_common|ehci_hcd|uhci_hcd|ecb|crc32c_generic|button|hid|usbhid|evdev|hid_generic|overlay|xt_nat|qnx4|sb_edac|acpi_cpufreq|ixgbe|pf_ring|tcp_htcp|cfg80211|x86_pkg_temp_thermal|mei_me|mei|processor|thermal_sys|lp|enclosure|ses|ehci_pci|igb|i2c_i801|pps_core|isofs|nls_utf8|xt_REDIRECT|xt_multiport|iosf_mbi|qxl|cdc_ether|usbnet" | tee -a "$vuln"
469+
lsmod | ag -v "ablk_helper|ac97_bus|acpi_power_meter|aesni_intel|ahci|ata_generic|ata_piix|auth_rpcgss|binfmt_misc|bluetooth|bnep|bnx2|bridge|cdrom|cirrus|coretemp|crc_t10dif|crc32_pclmul|crc32c_intel|crct10dif_common|crct10dif_generic|crct10dif_pclmul|cryptd|dca|dcdbas|dm_log|dm_mirror|dm_mod|dm_region_hash|drm|drm_kms_helper|drm_panel_orientation_quirks|e1000|ebtable_broute|ebtable_filter|ebtable_nat|ebtables|edac_core|ext4|fb_sys_fops|floppy|fuse|gf128mul|ghash_clmulni_intel|glue_helper|grace|i2c_algo_bit|i2c_core|i2c_piix4|i7core_edac|intel_powerclamp|ioatdma|ip_set|ip_tables|ip6_tables|ip6t_REJECT|ip6t_rpfilter|ip6table_filter|ip6table_mangle|ip6table_nat|ip6ta ble_raw|ip6table_security|ipmi_devintf|ipmi_msghandler|ipmi_si|ipmi_ssif|ipt_MASQUERADE|ipt_REJECT|iptable_filter|iptable_mangle|iptable_nat|iptable_raw|iptable_security|iTCO_vendor_support|iTCO_wdt|jbd2|joydev|kvm|kvm_intel|libahci|libata|libcrc32c|llc|lockd|lpc_ich|lrw|mbcache|megaraid_sas|mfd_core|mgag200|Module|mptbase|mptscsih|mptspi|nf_conntrack|nf_conntrack_ipv4|nf_conntrack_ipv6|nf_defrag_ipv4|nf_defrag_ipv6|nf_nat|nf_nat_ipv4|nf_nat_ipv6|nf_nat_masquerade_ipv4|nfnetlink|nfnetlink_log|nfnetlink_queue|nfs_acl|nfsd|parport|parport_pc|pata_acpi|pcspkr|ppdev|rfkill|sch_fq_codel|scsi_transport_spi|sd_mod|serio_raw|sg|shpchp|snd|snd_ac97_codec|snd_ens1371|snd_page_alloc|snd_pcm|snd_rawmidi|snd_seq|snd_seq_device|snd_seq_midi|snd_seq_midi_event|snd_timer|soundcore|sr_mod|stp|sunrpc|syscopyarea|sysfillrect|sysimgblt|tcp_lp|ttm|tun|uvcvideo|videobuf2_core|videobuf2_memops|videobuf2_vmalloc|videodev|virtio|virtio_balloon|virtio_console|virtio_net|virtio_pci|virtio_ring|virtio_scsi|vmhgfs|vmw_balloon|vmw_vmci|vmw_vsock_vmci_transport|vmware_balloon|vmwgfx|vsock|xfs|xt_CHECKSUM|xt_conntrack|xt_state|raid*|tcpbbr|btrfs|.*diag|psmouse|ufs|linear|msdos|cpuid|veth|xt_tcpudp|xfrm_user|xfrm_algo|xt_addrtype|br_netfilter|input_leds|sch_fq|ib_iser|rdma_cm|iw_cm|ib_cm|ib_core|.*scsi.*|tcp_bbr|pcbc|autofs4|multipath|hfs.*|minix|ntfs|vfat|jfs|usbcore|usb_common|ehci_hcd|uhci_hcd|ecb|crc32c_generic|button|hid|usbhid|evdev|hid_generic|overlay|xt_nat|qnx4|sb_edac|acpi_cpufreq|ixgbe|pf_ring|tcp_htcp|cfg80211|x86_pkg_temp_thermal|mei_me|mei|processor|thermal_sys|lp|enclosure|ses|ehci_pci|igb|i2c_i801|pps_core|isofs|nls_utf8|xt_REDIRECT|xt_multiport|iosf_mbi|qxl|cdc_ether|usbnet|ip6table_raw|skx_edac|intel_rapl|wmi|acpi_pad|ast|i40e|ptp|nfit|libnvdimm|bpfilter|failover" | tee -a "$vuln"
461470
echo -e "\n" | tee -a "$vuln"
462471

463472
echo -e "\e[00;31m[+]Rootkit 内核模块\e[00m" | tee -a "$vuln"
@@ -471,7 +480,7 @@ rootkit_check() {
471480
echo -e "\n" | tee -a "$vuln"
472481

473482
echo -e "\e[00;31m[+]可疑的.ko模块\e[00m" | tee -a "$vuln"
474-
find / ! -path "/proc/*" ! -path "/usr/lib/modules/*" ! -path "/boot/*" -regextype posix-extended -regex '.*\.ko' | tee -a "$vuln"
483+
find / ! -path "/proc/*" ! -path "/usr/lib/modules/*" ! -path "/lib/modules/*" ! -path "/boot/*" -regextype posix-extended -regex '.*\.ko' | tee -a "$vuln"
475484
echo -e "\n" | tee -a "$vuln"
476485
}
477486

@@ -501,13 +510,23 @@ ssh_check() {
501510
fi
502511
echo -e "\n" | tee -a "$vuln"
503512

513+
#ssh后门配置检查
514+
echo -e "\e[00;31m[+]SSH 软连接后门 \e[00m" | tee -a "$vuln"
515+
if ps -ef | ag '\s+\-oport=\d+' >/dev/null 2>&1; then
516+
ps -ef | ag '\s+\-oport=\d+' | tee -a "$vuln"
517+
else
518+
echo "未检测到SSH软连接后门" | tee -a "$vuln"
519+
520+
fi
521+
echo -e "\n" | tee -a "$vuln"
522+
504523
echo -e "\e[00;31m[+]SSH inetd后门检查 \e[00m" | tee -a "$vuln"
505524
if [ -e "/etc/inetd.conf" ]; then
506525
grep -E '(bash -i)' </etc/inetd.conf | tee -a "$vuln"
507526
fi
508527
echo -e "\n" | tee -a "$vuln"
509528

510-
echo -e "\e[00;31m[+]SSH key\e[00m" | tee -a "$filename"
529+
echo -e "\e[00;31m[+]SSH key\e[00m" | tee -a "$vuln"
511530
sshkey=${HOME}/.ssh/authorized_keys
512531
if [ -e "${sshkey}" ]; then
513532
# shellcheck disable=SC2002
@@ -562,26 +581,6 @@ miner_check() {
562581
echo -e "\n" | tee -a "$vuln"
563582
}
564583

565-
rkhunter_install() {
566-
echo -e "############ Rkhunter 安装 ############\n" | tee -a "$filename"
567-
echo -e "\e[00;31m[+]Rkhunter查杀\e[00m" | tee -a "$filename"
568-
if rkhunter >/dev/null 2>&1; then
569-
rkhunter --checkall --sk | ag -v 'OK|Not found|None found'
570-
else
571-
if [ -e "/tmp/rkhunter.tar.gz" ]; then
572-
cd /tmp && tar -zxvf /tmp/rkhunter.tar.gz >/dev/null 2>&1
573-
cd /tmp/rkhunter-1.4.6/ && ./installer.sh --install >/dev/null 2>&1
574-
rkhunter --checkall --sk | ag -v 'OK|Not found|None found'
575-
else
576-
echo -e "找不到rkhunter.tar.gz尝试下载"
577-
wget https://github.com/al0ne/LinuxCheck/raw/master/rkhunter.tar.gz -O /tmp/rkhunter.tar.gz >/dev/null 2>&1
578-
tar -zxvf /tmp/rkhunter.tar.gz >/dev/null 2>&1
579-
cd /tmp/rkhunter-1.4.6/ && ./installer.sh --install >/dev/null 2>&1
580-
rkhunter --checkall --sk | ag -v 'OK|Not found|None found'
581-
fi
582-
fi
583-
}
584-
585584
risk_check() {
586585
echo -e "############ 服务器风险/漏洞检查 ############\n" | tee -a "$vuln"
587586
echo -e "\e[00;31m[+]Redis弱密码检测\e[00m" | tee -a "$vuln"
@@ -602,5 +601,4 @@ ssh_check
602601
webshell_check
603602
poison_check
604603
miner_check
605-
rkhunter_install
606604
risk_check

0 commit comments

Comments
 (0)