linux安全基线加固

2022-11-24  本文已影响0人  Tess鱼丸

安全基线加固

一、帐号与口令-用户口令设置, 配置用户口令强度检查达到12位,要求用户口令包括数字、小写字母、大写字母和特殊符号4类中至少2类。

[root@www ~]# vim /etc/pam.d/system-auth

二、 帐号与口令-检查是否存在除root之外UID为0的用户

操作步骤:
执行:awk -F: '(3 == 0) { print1 }' /etc/passwd
返回值包括“root”以外的条目,则低于安全要求。

三、帐号与口令-检查是否存在如下不必要账户:lp, sync, shutdown, halt, news,

uucp, operator, games, gopher等,
操作步骤:
执行:cat /etc/passwd
如果不使用,用以下命令进行删除。

四:给不同的用户分配不同的帐号,避免多个用户共享帐号。

至少分配root,auditor,operator角色。

五:设置帐号在3次连续尝试认证失败后锁定,锁定时间为1分钟,避免用户口

令被暴力破解。

步骤:建立/var/log/faillog文件并设置权限骤
touch /var/log/faillog
chmod 600 /var/log/faillog

编辑/etc/pam.d/system-auth文件,在
auth required pam_env.so后面添加
auth required pam_tally.so onerr=fail deny=3 unlock_time=60

六:帐号与口令-检查除ROOT外是否有其他账户拥有shell权限

执行:cat /etc/passwd观察是否有非root账户设置/bin/bash或/bin/sh权限
无特殊应用情况下,如发现上述账户,则低于安全要求

七:帐号与口令-远程连接的安全性配置

步骤:执行:find / -name .netrc,检查系统中是否有.netrc文件;
执行:find / -name .rhosts ,检查系统中是否有.rhosts文件

返回值包含以上条件,则低于安全要求。
如无必要,删除这两个文件

八:限制ssh连接的IP配置

配置tcp_wrappers,限制允许远程登陆系统的IP范围。

参考配置操作
编辑/etc/hosts.deny
添加sshd:ALL

编辑/etc/hosts.allow
添加
sshd:168.8.44.0/255.255.255.0#允许168.8.44.0网段远程登陆
sshd:168.8.43.0/255.255.255.0#允许168.8.43.0网段远程登陆

1、判定条件
只有网管网段可以ssh登陆系统。
2、检测操作
cat /etc/hosts.deny
cat /etc/hosts.allow

九:用户的umask安全配置

执行:more /etc/profile more /etc/csh.login more /etc/csh.cshrc more
/etc/bashrc检查是否包含umask值

补充操作说明:vi /etc/profile
建议设置用户的默认umask=077

十:文件系统-查找未授权的SUID/SGID文件

用下面的命令查找系统中所有的SUID和SGID程序,执行:

此题可以用shell脚本执行
[root@www Desktop]# vim 111.sh
####编辑一下内容
#!/bin/bash
for PART in `grep -v ^# /etc/fstab | awk '($6 != "0") {print $2 }'`; do 
find $PART \( -perm -04000 -o -perm -02000 \) -type f -xdev -print 
done
[root@www Desktop]#  chmod +x 111.sh
[root@www Desktop]#  ./111/sh
#!/bin/bash
for PART in `grep -v ^# /etc/fstab | awk '($6 != "0") {print $2 }'`; do 
find $PART \( -perm -04000 -o -perm -02000 \) -type f -xdev -print 
done
for PART in `grep -v ^# /etc/fstab | awk '($6 != "0") {print $2 }'`; do 
find $PART \( -perm -04000 -o -perm -02000 \) -type f -xdev -print 
done

若存在未授权的文件,则低于安全要求。


十一:检查任何人都有写权限的目录

在系统中定位任何人都有写权限的目录用下面的命令:

for PART in `awk '($3 == "ext2" || $3 == "ext3") \
{ print $2 }' /etc/fstab`; do 
find $PART -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print 
done

十二、查找任何人都有写权限的文件

在系统中定位任何人都有写权限的文件用下面的命令:

for PART in `grep -v ^# /etc/fstab | awk '($6 != "0") {print $2 }'`; do 
find $PART -xdev -type f \( -perm -0002 -a ! -perm -1000 \) -print 
done

若返回值非空,则低于安全要求。

十三、检查没有属主的文件

定位系统中没有属主的文件用下面的命令:

for PART in `grep -v ^# /etc/fstab | awk '($6 != "0") {print $2 }'`; do 
find $PART -nouser -o -nogroup -print 
done 

注意:不用管“/dev”目录下的那些文件

补充操作说明
发现没有属主的文件往往就意味着有黑客入侵你的系统了。不能允许没有属
主的文件存在。如果在系统中发现了没有属主的文件或目录,先查看它的完
整性,如果一切正常,给它一个属主。有时候卸载程序可能会出现一些没有
属主的文件或目录,在这种情况下可以把这些文件和目录删除掉

十四、检查异常隐含文件
用“find”程序可以查找到这些隐含文件。例如:
[root@www ~]# find / -xdev -name ".." -print
/usr/share/man/man1/..1.gz
[root@www ~]# find / -xdev -name "..
" -print |cat -v
/usr/share/man/man1/..1.gz
同时也要注意象“.xx”和“.mail”这样的文件名的。(这些文件名看起来都很象正常的文件名)

若返回值非空,则低于安全要求。

补充操作说明
在系统的每个地方都要查看一下有没有异常隐含文件(点号是起始字符的,
用“ls”命令看不到的文件),因为这些文件可能是隐藏的黑客工具或者其它
一些信息(口令破解程序、其它系统的口令文件,等等)。在UNIX/LINUX
下,一个常用的技术就是用一些特殊的名,如:“…”、“.. ”(点点空格)
或“..^G”(点点control-G),来隐含文件或目录。

十五、日志审计-syslog登录事件记录

执行命令:more /etc/rsyslog.conf
查看参数authpriv值
authpriv.* /var/log/secure

若未对所有登录事件都记录,则低于安全要求。

十六、Linux日志增强要求项

执行命令:
chattr +a /var/log/messages
chattr +i /var/log/messages.*
chattr +i /etc/shadow
chattr +i /etc/passwd
chattr +I /etc/group

十七、操作系统超时注销

参考配置操作
编辑/etc/profile文件,添加
TMOUT=300
用户登陆后如果300秒内没有做任何操作,则自动注销登陆。

十八、禁用不必要服务

根据实际情况,关闭不必要的系统服务,如:finger,kudzu,isdn,nfs,apm,
sound,pcmcia,vsftpd, rhnsd,Bluetooth,sendmail,lpd,netfs,telnet,RPC,imap
等服务。

在无特殊应用情况下,若有上述提到的服务开启,则不符合要求。

这是错的

以下是对的

[root@www ~]# systemctl start vsftpd
[root@www ~]#
[root@www ~]# ps ax |grep vsftpd
 22769 pts/1    S+     0:00 grep --color=auto vsftpd
[root@www ~]# 
[root@www ~]# systemctl stop vsftpd
[root@www ~]# 
[root@www ~]# systemctl list-units|grep running
proc-sys-fs-binfmt_misc.automount                                                   loaded active running   Arbitrary Executable File Formats File System Automount Point
session-1.scope                                                                     loaded active running   Session 1 of user root
session-14.scope                                                                    loaded active running   Session 14 of user root
abrt-oops.service                                                                   loaded active running   ABRT kernel log watcher
abrt-xorg.service                                                                   loaded active running   ABRT Xorg log watcher
abrtd.service                                                                       loaded active running   ABRT Automated Bug Reporting Tool
accounts-daemon.service                                                             loaded active running   Accounts Service
alsa-state.service                                                                  loaded active running   Manage Sound Card State (restore and store)
atd.service                                                                         loaded active running   Job spooling tools
auditd.service                                                                      loaded active running   Security Auditing Service
avahi-daemon.service                                                                loaded active running   Avahi mDNS/DNS-SD Stack
bolt.service                                                                        loaded active running   Thunderbolt system service
chronyd.service                                                                     loaded active running   NTP client/server
colord.service                                                                      loaded active running   Manage, Install and Generate Color Profiles
crond.service                                                                       loaded active running   Command Scheduler
cups.service                                                                        loaded active running   CUPS Printing Service
dbus.service                                                                        loaded active running   D-Bus System Message Bus
fwupd.service                                                                       loaded active running   Firmware update daemon
gdm.service                                                                         loaded active running   GNOME Display Manager
gssproxy.service                                                                    loaded active running   GSSAPI Proxy Daemon
httpd.service                                                                       loaded active running   The Apache HTTP Server
irqbalance.service                                                                  loaded active running   irqbalance daemon
ksmtuned.service                                                                    loaded active running   Kernel Samepage Merging (KSM) Tuning Daemon
libstoragemgmt.service                                                              loaded active running   libstoragemgmt plug-in server daemon
libvirtd.service                                                                    loaded active running   Virtualization daemon
lvm2-lvmetad.service                                                                loaded active running   LVM2 metadata daemon
ModemManager.service                                                                loaded active running   Modem Manager
NetworkManager.service                                                              loaded active running   Network Manager
packagekit.service                                                                  loaded active running   PackageKit Daemon
polkit.service                                                                      loaded active running   Authorization Manager
postfix.service                                                                     loaded active running   Postfix Mail Transport Agent
rngd.service                                                                        loaded active running   Hardware RNG Entropy Gatherer Daemon
rpcbind.service                                                                     loaded active running   RPC bind service
rsyslog.service                                                                     loaded active running   System Logging Service
rtkit-daemon.service                                                                loaded active running   RealtimeKit Scheduling Policy Service
smartd.service                                                                      loaded active running   Self Monitoring and Reporting Technology (SMART) Daemon
sshd.service                                                                        loaded active running   OpenSSH server daemon
systemd-journald.service                                                            loaded active running   Journal Service
systemd-logind.service                                                              loaded active running   Login Service
systemd-udevd.service                                                               loaded active running   udev Kernel Device Manager
tuned.service                                                                       loaded active running   Dynamic System Tuning Daemon
udisks2.service                                                                     loaded active running   Disk Manager
upower.service                                                                      loaded active running   Daemon for power management
vgauthd.service                                                                     loaded active running   VGAuth Service for open-vm-tools
vmtoolsd.service                                                                    loaded active running   Service for virtual machines hosted on VMware
wpa_supplicant.service                                                              loaded active running   WPA Supplicant daemon
avahi-daemon.socket                                                                 loaded active running   Avahi mDNS/DNS-SD Stack Activation Socket
cups.socket                                                                         loaded active running   CUPS Printing Service Sockets
dbus.socket                                                                         loaded active running   D-Bus System Message Bus Socket
lvm2-lvmetad.socket                                                                 loaded active running   LVM2 metadata daemon socket
rpcbind.socket                                                                      loaded active running   RPCbind Server Activation Socket
systemd-journald.socket                                                             loaded active running   Journal Socket
systemd-udevd-control.socket                                                        loaded active running   udev Control Socket
systemd-udevd-kernel.socket                                                         loaded active running   udev Kernel Socket
[root@www ~]# 
上一篇下一篇

猜你喜欢

热点阅读